Skip to content

Commit 655111f

Browse files
aduh95targos
authored andcommitted
esm: handle globalPreload hook returning a nullish value
PR-URL: #48249 Backport-PR-URL: #50669Fixes: #48240 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
1 parent 9938a8b commit 655111f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

‎lib/internal/modules/esm/hooks.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Hooks{
168168
port: insideLoader,
169169
});
170170

171-
if(preloaded==null){return;}
171+
if(preloaded==null){continue;}
172172

173173
if(typeofpreloaded!=='string'){// [2]
174174
thrownewERR_INVALID_RETURN_VALUE(

‎test/es-module/test-esm-loader-hooks.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,20 @@ describe('Loader hooks',{concurrency: true }, () =>{
348348
});
349349
});
350350

351+
it('should handle globalPreload returning undefined',async()=>{
352+
const{ code, signal, stdout, stderr }=awaitspawnPromisified(execPath,[
353+
'--no-warnings',
354+
'--experimental-loader',
355+
'data:text/javascript,export function globalPreload(){}',
356+
fixtures.path('empty.js'),
357+
]);
358+
359+
assert.strictEqual(stderr,'');
360+
assert.strictEqual(stdout,'');
361+
assert.strictEqual(code,0);
362+
assert.strictEqual(signal,null);
363+
});
364+
351365
it('should be fine to call `process.removeAllListeners("beforeExit")` from the main thread',async()=>{
352366
const{ code, signal, stdout, stderr }=awaitspawnPromisified(execPath,[
353367
'--no-warnings',

0 commit comments

Comments
(0)