Skip to content

Commit 106848c

Browse files
committed
Correctly handle named function expressions when saving ScopeInfo
Previous fix for a similar issue #6157 didn't handle the case of a function expression in which the param and function expression scopes are merged with the body scope. In that case, the function defined in the param scope needs to have access to the body scope of the enclosing function. Fixes: https://microsoft.visualstudio.com/OS/_workitems/edit/18926499/
1 parent 9f72ec4 commit 106848c

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

lib/Runtime/ByteCode/ScopeInfo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,20 @@ namespace Js
162162
Scope* currentScope = byteCodeGenerator->GetCurrentScope();
163163
Assert(currentScope->GetFunc() == funcInfo);
164164

165-
// Disable the below temporarily because of bad interaction with named function expressions
166-
#if 0
167165
if (funcInfo->root->IsDeclaredInParamScope()) {
168166
Assert(currentScope->GetScopeType() == ScopeType_FunctionBody);
169167
Assert(currentScope->GetEnclosingScope());
170168

171169
FuncInfo* func = currentScope->GetEnclosingScope()->GetFunc();
172170
Assert(func);
173171

174-
if (func->IsBodyAndParamScopeMerged())
172+
if (func->IsBodyAndParamScopeMerged() && !(func->funcExprScope && func->funcExprScope->GetCanMerge()))
175173
{
176174
currentScope = func->GetParamScope();
177175
Assert(currentScope->GetScopeType() == ScopeType_Parameter);
178176
Assert(!currentScope->GetMustInstantiate());
179177
}
180178
}
181-
#endif
182179

183180
while (currentScope->GetFunc() == funcInfo)
184181
{

test/Bugs/bug_OS18926499.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,26 @@ try {
2323
} catch {
2424
console.log('pass');
2525
}
26+
27+
var foo3 = function foo3a(a = (function foo3b() { foo3a; })()) {
28+
a;
29+
};
30+
31+
try {
32+
foo3()
33+
console.log('pass');
34+
} catch {
35+
console.log('fail');
36+
}
37+
38+
var foo4 = function foo4a(a = (function() { +x; })()) {
39+
function bar() { eval(''); }
40+
var x;
41+
};
42+
43+
try {
44+
foo4()
45+
console.log('fail');
46+
} catch {
47+
console.log('pass');
48+
}

test/Bugs/rlexe.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,12 @@
582582
<compile-flags>-args summary -endargs</compile-flags>
583583
</default>
584584
</test>
585-
<!--
586-
Re-enable after fixing ScopeInfo::SaveEnclosingScopeInfo to handle named function expressions
587585
<test>
588586
<default>
589587
<files>bug_OS18926499.js</files>
590588
<compile-flags>-force:deferparse</compile-flags>
591589
</default>
592590
</test>
593-
-->
594591
<test>
595592
<default>
596593
<files>Bug19767482.js</files>

0 commit comments

Comments
 (0)