Skip to content

Commit f3fe28b

Browse files
committed
module: fix re-entrant module importing
1 parent 7fb608a commit f3fe28b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

lib/Runtime/Language/SourceTextModuleRecord.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ namespace Js
722722
Recycler* recycler = GetScriptContext()->GetRecycler();
723723
this->parentModuleList = RecyclerNew(recycler, ModuleRecordList, recycler);
724724
}
725-
bool contains = this->parentModuleList->Contains(parentRecord);
726-
if (!contains)
725+
726+
if (!this->parentModuleList->Contains(parentRecord))
727727
{
728728
this->parentModuleList->Add(parentRecord);
729729
parentRecord->numPendingChildrenModule++;
@@ -827,20 +827,15 @@ namespace Js
827827
SetWasDeclarationInitialized();
828828
if (childrenModuleSet != nullptr)
829829
{
830-
childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
830+
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
831831
{
832-
Assert(moduleRecord->WasParsed());
833-
moduleRecord->shouldGenerateRootFunction =
834-
moduleRecord->ModuleDeclarationInstantiation();
832+
Assert(childModuleRecord->WasParsed());
833+
childModuleRecord->ModuleDeclarationInstantiation();
835834
});
836835

837-
childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
836+
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
838837
{
839-
if (moduleRecord->shouldGenerateRootFunction)
840-
{
841-
moduleRecord->shouldGenerateRootFunction = false;
842-
moduleRecord->GenerateRootFunction();
843-
}
838+
childModuleRecord->GenerateRootFunction();
844839
});
845840
}
846841

@@ -866,6 +861,11 @@ namespace Js
866861

867862
void SourceTextModuleRecord::GenerateRootFunction()
868863
{
864+
if (this->rootFunction != nullptr)
865+
{
866+
return;
867+
}
868+
869869
ScriptContext* scriptContext = GetScriptContext();
870870
Js::AutoDynamicCodeReference dynamicFunctionReference(scriptContext);
871871
CompileScriptException se;

lib/Runtime/Language/SourceTextModuleRecord.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ namespace Js
117117
// TODO: move non-GC fields out to avoid false reference?
118118
// This is the parsed tree resulted from compilation.
119119
Field(bool) wasParsed;
120-
Field(bool) shouldGenerateRootFunction;
121120
Field(bool) wasDeclarationInitialized;
122121
Field(bool) parentsNotified;
123122
Field(bool) isRootModule;
@@ -178,4 +177,4 @@ namespace Js
178177
uint moduleId;
179178
Field(Var)* localExportSlotsAddr;
180179
};
181-
}
180+
}

0 commit comments

Comments
 (0)