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
  • Loading branch information
anonrig committed Dec 3, 2023
1 parent 2f40652 commit 86d275a
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 86d275a

Please sign in to comment.