@@ -11,7 +11,6 @@ const {
1111 PromisePrototypeThen,
1212 RegExpPrototypeSymbolReplace,
1313 encodeURIComponent,
14- globalThis,
1514 hardenRegExp,
1615} = primordials ;
1716
@@ -23,11 +22,6 @@ const {
2322 kRequiredModuleSymbol,
2423} = require ( 'internal/modules/cjs/loader' ) ;
2524const { imported_cjs_symbol } = internalBinding ( 'symbols' ) ;
26- const {
27- privateSymbols : {
28- entry_point_module_private_symbol,
29- } ,
30- } = internalBinding ( 'util' ) ;
3125
3226const assert = require ( 'internal/assert' ) ;
3327const {
@@ -356,39 +350,6 @@ class ModuleLoader {
356350 return { wrap : job . module , namespace : job . runSync ( parent ) . namespace } ;
357351 }
358352
359- /**
360- * Load and evaluate the entry point module.
361- * The graph is always loaded and linked synchronously. When it contains no top-level
362- * await it is evaluated synchronously too, so startup creates no promises at all.
363- * When it does contain top-level await, evaluation falls back to `job.run()` here,
364- * reusing the job that was just built rather than making the caller re-enter the
365- * loader and redo the resolution and linking for the same module.
366- * @param {string } url The URL of the entry point module.
367- * @returns {ModuleJobSync|undefined } The job still needing asynchronous evaluation when
368- * the graph has top-level await, otherwise `undefined` - the module is then already
369- * fully evaluated and no promise was ever created.
370- */
371- importForEntryPoint ( url ) {
372- return onImport . traceSync ( ( ) => {
373- const request = { specifier : url , phase : kEvaluationPhase , attributes : kEmptyObject , __proto__ : null } ;
374- const job = this . getOrCreateModuleJob ( undefined , request , kImportInImportedESM ) ;
375- job . instantiateSync ( ) ;
376- if ( job . module . hasAsyncGraph ) {
377- // Hand the job back so the caller can evaluate it through the ordinary
378- // asynchronous entry point machinery, without re-resolving and re-linking
379- // the module the way re-entering `import()` would.
380- return job ;
381- }
382- globalThis [ entry_point_module_private_symbol ] = job . module ;
383- job . runSync ( ) ;
384- return undefined ;
385- } , {
386- __proto__ : null ,
387- parentURL : undefined ,
388- url,
389- } ) ;
390- }
391-
392353 /**
393354 * Check invariants on a cached module job when require()'d from ESM.
394355 * @param {string } specifier The first parameter of require().
@@ -611,14 +572,10 @@ class ModuleLoader {
611572 assert ( moduleOrModulePromise instanceof ModuleWrap , `Expected ModuleWrap for loading ${ url } ` ) ;
612573 }
613574
575+ // TODO(joyeecheung): use ModuleJobSync for kRequireInImportedCJS too.
576+ const ModuleJobCtor = ( requestType === kImportInRequiredESM ? ModuleJobSync : ModuleJob ) ;
614577 const isMain = ( parentURL === undefined ) ;
615578 const inspectBrk = ( isMain && getOptionValue ( '--inspect-brk' ) ) ;
616- // Use ModuleJobSync whenever we're on the main thread (not the async loader hook worker),
617- // except for kRequireInImportedCJS (TODO: consolidate that case too).
618- // TODO(joyeecheung): use ModuleJobSync for kRequireInImportedCJS too.
619- const ModuleJobCtor = ( this . isForAsyncLoaderHookWorker ||
620- requestType === kRequireInImportedCJS ) ?
621- ModuleJob : ModuleJobSync ;
622579 job = new ModuleJobCtor (
623580 this ,
624581 url ,
@@ -645,9 +602,8 @@ class ModuleLoader {
645602 */
646603 getOrCreateModuleJob ( parentURL , request , requestType ) {
647604 let maybePromise ;
648- if ( ! this . isForAsyncLoaderHookWorker ) {
649- // On the main thread, always resolve synchronously;
650- // `resolveSync` coordinates with the async loader hook worker if needed.
605+ if ( requestType === kRequireInImportedCJS || requestType === kImportInRequiredESM ) {
606+ // In these two cases, resolution must be synchronous.
651607 maybePromise = this . resolveSync ( parentURL , request ) ;
652608 assert ( ! isPromise ( maybePromise ) ) ;
653609 } else {
0 commit comments