Skip to content

Commit e76b30e

Browse files
committed
[1.6>1.7] [MERGE #3389 @sigatrev] OS#12528802 fix crash accessing FuncObjectOpnd when function object is inlined
Merge pull request #3389 from sigatrev:NewScopeObject
2 parents 8cfe47d + 6184421 commit e76b30e

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

lib/Backend/Lower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
306306
this->m_lowererMD.LoadHelperArgument(instr, IR::IntConstOpnd::New(currFunc->GetHasNonSimpleParams() ? TRUE : FALSE, TyUint8, currFunc));
307307

308308
// s2 = current function.
309-
IR::Opnd * paramOpnd = GetFuncObjectOpnd(instr);
309+
IR::Opnd * paramOpnd = LoadFunctionBodyOpnd(instr);
310310
this->m_lowererMD.LoadHelperArgument(instr, paramOpnd);
311311

312312
m_lowererMD.ChangeToHelperCallMem(instr, IR::HelperOP_NewScopeObjectWithFormals);

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7002,15 +7002,15 @@ namespace Js
70027002
return scriptContext->GetLibrary()->CreateActivationObject();
70037003
}
70047004

7005-
Var JavascriptOperators::OP_NewScopeObjectWithFormals(ScriptContext* scriptContext, JavascriptFunction * funcCallee, bool nonSimpleParamList)
7005+
Var JavascriptOperators::OP_NewScopeObjectWithFormals(ScriptContext* scriptContext, FunctionBody * calleeBody, bool nonSimpleParamList)
70067006
{
70077007
Js::ActivationObject * frameObject = (ActivationObject*)OP_NewScopeObject(scriptContext);
70087008
// No fixed fields for formal parameters of the arguments object. Also, mark all fields as initialized up-front, because
70097009
// we will set them directly using SetSlot below, so the type handler will not have a chance to mark them as initialized later.
70107010
// CONSIDER : When we delay type sharing until the second instance is created, pass an argument indicating we want the types
70117011
// and handlers created here to be marked as shared up-front. This is to ensure we don't get any fixed fields and that the handler
70127012
// is ready for storing values directly to slots.
7013-
DynamicType* newType = PathTypeHandlerBase::CreateNewScopeObject(scriptContext, frameObject->GetDynamicType(), funcCallee->GetFunctionBody()->GetFormalsPropIdArray(), nonSimpleParamList ? PropertyLetDefaults : PropertyNone);
7013+
DynamicType* newType = PathTypeHandlerBase::CreateNewScopeObject(scriptContext, frameObject->GetDynamicType(), calleeBody->GetFormalsPropIdArray(), nonSimpleParamList ? PropertyLetDefaults : PropertyNone);
70147014

70157015
int oldSlotCapacity = frameObject->GetDynamicType()->GetTypeHandler()->GetSlotCapacity();
70167016
int newSlotCapacity = newType->GetTypeHandler()->GetSlotCapacity();

lib/Runtime/Language/JavascriptOperators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ namespace Js
453453
static void OP_InvalidateCachedScope(Var varEnv, int32 envIndex);
454454
static void OP_InitCachedFuncs(Var varScope, FrameDisplay *pDisplay, const FuncInfoArray *info, ScriptContext *scriptContext);
455455
static Var OP_NewScopeObject(ScriptContext* scriptContext);
456-
static Var OP_NewScopeObjectWithFormals(ScriptContext* scriptContext, JavascriptFunction * funcCallee, bool nonSimpleParamList);
456+
static Var OP_NewScopeObjectWithFormals(ScriptContext* scriptContext, FunctionBody * calleeBody, bool nonSimpleParamList);
457457
static Field(Var)* OP_NewScopeSlots(unsigned int count, ScriptContext *scriptContext, Var scope);
458458
static Field(Var)* OP_NewScopeSlotsWithoutPropIds(unsigned int count, int index, ScriptContext *scriptContext, FunctionBody *functionBody);
459459
static Field(Var)* OP_CloneScopeSlots(Field(Var) *scopeSlots, ScriptContext *scriptContext);

test/inlining/bug12528802.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
var obj = { foo : function() {} };
7+
8+
function bar(arg)
9+
{
10+
obj.foo.apply(obj, arguments);
11+
let local;
12+
let baz = function() { local; };
13+
}
14+
15+
function test()
16+
{
17+
bar();
18+
}
19+
20+
test();
21+
test();
22+
test();
23+
24+
WScript.Echo("PASSED");

test/inlining/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,9 @@
284284
<files>bug11265991.js</files>
285285
</default>
286286
</test>
287+
<test>
288+
<default>
289+
<files>bug12528802.js</files>
290+
</default>
291+
</test>
287292
</regress-exe>

0 commit comments

Comments
 (0)