Skip to content

Commit 6828dba

Browse files
remove 'preload' execution
1 parent f3d4fc3 commit 6828dba

File tree

2 files changed

+3
-63
lines changed

2 files changed

+3
-63
lines changed

lib/internal/modules/esm/hooks.js

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class Hooks {
138138

139139
/**
140140
* Collect custom/user-defined module loader hook(s).
141-
* After all hooks have been collected, the global preload hook(s) must be initialized.
142141
* @param {string} url Custom loader specifier
143142
* @param {Record<string, unknown>} exports
144143
* @param {any} [data] Arbitrary data to be passed from the custom loader (user-land)
@@ -501,8 +500,6 @@ class HooksProxy {
501500
AtomicsWait(this.#lock, WORKER_TO_MAIN_THREAD_NOTIFICATION, 0);
502501
const response = this.#worker.receiveMessageSync();
503502
if (response == null || response.message.status === 'exit') { return; }
504-
const { preloadScripts } = this.#unwrapMessage(response);
505-
this.#executePreloadScripts(preloadScripts);
506503
}
507504

508505
this.#isReady = true;
@@ -619,63 +616,6 @@ class HooksProxy {
619616
importMetaInitialize(meta, context, loader) {
620617
this.#importMetaInitializer(meta, context, loader);
621618
}
622-
623-
#executePreloadScripts(preloadScripts) {
624-
for (let i = 0; i < preloadScripts.length; i++) {
625-
const { code, port } = preloadScripts[i];
626-
const { compileFunction } = require('vm');
627-
const preloadInit = compileFunction(
628-
code,
629-
['getBuiltin', 'port', 'setImportMetaCallback'],
630-
{
631-
filename: '<preload>',
632-
},
633-
);
634-
let finished = false;
635-
let replacedImportMetaInitializer = false;
636-
let next = this.#importMetaInitializer;
637-
const { BuiltinModule } = require('internal/bootstrap/realm');
638-
// Calls the compiled preload source text gotten from the hook
639-
// Since the parameters are named we use positional parameters
640-
// see compileFunction above to cross reference the names
641-
try {
642-
FunctionPrototypeCall(
643-
preloadInit,
644-
globalThis,
645-
// Param getBuiltin
646-
(builtinName) => {
647-
if (StringPrototypeStartsWith(builtinName, 'node:')) {
648-
builtinName = StringPrototypeSlice(builtinName, 5);
649-
} else if (!BuiltinModule.canBeRequiredWithoutScheme(builtinName)) {
650-
throw new ERR_UNKNOWN_BUILTIN_MODULE(builtinName);
651-
}
652-
if (BuiltinModule.canBeRequiredByUsers(builtinName)) {
653-
return require(builtinName);
654-
}
655-
throw new ERR_UNKNOWN_BUILTIN_MODULE(builtinName);
656-
},
657-
// Param port
658-
port,
659-
// setImportMetaCallback
660-
(fn) => {
661-
if (finished || typeof fn !== 'function') {
662-
throw new ERR_INVALID_ARG_TYPE('fn', fn);
663-
}
664-
replacedImportMetaInitializer = true;
665-
const parent = next;
666-
next = (meta, context) => {
667-
return fn(meta, context, parent);
668-
};
669-
},
670-
);
671-
} finally {
672-
finished = true;
673-
if (replacedImportMetaInitializer) {
674-
this.#importMetaInitializer = next;
675-
}
676-
}
677-
}
678-
}
679619
}
680620
ObjectSetPrototypeOf(HooksProxy.prototype, null);
681621

lib/internal/modules/esm/worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function wrapMessage(status, body) {
7474
}
7575

7676
async function customizedModuleWorker(lock, syncCommPort, errorHandler) {
77-
let hooks, preloadScripts, initializationError;
77+
let hooks;
78+
let initializationError;
7879
let hasInitializationError = false;
7980

8081
{
@@ -93,7 +94,6 @@ async function customizedModuleWorker(lock, syncCommPort, errorHandler) {
9394
try {
9495
const initResult = await initializeHooks();
9596
hooks = initResult.hooks;
96-
preloadScripts = initResult.preloadScripts;
9797
} catch (exception) {
9898
// If there was an error while parsing and executing a user loader, for example if because a
9999
// loader contained a syntax error, then we need to send the error to the main thread so it can
@@ -107,7 +107,7 @@ async function customizedModuleWorker(lock, syncCommPort, errorHandler) {
107107
if (hasInitializationError) {
108108
syncCommPort.postMessage(wrapMessage('error', initializationError));
109109
} else {
110-
syncCommPort.postMessage(wrapMessage('success', { preloadScripts }), preloadScripts.map(({ port }) => port));
110+
syncCommPort.postMessage(wrapMessage('success'));
111111
}
112112

113113
// We're ready, so unlock the main thread.

0 commit comments

Comments
 (0)