Skip to content

Commit f601a24

Browse files
aduh95franciszek-koltuniuk-red
authored andcommitted
esm: handle globalPreload hook returning a nullish value
PR-URL: nodejs#48249 Fixes: nodejs#48240 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
1 parent 9421c52 commit f601a24

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/internal/modules/esm/hooks.js

+1-1
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

+14
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)