From 095d7d27105168e8d35946aeb4fc71cba2479a79 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sun, 6 Oct 2019 23:44:23 -0400 Subject: [PATCH] last tests --- lib/internal/modules/cjs/loader.js | 6 ++++++ lib/repl.js | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index d21caaf0dd2f0a..00678a28b79c7f 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -66,6 +66,8 @@ const { ERR_INVALID_OPT_VALUE, ERR_REQUIRE_ESM } = require('internal/errors').codes; +const { hasUncaughtExceptionCaptureCallback } = + require('internal/process/execution'); const { validateString } = require('internal/validators'); const pendingDeprecation = getOptionValue('--pending-deprecation'); const experimentalExports = getOptionValue('--experimental-exports'); @@ -1012,6 +1014,10 @@ Module.runMain = function(main) { return loader.import(pathToFileURL(mainPath || process.argv[1]).href); }) .catch((e) => { + if (hasUncaughtExceptionCaptureCallback()) { + process._fatalException(e); + return; + } internalBinding('errors').triggerUncaughtException( e, true /* fromPromise */ diff --git a/lib/repl.js b/lib/repl.js index 5fb0fc79aa3404..1017e77a9fc5d3 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -99,6 +99,7 @@ const { } = internalBinding('contextify'); const history = require('internal/repl/history'); +const { setImmediate } = require('timers'); // Lazy-loaded. let processTopLevelAwait; @@ -1074,7 +1075,11 @@ function complete(line, callback) { // All this is only profitable if the nested REPL does not have a // bufferedCommand. if (!magic[kBufferedCommandSymbol]) { - magic._domain.on('error', (err) => { throw err; }); + magic._domain.on('error', (err) => { + setImmediate(() => { + throw err; + }); + }); return magic.complete(line, callback); } }