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

Commit

Permalink
deps: update ChakraCore to chakra-core/ChakraCore@4e2496ab03
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
obastemur authored and chakrabot committed Jan 19, 2018
1 parent aad4545 commit f40894f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
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))
{
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
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 deps/chakrashim/core/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 deps/chakrashim/core/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 deps/chakrashim/core/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 deps/chakrashim/core/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 deps/chakrashim/core/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(){}

0 comments on commit f40894f

Please sign in to comment.