Skip to content

Commit 664a9bd

Browse files
committed
Fix byte code gen for function-in-block in eval. An optimization to permit redeferral of function-in-block was missing a legality check in eval code.
1 parent f1d4d8d commit 664a9bd

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,11 +3834,13 @@ void ByteCodeGenerator::StartEmitFunction(ParseNode *pnodeFnc)
38343834

38353835
FuncInfo *funcInfo = pnodeFnc->sxFnc.funcInfo;
38363836

3837-
if (funcInfo->byteCodeFunction->IsFunctionParsed() &&
3838-
!(flags & (fscrEval | fscrImplicitThis | fscrImplicitParents)))
3837+
if (funcInfo->byteCodeFunction->IsFunctionParsed())
38393838
{
3840-
// Only set the environment depth if it's truly known (i.e., not in eval or event handler).
3841-
funcInfo->GetParsedFunctionBody()->SetEnvDepth(this->envDepth);
3839+
if (!(flags & (fscrEval | fscrImplicitThis | fscrImplicitParents)))
3840+
{
3841+
// Only set the environment depth if it's truly known (i.e., not in eval or event handler).
3842+
funcInfo->GetParsedFunctionBody()->SetEnvDepth(this->envDepth);
3843+
}
38423844

38433845
if (pnodeFnc->sxFnc.FIBPreventsDeferral())
38443846
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
eval(
7+
'function outer() {' +
8+
' var f = "f";' +
9+
' if (true) {' +
10+
' let o = { x : function() { if (f !== "f") { WScript.Echo("fail"); throw 1; } } };' +
11+
' function i() {}' +
12+
' o.x();' +
13+
' }' +
14+
'}');
15+
16+
for (var i = 0; i < 100; i++)
17+
arr = [10000];
18+
outer();
19+
WScript.Echo('pass');

test/Function/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,10 @@
443443
<baseline>redefer-recursive-inlinees.baseline</baseline>
444444
</default>
445445
</test>
446+
<test>
447+
<default>
448+
<files>redefer-f-i-b-eval.js</files>
449+
<compile-flags>-force:deferparse -force:redeferral</compile-flags>
450+
</default>
451+
</test>
446452
</regress-exe>

0 commit comments

Comments
 (0)