Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions benchmark/esm/startup-esm-graph.js

This file was deleted.

52 changes: 4 additions & 48 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
PromisePrototypeThen,
RegExpPrototypeSymbolReplace,
encodeURIComponent,
globalThis,
hardenRegExp,
} = primordials;

Expand All @@ -23,11 +22,6 @@ const {
kRequiredModuleSymbol,
} = require('internal/modules/cjs/loader');
const { imported_cjs_symbol } = internalBinding('symbols');
const {
privateSymbols: {
entry_point_module_private_symbol,
},
} = internalBinding('util');

const assert = require('internal/assert');
const {
Expand Down Expand Up @@ -356,39 +350,6 @@ class ModuleLoader {
return { wrap: job.module, namespace: job.runSync(parent).namespace };
}

/**
* Load and evaluate the entry point module.
* The graph is always loaded and linked synchronously. When it contains no top-level
* await it is evaluated synchronously too, so startup creates no promises at all.
* When it does contain top-level await, evaluation falls back to `job.run()` here,
* reusing the job that was just built rather than making the caller re-enter the
* loader and redo the resolution and linking for the same module.
* @param {string} url The URL of the entry point module.
* @returns {ModuleJobSync|undefined} The job still needing asynchronous evaluation when
* the graph has top-level await, otherwise `undefined` - the module is then already
* fully evaluated and no promise was ever created.
*/
importForEntryPoint(url) {
return onImport.traceSync(() => {
const request = { specifier: url, phase: kEvaluationPhase, attributes: kEmptyObject, __proto__: null };
const job = this.getOrCreateModuleJob(undefined, request, kImportInImportedESM);
job.instantiateSync();
if (job.module.hasAsyncGraph) {
// Hand the job back so the caller can evaluate it through the ordinary
// asynchronous entry point machinery, without re-resolving and re-linking
// the module the way re-entering `import()` would.
return job;
}
globalThis[entry_point_module_private_symbol] = job.module;
job.runSync();
return undefined;
}, {
__proto__: null,
parentURL: undefined,
url,
});
}

/**
* Check invariants on a cached module job when require()'d from ESM.
* @param {string} specifier The first parameter of require().
Expand Down Expand Up @@ -611,14 +572,10 @@ class ModuleLoader {
assert(moduleOrModulePromise instanceof ModuleWrap, `Expected ModuleWrap for loading ${url}`);
}

// TODO(joyeecheung): use ModuleJobSync for kRequireInImportedCJS too.
const ModuleJobCtor = (requestType === kImportInRequiredESM ? ModuleJobSync : ModuleJob);
const isMain = (parentURL === undefined);
const inspectBrk = (isMain && getOptionValue('--inspect-brk'));
// Use ModuleJobSync whenever we're on the main thread (not the async loader hook worker),
// except for kRequireInImportedCJS (TODO: consolidate that case too).
// TODO(joyeecheung): use ModuleJobSync for kRequireInImportedCJS too.
const ModuleJobCtor = (this.isForAsyncLoaderHookWorker ||
requestType === kRequireInImportedCJS) ?
ModuleJob : ModuleJobSync;
job = new ModuleJobCtor(
this,
url,
Expand All @@ -645,9 +602,8 @@ class ModuleLoader {
*/
getOrCreateModuleJob(parentURL, request, requestType) {
let maybePromise;
if (!this.isForAsyncLoaderHookWorker) {
// On the main thread, always resolve synchronously;
// `resolveSync` coordinates with the async loader hook worker if needed.
if (requestType === kRequireInImportedCJS || requestType === kImportInRequiredESM) {
// In these two cases, resolution must be synchronous.
maybePromise = this.resolveSync(parentURL, request);
assert(!isPromise(maybePromise));
} else {
Expand Down
Loading
Loading