Skip to content

Commit 4910e19

Browse files
committed
esm: handle globalPreload hook returning a nullish value
1 parent 6a6b3c5 commit 4910e19

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
@@ -244,6 +244,20 @@ describe('Loader hooks', { concurrency: true }, () => {
244244
assert.strictEqual(signal, null);
245245
});
246246

247+
it('should handle globalPreload returning undefined', async () => {
248+
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
249+
'--no-warnings',
250+
'--experimental-loader',
251+
'data:text/javascript,export function globalPreload(){}',
252+
fixtures.path('empty.js'),
253+
]);
254+
255+
assert.strictEqual(stderr, '');
256+
assert.strictEqual(stdout, '');
257+
assert.strictEqual(code, 0);
258+
assert.strictEqual(signal, null);
259+
});
260+
247261
it('should be fine to call `process.removeAllListeners("beforeExit")` from the main thread', async () => {
248262
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
249263
'--no-warnings',

0 commit comments

Comments
 (0)