@@ -42,7 +42,6 @@ namespace Js
42
42
isRootModule(false ),
43
43
hadNotifyHostReady(false ),
44
44
localExportSlots(nullptr ),
45
- numPendingChildrenModule(0 ),
46
45
moduleId(InvalidModuleIndex),
47
46
localSlotCount(InvalidSlotCount),
48
47
promise(nullptr ),
@@ -225,6 +224,11 @@ namespace Js
225
224
226
225
void SourceTextModuleRecord::NotifyParentsAsNeeded ()
227
226
{
227
+ if (notifying)
228
+ {
229
+ return ;
230
+ }
231
+ notifying = true ;
228
232
// Notify the parent modules that this child module is either in fault state or finished.
229
233
if (this ->parentModuleList != nullptr )
230
234
{
@@ -233,6 +237,7 @@ namespace Js
233
237
parentModule->OnChildModuleReady (this , this ->errorObject );
234
238
});
235
239
}
240
+ notifying = false ;
236
241
SetParentsNotified ();
237
242
}
238
243
@@ -326,7 +331,7 @@ namespace Js
326
331
OUTPUT_TRACE_DEBUGONLY (Js::ModulePhase, _u (" PrepareForModuleDeclarationInitialization(%s)\n " ), this ->GetSpecifierSz ());
327
332
HRESULT hr = NO_ERROR;
328
333
329
- if (numPendingChildrenModule == 0 )
334
+ if (ConfirmChildrenParsed () )
330
335
{
331
336
OUTPUT_TRACE_DEBUGONLY (Js::ModulePhase, _u (" \t >NotifyParentsAsNeeded\n " ));
332
337
NotifyParentsAsNeeded ();
@@ -355,12 +360,6 @@ namespace Js
355
360
}
356
361
}
357
362
}
358
- #if DBG
359
- else
360
- {
361
- OUTPUT_TRACE_DEBUGONLY (Js::ModulePhase, _u (" \t numPendingChildrenModule=(%d)\n " ), numPendingChildrenModule);
362
- }
363
- #endif
364
363
return hr;
365
364
}
366
365
@@ -399,12 +398,6 @@ namespace Js
399
398
}
400
399
else
401
400
{
402
- if (numPendingChildrenModule == 0 )
403
- {
404
- return NOERROR; // this is only in case of recursive module reference. Let the higher stack frame handle this module.
405
- }
406
- numPendingChildrenModule--;
407
-
408
401
hr = PrepareForModuleDeclarationInitialization ();
409
402
}
410
403
return hr;
@@ -715,21 +708,52 @@ namespace Js
715
708
{
716
709
parentRecord->childrenModuleSet ->AddNew (moduleName, this );
717
710
718
- if (! this ->WasParsed () )
711
+ if (this ->parentModuleList == nullptr )
719
712
{
720
- if (this ->parentModuleList == nullptr )
713
+ Recycler* recycler = GetScriptContext ()->GetRecycler ();
714
+ this ->parentModuleList = RecyclerNew (recycler, ModuleRecordList, recycler);
715
+ }
716
+
717
+ if (!this ->parentModuleList ->Contains (parentRecord))
718
+ {
719
+ this ->parentModuleList ->Add (parentRecord);
720
+ }
721
+ }
722
+ }
723
+
724
+ bool SourceTextModuleRecord::ConfirmChildrenParsed ()
725
+ {
726
+ if (!this ->WasParsed ())
727
+ {
728
+ return false ;
729
+ }
730
+ if (confirmedReady || this ->ParentsNotified ())
731
+ {
732
+ return true ;
733
+ }
734
+ bool result = true ;
735
+ confirmedReady = true ;
736
+ EnsureChildModuleSet (GetScriptContext ());
737
+ childrenModuleSet->EachValue ([&](SourceTextModuleRecord* childModuleRecord) {
738
+ if (childModuleRecord->ParentsNotified ())
739
+ {
740
+ return false ;
741
+ }
742
+ else
743
+ {
744
+ if (childModuleRecord->ConfirmChildrenParsed ())
721
745
{
722
- Recycler* recycler = GetScriptContext ()->GetRecycler ();
723
- this ->parentModuleList = RecyclerNew (recycler, ModuleRecordList, recycler);
746
+ return false ;
724
747
}
725
-
726
- if (!this ->parentModuleList ->Contains (parentRecord))
748
+ else
727
749
{
728
- this -> parentModuleList -> Add (parentRecord) ;
729
- parentRecord-> numPendingChildrenModule ++ ;
750
+ result = false ;
751
+ return true ;
730
752
}
731
753
}
732
- }
754
+ });
755
+ confirmedReady = false ;
756
+ return result;
733
757
}
734
758
735
759
void SourceTextModuleRecord::EnsureChildModuleSet (ScriptContext *scriptContext)
@@ -751,16 +775,9 @@ namespace Js
751
775
if (requestedModuleList != nullptr )
752
776
{
753
777
EnsureChildModuleSet (scriptContext);
754
- ArenaAllocator* allocator = scriptContext->GeneralAllocator ();
755
- SList<LPCOLESTR> * moduleRecords = Anew (allocator, SList<LPCOLESTR>, allocator);
756
778
757
- // Reverse the order for the host. So, host can read the files top-down
758
779
requestedModuleList->MapUntil ([&](IdentPtr specifier) {
759
780
LPCOLESTR moduleName = specifier->Psz ();
760
- return !moduleRecords->Prepend (moduleName);
761
- });
762
-
763
- moduleRecords->MapUntil ([&](LPCOLESTR moduleName) {
764
781
ModuleRecordBase* moduleRecordBase = nullptr ;
765
782
SourceTextModuleRecord* moduleRecord = nullptr ;
766
783
bool itemFound = childrenModuleSet->TryGetValue (moduleName, &moduleRecord);
@@ -787,7 +804,6 @@ namespace Js
787
804
}
788
805
return false ;
789
806
});
790
- moduleRecords->Clear ();
791
807
792
808
if (FAILED (hr))
793
809
{
0 commit comments