Skip to content

Commit 709ac47

Browse files
anonrigtargos
authored andcommitted
src: disable uncaught exception abortion for ESM syntax detection
PR-URL: #50987 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 812ab9e commit 709ac47

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/node_contextify.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ void ContextifyContext::ContainsModuleSyntax(
14681468
String::NewFromUtf8(isolate, "__dirname").ToLocalChecked()};
14691469

14701470
TryCatchScope try_catch(env);
1471+
ShouldNotAbortOnUncaughtScope no_abort_scope(env);
14711472

14721473
ContextifyContext::CompileFunctionAndCacheResult(env,
14731474
context,

test/es-module/test-esm-detect-ambiguous.mjs

+20
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,23 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
235235
}
236236
});
237237
});
238+
239+
// Validate temporarily disabling `--abort-on-uncaught-exception`
240+
// while running `containsModuleSyntax`.
241+
// Ref: https://github.com/nodejs/node/issues/50878
242+
describe('Wrapping a `require` of an ES module while using `--abort-on-uncaught-exception`', () => {
243+
it('should work', async () => {
244+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
245+
'--abort-on-uncaught-exception',
246+
'--eval',
247+
'assert.throws(() => require("./package-type-module/esm.js"), { code: "ERR_REQUIRE_ESM" })',
248+
], {
249+
cwd: fixtures.path('es-modules'),
250+
});
251+
252+
strictEqual(stderr, '');
253+
strictEqual(stdout, '');
254+
strictEqual(code, 0);
255+
strictEqual(signal, null);
256+
});
257+
});

0 commit comments

Comments
 (0)