Skip to content

Commit

Permalink
esm: handle globalPreload hook returning a nullish value
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#48249
Backport-PR-URL: nodejs/node#50669
Fixes: nodejs/node#48240
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent 02041f8 commit babd75f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graal-nodejs/lib/internal/modules/esm/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Hooks {
port: insideLoader,
});

if (preloaded == null) { return; }
if (preloaded == null) { continue; }

if (typeof preloaded !== 'string') { // [2]
throw new ERR_INVALID_RETURN_VALUE(
Expand Down
14 changes: 14 additions & 0 deletions graal-nodejs/test/es-module/test-esm-loader-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,20 @@ describe('Loader hooks', { concurrency: true }, () => {
});
});

it('should handle globalPreload returning undefined', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-loader',
'data:text/javascript,export function globalPreload(){}',
fixtures.path('empty.js'),
]);

assert.strictEqual(stderr, '');
assert.strictEqual(stdout, '');
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

it('should be fine to call `process.removeAllListeners("beforeExit")` from the main thread', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down

0 comments on commit babd75f

Please sign in to comment.