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.
• Make use of the nullish coalescing operator.

PR-URL: #40664
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
VoltrexKeyva authored and targos committed Nov 8, 2021
1 parent 306d953 commit ea968d5
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
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 @@ -158,7 +152,7 @@ function createOnGlobalUncaughtException() {
'Exception',
'Exception',
null,
er ? er : {});
er ?? {});
}
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
}
Expand Down

0 comments on commit ea968d5

Please sign in to comment.