Skip to content

Commit

Permalink
process: refactor execution
Browse files Browse the repository at this point in the history
• Removed unreachable code of the `evalModule()` function as an early
error is thrown when the `print` parameter is a truthy value.
• Check if the `er` parameter of the returned function of the
`createOnGlobalUncaughtException()` function is not nullish first
instead of comparing it's type.
• Make use of the nullish coalescing operator.
  • Loading branch information
VoltrexKeyva committed Oct 30, 2021
1 parent f8035ec commit 38f859f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/internal/process/execution.js
Expand Up @@ -42,15 +42,9 @@ function evalModule(source, print) {
if (print) {
throw new ERR_EVAL_ESM_CANNOT_PRINT();
}
const { log } = require('internal/console/global');
const { loadESM } = require('internal/process/esm_loader');
const { handleMainPromise } = require('internal/modules/run_main');
return handleMainPromise(loadESM(async (loader) => {
const { result } = await loader.eval(source);
if (print) {
log(result);
}
}));
return handleMainPromise(loadESM((loader) => loader.eval(source)));
}

function evalScript(name, body, breakFirstLine, print) {
Expand Down Expand Up @@ -153,12 +147,12 @@ function createOnGlobalUncaughtException() {
const report = internalBinding('report');
if (report != null && report.shouldReportOnUncaughtException()) {
report.writeReport(
typeof er?.message === 'string' ?
(er && typeof er.message === 'string') ?
er.message :
'Exception',
'Exception',
null,
er ? er : {});
er ?? {});
}
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
}
Expand Down

0 comments on commit 38f859f

Please sign in to comment.