Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions lib/Runtime/Language/SourceTextModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ namespace Js
Recycler* recycler = GetScriptContext()->GetRecycler();
this->parentModuleList = RecyclerNew(recycler, ModuleRecordList, recycler);
}
bool contains = this->parentModuleList->Contains(parentRecord);
if (!contains)

if (!this->parentModuleList->Contains(parentRecord))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My branch wasn't updated hence there was an assert(!contains) here. That's why the change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert was wrong - I have removed that.


In reply to: 162434163 [](ancestors = 162434163)

{
this->parentModuleList->Add(parentRecord);
parentRecord->numPendingChildrenModule++;
Expand Down Expand Up @@ -751,10 +751,18 @@ namespace Js
if (requestedModuleList != nullptr)
{
EnsureChildModuleSet(scriptContext);
ArenaAllocator* allocator = scriptContext->GeneralAllocator();
SList<LPCOLESTR> * moduleRecords = Anew(allocator, SList<LPCOLESTR>, allocator);

// Reverse the order for the host. So, host can read the files top-down
requestedModuleList->MapUntil([&](IdentPtr specifier) {
LPCOLESTR moduleName = specifier->Psz();
return !moduleRecords->Prepend(moduleName);
});

moduleRecords->MapUntil([&](LPCOLESTR moduleName) {
ModuleRecordBase* moduleRecordBase = nullptr;
SourceTextModuleRecord* moduleRecord = nullptr;
LPCOLESTR moduleName = specifier->Psz();
bool itemFound = childrenModuleSet->TryGetValue(moduleName, &moduleRecord);
if (!itemFound)
{
Expand All @@ -779,6 +787,8 @@ namespace Js
}
return false;
});
moduleRecords->Clear();

if (FAILED(hr))
{
if (this->errorObject == nullptr)
Expand Down Expand Up @@ -827,20 +837,15 @@ namespace Js
SetWasDeclarationInitialized();
if (childrenModuleSet != nullptr)
{
childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
{
Assert(moduleRecord->WasParsed());
moduleRecord->shouldGenerateRootFunction =
moduleRecord->ModuleDeclarationInstantiation();
Assert(childModuleRecord->WasParsed());
childModuleRecord->ModuleDeclarationInstantiation();
});

childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
{
if (moduleRecord->shouldGenerateRootFunction)
{
moduleRecord->shouldGenerateRootFunction = false;
moduleRecord->GenerateRootFunction();
}
childModuleRecord->GenerateRootFunction();
});
}

Expand All @@ -866,6 +871,13 @@ namespace Js

void SourceTextModuleRecord::GenerateRootFunction()
{
// On cyclic dependency, we may endup generating the root function twice
// so make sure we don't
if (this->rootFunction != nullptr)
{
return;
}

ScriptContext* scriptContext = GetScriptContext();
Js::AutoDynamicCodeReference dynamicFunctionReference(scriptContext);
CompileScriptException se;
Expand Down
3 changes: 1 addition & 2 deletions lib/Runtime/Language/SourceTextModuleRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ namespace Js
// TODO: move non-GC fields out to avoid false reference?
// This is the parsed tree resulted from compilation.
Field(bool) wasParsed;
Field(bool) shouldGenerateRootFunction;
Field(bool) wasDeclarationInitialized;
Field(bool) parentsNotified;
Field(bool) isRootModule;
Expand Down Expand Up @@ -178,4 +177,4 @@ namespace Js
uint moduleId;
Field(Var)* localExportSlotsAddr;
};
}
}
4 changes: 2 additions & 2 deletions test/es6/bug_issue_3257_mod/mod0.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

import '../bug_issue_3257_mod1.js';
import '../bug_issue_3257_mod2/mod2.js';
import 'bug_issue_3257_mod1.js';
import 'bug_issue_3257_mod2/mod2.js';

console.log("mod0");
2 changes: 1 addition & 1 deletion test/es6/bug_issue_3257_mod2/mod2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

import '../bug_issue_3257_mod/mod0.js';
import 'bug_issue_3257_mod/mod0.js';
console.log("mod2");
7 changes: 7 additions & 0 deletions test/es6/module-bugfixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ var tests = [
testRunner.LoadModule(functionBody);
}
},
{
name: "Issue 4570: Module that appears multiple times in dependency tree",
body: function() {
let functionBody = "import 'module_4570_dep1.js';"
testRunner.LoadModule(functionBody);
}
}
];

testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
11 changes: 11 additions & 0 deletions test/es6/module_4570_dep1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

//tests import of module that has two different names
import Thing1 from './module_4570_dep2.js';
import Thing2 from '././module_4570_dep2.js';

Thing1();
Thing2();
6 changes: 6 additions & 0 deletions test/es6/module_4570_dep2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

export default function(){}