@@ -329,7 +329,7 @@ class ModuleJobBase {
329329 debug ( `ModuleJobBase.syncLink() ${ this . url } -> ${ request . specifier } ` , job ) ;
330330 assert ( ! isPromise ( job ) ) ;
331331 assert ( job . module instanceof ModuleWrap ) ;
332- if ( this . shouldRunModule ( request . phase ) ) {
332+ if ( this . shouldEvaluateModule ( request . phase ) ) {
333333 ArrayPrototypePush ( evaluationDepJobs , job ) ;
334334 }
335335 modules [ idx ] = job . module ;
@@ -383,7 +383,7 @@ class ModuleJobBase {
383383 shouldLinkModule ( phase ) {
384384 return phase >= kDeferPhase ;
385385 }
386- shouldRunModule ( phase ) {
386+ shouldEvaluateModule ( phase ) {
387387 return phase === kEvaluationPhase ;
388388 }
389389}
@@ -466,7 +466,7 @@ class ModuleJob extends ModuleJobBase {
466466 const dependencyJobPromise = this . loader . getOrCreateModuleJob ( this . url , request , requestType ) ;
467467 const modulePromise = PromisePrototypeThen ( dependencyJobPromise , ( job ) => {
468468 debug ( `ModuleJob.asyncLink() ${ this . url } -> ${ request . specifier } ` , job ) ;
469- if ( this . shouldRunModule ( request . phase ) ) {
469+ if ( this . shouldEvaluateModule ( request . phase ) ) {
470470 ArrayPrototypePush ( evaluationDepJobs , job ) ;
471471 }
472472 return job . modulePromise ;
@@ -521,7 +521,7 @@ class ModuleJob extends ModuleJobBase {
521521 }
522522
523523 runSync ( parent ) {
524- assert ( this . shouldRunModule ( this . phase ) ) ;
524+ assert ( this . shouldEvaluateModule ( this . phase ) ) ;
525525 assert ( this . module instanceof ModuleWrap ) ;
526526 let status = this . module . getStatus ( ) ;
527527
@@ -561,17 +561,17 @@ class ModuleJob extends ModuleJobBase {
561561 }
562562
563563 async run ( isEntryPoint = false ) {
564- debug ( 'ModuleJob.run()' , this . module ) ;
565- assert ( this . shouldRunModule ( this . phase ) ) ;
564+ debug ( 'ModuleJob.run(); phase: ' , this . phase , this . module ) ;
566565 await this . #instantiate( ) ;
567566 if ( isEntryPoint ) {
568567 globalThis [ entry_point_module_private_symbol ] = this . module ;
569568 }
569+
570570 const timeout = - 1 ;
571571 const breakOnSigint = false ;
572572 setHasStartedUserESMExecution ( ) ;
573573 try {
574- await this . module . evaluate ( timeout , breakOnSigint ) ;
574+ await this . module . evaluate ( timeout , breakOnSigint , this . phase ) ;
575575 } catch ( e ) {
576576 explainCommonJSGlobalLikeNotDefinedError ( e , this . module . url , this . module . hasTopLevelAwait ) ;
577577 throw e ;
@@ -641,7 +641,8 @@ class ModuleJobSync extends ModuleJobBase {
641641 }
642642
643643 async run ( isEntryPoint = false ) {
644- assert ( this . shouldRunModule ( this . phase ) ) ;
644+ assert ( this . shouldEvaluateModule ( this . phase ) ) ;
645+ // This path is hit by a require'd module that is imported again.
645646 const status = this . module . getStatus ( ) ;
646647 debug ( 'ModuleJobSync.run()' , status , this . module ) ;
647648 // If the module was previously required and errored, reject from import() again.
@@ -676,7 +677,7 @@ class ModuleJobSync extends ModuleJobBase {
676677 const { callAndPauseOnStart } = internalBinding ( 'inspector' ) ;
677678 this . evaluationPromise = callAndPauseOnStart ( this . module . evaluate , this . module , timeout , breakOnSigint ) ;
678679 } else {
679- this . evaluationPromise = this . module . evaluate ( timeout , breakOnSigint ) ;
680+ this . evaluationPromise = this . module . evaluate ( timeout , breakOnSigint , this . phase ) ;
680681 }
681682 await this . evaluationPromise ;
682683 this . evaluationPromise = undefined ;
@@ -704,7 +705,7 @@ class ModuleJobSync extends ModuleJobBase {
704705
705706 runSync ( parent ) {
706707 debug ( 'ModuleJobSync.runSync()' , this . module ) ;
707- assert ( this . shouldRunModule ( this . phase ) ) ;
708+ assert ( this . shouldEvaluateModule ( this . phase ) ) ;
708709 // TODO(joyeecheung): Reject graphs with top-level await _before_ instantiation, so that the
709710 // async graph error supersedes instantiation (mismatch export) errors in the graph.
710711 this . instantiateSync ( ) ;
0 commit comments