Skip to content

Commit 03fba5c

Browse files
author
Jianchun Xu
committed
fix incorrect debugger mode reparse after function redefer
Debug mode reparse should still set "reuseNestedFunc", otherwise we'll discard existing nested func info and create new FunctionInfo/FunctionBody for nested functions, conflicting with existing ones. Existing debug mode reparse also not expecting function redefer introduced ParseableFunctionInfo in nested FunctionBody chain. It did not reuse existing child FunctionBody and not clean up them for reparse properly when a parent function was redeferred. Patch the code to fix this. Credits to Paul/Akrosh.
1 parent b5c277f commit 03fba5c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ Symbol * ByteCodeGenerator::FindSymbol(Symbol **symRef, IdentPtr pid, bool forRe
16331633
bool didTransferToFncVarSym = false;
16341634

16351635
if (!PHASE_OFF(Js::OptimizeBlockScopePhase, top->byteCodeFunction) &&
1636-
sym->GetIsBlockVar() &&
1636+
sym->GetIsBlockVar() &&
16371637
!sym->GetScope()->IsBlockInLoop() &&
16381638
sym->GetSymbolType() == STFunction)
16391639
{
@@ -3318,13 +3318,23 @@ void VisitNestedScopes(ParseNode* pnodeScopeList, ParseNode* pnodeParent, ByteCo
33183318

33193319
Js::ParseableFunctionInfo::NestedArray * parentNestedArray = parentFunc->GetNestedArray();
33203320
Js::ParseableFunctionInfo* reuseNestedFunc = nullptr;
3321-
if (parentNestedArray && byteCodeGenerator->GetScriptContext()->IsScriptContextInNonDebugMode())
3321+
if (parentNestedArray)
33223322
{
33233323
Assert(*pIndex < parentNestedArray->nestedCount);
33243324
Js::FunctionInfo * info = parentNestedArray->functionInfoArray[*pIndex];
33253325
if (info && info->HasParseableInfo())
33263326
{
33273327
reuseNestedFunc = info->GetParseableFunctionInfo();
3328+
3329+
// If parentFunc was redeferred, try to set pCurrentFunction to this FunctionBody,
3330+
// and cleanup to reparse (as previous cleanup stops at redeferred parentFunc).
3331+
if (!byteCodeGenerator->IsInNonDebugMode()
3332+
&& !byteCodeGenerator->pCurrentFunction
3333+
&& reuseNestedFunc->IsFunctionBody())
3334+
{
3335+
byteCodeGenerator->pCurrentFunction = reuseNestedFunc->GetFunctionBody();
3336+
byteCodeGenerator->pCurrentFunction->CleanupToReparse();
3337+
}
33283338
}
33293339
}
33303340
PreVisitFunction(pnodeScope, byteCodeGenerator, reuseNestedFunc);

0 commit comments

Comments
 (0)