Skip to content

Commit 1b7b5ac

Browse files
committed
[MERGE chakra-core#2550 @pleath] Fix byte code gen with block-scoped function called from with and captured elsewhere.
Merge pull request chakra-core#2550 from pleath:10735999 Make sure that if some references to a block-scoped function are optimized to refer to the var-scoped binding and others are not, and both bindings are marked for closure capture, then both scopes are processed accordingly.
2 parents 65ab57b + 989f86d commit 1b7b5ac

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,9 @@ Symbol * ByteCodeGenerator::FindSymbol(Symbol **symRef, IdentPtr pid, bool forRe
16871687
sym->SetHasRealBlockVarRef();
16881688
}
16891689

1690-
if (nonLocalRef)
1690+
// This may not be a non-local reference, but the symbol may still be accessed non-locally. ('with', e.g.)
1691+
// In that case, make sure we still process the symbol and its scope for closure capture.
1692+
if (nonLocalRef || sym->GetHasNonLocalReference())
16911693
{
16921694
// Symbol referenced through a closure. Mark it as such and give it a property ID.
16931695
this->ProcessCapturedSym(sym);

test/Closures/bug_OS_10735999.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
function test0() {
7+
var obj1 = {};
8+
var func0 = function () {
9+
if (true) {
10+
function func5() {
11+
return function () {
12+
(function () {
13+
func5;
14+
});
15+
}();
16+
}
17+
with ({}) {
18+
argMath2 = func5.call(obj1);
19+
}
20+
}
21+
};
22+
func0();
23+
}
24+
test0();
25+
WScript.Echo('pass');

test/Closures/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,10 @@
164164
<tags>BugFix,exclude_dynapogo</tags>
165165
</default>
166166
</test>
167+
<test>
168+
<default>
169+
<files>bug_OS_10735999.js</files>
170+
<tags>BugFix</tags>
171+
</default>
172+
</test>
167173
</regress-exe>

0 commit comments

Comments
 (0)