Skip to content

Commit

Permalink
src: disable uncaught exception abortion for ESM syntax detection
Browse files Browse the repository at this point in the history
PR-URL: #50987
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
  • Loading branch information
anonrig authored and targos committed Dec 4, 2023
1 parent 812ab9e commit 709ac47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ void ContextifyContext::ContainsModuleSyntax(
String::NewFromUtf8(isolate, "__dirname").ToLocalChecked()};

TryCatchScope try_catch(env);
ShouldNotAbortOnUncaughtScope no_abort_scope(env);

ContextifyContext::CompileFunctionAndCacheResult(env,
context,
Expand Down
20 changes: 20 additions & 0 deletions test/es-module/test-esm-detect-ambiguous.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,23 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
}
});
});

// Validate temporarily disabling `--abort-on-uncaught-exception`
// while running `containsModuleSyntax`.
// Ref: https://github.com/nodejs/node/issues/50878
describe('Wrapping a `require` of an ES module while using `--abort-on-uncaught-exception`', () => {
it('should work', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--abort-on-uncaught-exception',
'--eval',
'assert.throws(() => require("./package-type-module/esm.js"), { code: "ERR_REQUIRE_ESM" })',
], {
cwd: fixtures.path('es-modules'),
});

strictEqual(stderr, '');
strictEqual(stdout, '');
strictEqual(code, 0);
strictEqual(signal, null);
});
});

0 comments on commit 709ac47

Please sign in to comment.