Skip to content

Commit 362135a

Browse files
anonrigrichardlau
authored andcommitted
src: disable uncaught exception abortion for ESM syntax detection
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]>
1 parent 59805f6 commit 362135a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎src/node_contextify.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ void ContextifyContext::ContainsModuleSyntax(
14691469
String::NewFromUtf8(isolate, "__dirname").ToLocalChecked()};
14701470

14711471
TryCatchScope try_catch(env);
1472+
ShouldNotAbortOnUncaughtScope no_abort_scope(env);
14721473

14731474
ContextifyContext::CompileFunctionAndCacheResult(env,
14741475
context,

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

Lines changed: 20 additions & 0 deletions
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 }=awaitspawnPromisified(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)