Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit f40894f

Browse files
obastemurchakrabot
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@4e2496ab03
[1.8>1.9] [MERGE #4574 @obastemur] module: fix re-entrant module importing Merge pull request #4574 from obastemur:fix_reent Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
1 parent aad4545 commit f40894f

File tree

7 files changed

+53
-18
lines changed

7 files changed

+53
-18
lines changed

deps/chakrashim/core/lib/Runtime/Language/SourceTextModuleRecord.cpp

Lines changed: 25 additions & 13 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++;
@@ -751,10 +751,18 @@ namespace Js
751751
if (requestedModuleList != nullptr)
752752
{
753753
EnsureChildModuleSet(scriptContext);
754+
ArenaAllocator* allocator = scriptContext->GeneralAllocator();
755+
SList<LPCOLESTR> * moduleRecords = Anew(allocator, SList<LPCOLESTR>, allocator);
756+
757+
// Reverse the order for the host. So, host can read the files top-down
754758
requestedModuleList->MapUntil([&](IdentPtr specifier) {
759+
LPCOLESTR moduleName = specifier->Psz();
760+
return !moduleRecords->Prepend(moduleName);
761+
});
762+
763+
moduleRecords->MapUntil([&](LPCOLESTR moduleName) {
755764
ModuleRecordBase* moduleRecordBase = nullptr;
756765
SourceTextModuleRecord* moduleRecord = nullptr;
757-
LPCOLESTR moduleName = specifier->Psz();
758766
bool itemFound = childrenModuleSet->TryGetValue(moduleName, &moduleRecord);
759767
if (!itemFound)
760768
{
@@ -779,6 +787,8 @@ namespace Js
779787
}
780788
return false;
781789
});
790+
moduleRecords->Clear();
791+
782792
if (FAILED(hr))
783793
{
784794
if (this->errorObject == nullptr)
@@ -827,20 +837,15 @@ namespace Js
827837
SetWasDeclarationInitialized();
828838
if (childrenModuleSet != nullptr)
829839
{
830-
childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
840+
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
831841
{
832-
Assert(moduleRecord->WasParsed());
833-
moduleRecord->shouldGenerateRootFunction =
834-
moduleRecord->ModuleDeclarationInstantiation();
842+
Assert(childModuleRecord->WasParsed());
843+
childModuleRecord->ModuleDeclarationInstantiation();
835844
});
836845

837-
childrenModuleSet->Map([](LPCOLESTR specifier, SourceTextModuleRecord* moduleRecord)
846+
childrenModuleSet->EachValue([=](SourceTextModuleRecord* childModuleRecord)
838847
{
839-
if (moduleRecord->shouldGenerateRootFunction)
840-
{
841-
moduleRecord->shouldGenerateRootFunction = false;
842-
moduleRecord->GenerateRootFunction();
843-
}
848+
childModuleRecord->GenerateRootFunction();
844849
});
845850
}
846851

@@ -866,6 +871,13 @@ namespace Js
866871

867872
void SourceTextModuleRecord::GenerateRootFunction()
868873
{
874+
// On cyclic dependency, we may endup generating the root function twice
875+
// so make sure we don't
876+
if (this->rootFunction != nullptr)
877+
{
878+
return;
879+
}
880+
869881
ScriptContext* scriptContext = GetScriptContext();
870882
Js::AutoDynamicCodeReference dynamicFunctionReference(scriptContext);
871883
CompileScriptException se;

deps/chakrashim/core/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+
}

deps/chakrashim/core/test/es6/bug_issue_3257_mod/mod0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55

6-
import '../bug_issue_3257_mod1.js';
7-
import '../bug_issue_3257_mod2/mod2.js';
6+
import 'bug_issue_3257_mod1.js';
7+
import 'bug_issue_3257_mod2/mod2.js';
88

99
console.log("mod0");

deps/chakrashim/core/test/es6/bug_issue_3257_mod2/mod2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55

6-
import '../bug_issue_3257_mod/mod0.js';
6+
import 'bug_issue_3257_mod/mod0.js';
77
console.log("mod2");

deps/chakrashim/core/test/es6/module-bugfixes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ var tests = [
6161
testRunner.LoadModule(functionBody);
6262
}
6363
},
64+
{
65+
name: "Issue 4570: Module that appears multiple times in dependency tree",
66+
body: function() {
67+
let functionBody = "import 'module_4570_dep1.js';"
68+
testRunner.LoadModule(functionBody);
69+
}
70+
}
6471
];
6572

6673
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
//tests import of module that has two different names
7+
import Thing1 from './module_4570_dep2.js';
8+
import Thing2 from '././module_4570_dep2.js';
9+
10+
Thing1();
11+
Thing2();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
export default function(){}

0 commit comments

Comments
 (0)