Skip to content

Commit 3b00f3a

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

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
@@ -169,7 +169,7 @@ class Hooks {
169169
port: insideLoader,
170170
});
171171

172-
if (preloaded == null) { return; }
172+
if (preloaded == null) { continue; }
173173

174174
if (typeof preloaded !== 'string') { // [2]
175175
throw new ERR_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
@@ -400,6 +400,20 @@ describe('Loader hooks', { concurrency: true }, () => {
400400
});
401401
});
402402

403+
it('should handle globalPreload returning undefined', async () => {
404+
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
405+
'--no-warnings',
406+
'--experimental-loader',
407+
'data:text/javascript,export function globalPreload(){}',
408+
fixtures.path('empty.js'),
409+
]);
410+
411+
assert.strictEqual(stderr, '');
412+
assert.strictEqual(stdout, '');
413+
assert.strictEqual(code, 0);
414+
assert.strictEqual(signal, null);
415+
});
416+
403417
it('should be fine to call `process.removeAllListeners("beforeExit")` from the main thread', async () => {
404418
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
405419
'--no-warnings',

0 commit comments

Comments
 (0)