From 38f859f2bd820095c2a44a9cd9f872b8169d0b15 Mon Sep 17 00:00:00 2001 From: voltrexmaster Date: Sat, 30 Oct 2021 02:28:26 -0700 Subject: [PATCH] process: refactor execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • 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. --- lib/internal/process/execution.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index 48c525057f7477..93279f5075c0e8 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -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) { @@ -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. }