Skip to content

Commit 38f859f

Browse files
committed
process: refactor execution
• 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.
1 parent f8035ec commit 38f859f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

lib/internal/process/execution.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@ function evalModule(source, print) {
4242
if (print) {
4343
throw new ERR_EVAL_ESM_CANNOT_PRINT();
4444
}
45-
const { log } = require('internal/console/global');
4645
const { loadESM } = require('internal/process/esm_loader');
4746
const { handleMainPromise } = require('internal/modules/run_main');
48-
return handleMainPromise(loadESM(async (loader) => {
49-
const { result } = await loader.eval(source);
50-
if (print) {
51-
log(result);
52-
}
53-
}));
47+
return handleMainPromise(loadESM((loader) => loader.eval(source)));
5448
}
5549

5650
function evalScript(name, body, breakFirstLine, print) {
@@ -153,12 +147,12 @@ function createOnGlobalUncaughtException() {
153147
const report = internalBinding('report');
154148
if (report != null && report.shouldReportOnUncaughtException()) {
155149
report.writeReport(
156-
typeof er?.message === 'string' ?
150+
(er && typeof er.message === 'string') ?
157151
er.message :
158152
'Exception',
159153
'Exception',
160154
null,
161-
er ? er : {});
155+
er ?? {});
162156
}
163157
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
164158
}

0 commit comments

Comments
 (0)