@@ -630,6 +630,16 @@ class ModuleJobSync extends ModuleJobBase {
630630 return PromiseResolve ( this . module ) ;
631631 }
632632
633+ instantiateSync ( ) {
634+ try {
635+ this . module . instantiate ( ) ;
636+ } catch ( error ) {
637+ decorateErrorStack ( error ) ;
638+ handleCJSNamedExportError ( error , this . module , this . commonJsDeps ) ;
639+ throw error ;
640+ }
641+ }
642+
633643 async run ( isEntryPoint = false ) {
634644 assert ( this . shouldRunModule ( this . phase ) ) ;
635645 const status = this . module . getStatus ( ) ;
@@ -650,13 +660,7 @@ class ModuleJobSync extends ModuleJobBase {
650660 // or one that was initially require()'d and is now being imported after its instantiation
651661 // failed (e.g. a missing named export). Try finishing the instantiation: if it succeeds,
652662 // proceed to evaluation, otherwise re-throw the instantiation error.
653- try {
654- this . module . instantiate ( ) ;
655- } catch ( error ) {
656- decorateErrorStack ( error ) ;
657- handleCJSNamedExportError ( error , this . module , this . commonJsDeps ) ;
658- throw error ;
659- }
663+ this . instantiateSync ( ) ;
660664 }
661665 // `status === kInstantiated`: either just instantiated above, or previously instantiated
662666 // but evaluation was deferred (e.g. TLA detected by a prior `runSync()` call)
@@ -703,8 +707,7 @@ class ModuleJobSync extends ModuleJobBase {
703707 assert ( this . shouldRunModule ( this . phase ) ) ;
704708 // TODO(joyeecheung): Reject graphs with top-level await _before_ instantiation, so that the
705709 // async graph error supersedes instantiation (mismatch export) errors in the graph.
706- // TODO(joyeecheung): add the error decoration logic from the async instantiate.
707- this . module . instantiate ( ) ;
710+ this . instantiateSync ( ) ;
708711 // On the deprecated async loader hook worker thread, dependencies linked by an
709712 // earlier import may not be walkable synchronously, so double-check with
710713 // V8 now that the graph is instantiated.
0 commit comments