Skip to content

Commit d71347c

Browse files
committed
[MERGE #1388 @pleath] Simple fix to tracking of nested functions containing 'with'
Merge pull request #1388 from pleath:with Call to a nested function from within a 'with' requires that the function's enclosing scope be represented as an object. We were missing a case where the function is located in a param scope that will later be merge with a body scope. Also adding asserts to verify the object-ness of a scope when we're generating byte code that requires it.
2 parents 226a96e + 675a831 commit d71347c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4548,6 +4548,7 @@ void ByteCodeGenerator::EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot
45484548

45494549
Js::RegSlot tmpReg = funcInfo->AcquireTmpRegister();
45504550

4551+
Assert(scope->GetIsObject());
45514552
this->m_writer.SlotI1(Js::OpCode::LdEnvObj, tmpReg,
45524553
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));
45534554

@@ -4567,6 +4568,7 @@ void ByteCodeGenerator::EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot
45674568
funcInfo->FindOrAddReferencedPropertyId(propertyId));
45684569

45694570
Assert(!unwrapWithObj);
4571+
Assert(scope->GetIsObject());
45704572
this->m_writer.Reg1(Js::OpCode::LdLocalObj, instLocation);
45714573
if (thisLocation != Js::Constants::NoRegister)
45724574
{
@@ -4639,6 +4641,7 @@ void ByteCodeGenerator::EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot
46394641
{
46404642
if (envIndex != -1)
46414643
{
4644+
Assert(scope->GetIsObject());
46424645
this->m_writer.SlotI1(Js::OpCode::LdEnvObj, instLocation,
46434646
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));
46444647
}
@@ -4913,6 +4916,7 @@ void ByteCodeGenerator::EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, Iden
49134916

49144917
Js::RegSlot instLocation = funcInfo->AcquireTmpRegister();
49154918

4919+
Assert(scope->GetIsObject());
49164920
this->m_writer.SlotI1(
49174921
Js::OpCode::LdEnvObj,
49184922
instLocation,
@@ -5204,6 +5208,7 @@ void ByteCodeGenerator::EmitPropLoad(Js::RegSlot lhsLocation, Symbol *sym, Ident
52045208

52055209
Js::RegSlot instLocation = funcInfo->AcquireTmpRegister();
52065210

5211+
Assert(scope->GetIsObject());
52075212
this->m_writer.SlotI1(
52085213
Js::OpCode::LdEnvObj,
52095214
instLocation,
@@ -5444,6 +5449,7 @@ void ByteCodeGenerator::EmitPropDelete(Js::RegSlot lhsLocation, Symbol *sym, Ide
54445449

54455450
Js::RegSlot instLocation = funcInfo->AcquireTmpRegister();
54465451

5452+
Assert(scope->GetIsObject());
54475453
this->m_writer.SlotI1(
54485454
Js::OpCode::LdEnvObj,
54495455
instLocation,
@@ -5613,6 +5619,7 @@ void ByteCodeGenerator::EmitPropTypeof(Js::RegSlot lhsLocation, Symbol *sym, Ide
56135619

56145620
Js::RegSlot instLocation = funcInfo->AcquireTmpRegister();
56155621

5622+
Assert(scope->GetIsObject());
56165623
this->m_writer.SlotI1(Js::OpCode::LdEnvObj,
56175624
instLocation,
56185625
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,9 @@ FuncInfo* PostVisitFunction(ParseNode* pnode, ByteCodeGenerator* byteCodeGenerat
28092809

28102810
parentFunc->SetChildHasWith();
28112811

2812-
if (parentFunc->GetBodyScope()->GetHasOwnLocalInClosure())
2812+
if (parentFunc->GetBodyScope()->GetHasOwnLocalInClosure() ||
2813+
(parentFunc->GetParamScope()->GetHasOwnLocalInClosure() &&
2814+
parentFunc->GetParamScope()->GetCanMergeWithBodyScope()))
28132815
{
28142816
parentFunc->GetBodyScope()->SetIsObject();
28152817
// Record this for future use in the no-refresh debugging.

0 commit comments

Comments
 (0)