esm: handle globalPreload hook returning a nullish value

PR-URL: https://github.com/nodejs/node/pull/48249
Backport-PR-URL: https://github.com/nodejs/node/pull/50669
Fixes: https://github.com/nodejs/node/issues/48240
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
This commit is contained in:
Antoine du Hamel authored and Michaël Zasso committed 2023-11-23 10:42:35 +01:00
1 parent 9938a8bf13
commit 655111fa00
2 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -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(
+14
View File
@@ -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',