@@ -26,6 +26,8 @@ import { compartmentEvaluate } from './compartment-evaluate.js';
2626
2727const { quote : q } = assert ;
2828
29+ let id = 0 ;
30+
2931export const makeVirtualModuleInstance = (
3032 compartmentPrivateFields ,
3133 moduleSource ,
@@ -372,26 +374,14 @@ export const makeModuleInstance = (
372374 // export * cannot export default.
373375 const candidateAll = create ( null ) ;
374376 candidateAll . default = false ;
375- for ( const [ specifier , importUpdaters ] of updateRecord ) {
377+
378+ for ( const [ specifier ] of updateRecord ) {
376379 const instance = mapGet ( importedInstances , specifier ) ;
377380 // The module instance object is an internal literal, does not bind this,
378381 // and never revealed outside the SES shim.
379382 // There are two instantiation sites for instances and they are both in
380383 // this module.
381- // eslint-disable-next-line @endo/no-polymorphic-call
382- instance . execute ( ) ; // bottom up cycle tolerant
383384 const { notifiers : importNotifiers } = instance ;
384- for ( const [ importName , updaters ] of importUpdaters ) {
385- const importNotify = importNotifiers [ importName ] ;
386- if ( ! importNotify ) {
387- throw SyntaxError (
388- `The requested module '${ specifier } ' does not provide an export named '${ importName } '` ,
389- ) ;
390- }
391- for ( const updater of updaters ) {
392- importNotify ( updater ) ;
393- }
394- }
395385 if ( arrayIncludes ( exportAlls , specifier ) ) {
396386 // Make all these imports candidates.
397387 // Note names don't change in reexporting all
@@ -433,6 +423,26 @@ export const makeModuleInstance = (
433423 }
434424 }
435425
426+ // this must happen _after_ the previous loop so that re-exported names
427+ // have associated import notifiers
428+ for ( const [ specifier , importUpdaters ] of updateRecord ) {
429+ const instance = mapGet ( importedInstances , specifier ) ;
430+ // eslint-disable-next-line @endo/no-polymorphic-call
431+ instance . execute ( ) ; // bottom up cycle tolerant
432+ const { notifiers : importNotifiers } = instance ;
433+ for ( const [ importName , updaters ] of importUpdaters ) {
434+ const importNotify = importNotifiers [ importName ] ;
435+ if ( ! importNotify ) {
436+ throw SyntaxError (
437+ `The requested module '${ specifier } ' does not provide an export named '${ importName } '` ,
438+ ) ;
439+ }
440+ for ( const updater of updaters ) {
441+ importNotify ( updater ) ;
442+ }
443+ }
444+ }
445+
436446 // Sort the module exports namespace as per spec.
437447 // The module exports namespace will be wrapped in a module namespace
438448 // exports proxy which will serve as a "module exports namespace exotic
@@ -493,5 +503,6 @@ export const makeModuleInstance = (
493503 notifiers,
494504 exportsProxy,
495505 execute,
506+ id : ( id += 1 ) ,
496507 } ) ;
497508} ;
0 commit comments