@@ -11442,14 +11442,25 @@ ULONG Parser::GetDeferralThreshold(bool isProfileLoaded)
11442
11442
11443
11443
void Parser::FinishDeferredFunction(ParseNodeBlock * pnodeScopeList)
11444
11444
{
11445
- uint saveNextBlockId = m_nextBlockId;
11445
+ ParseContext parseContext;
11446
+ this->CaptureContext(&parseContext);
11447
+
11446
11448
m_nextBlockId = pnodeScopeList->blockId + 1;
11447
11449
11448
11450
FinishFunctionsInScope(pnodeScopeList,
11449
- [this](ParseNodeFnc * pnodeFnc)
11451
+ [this, &parseContext ](ParseNodeFnc * pnodeFnc)
11450
11452
{
11451
11453
Assert(pnodeFnc->nop == knopFncDecl);
11452
11454
11455
+ // We need to scan this function based on the already known limits of the function declaration as some of
11456
+ // the state such as fAllowIn may not be available at this point. Some of this state depends on the context
11457
+ // of the function declaration. For example, a function declaration may be inside a for..in statement's var
11458
+ // declaration. It may not be appropriate/possible to try and save all such context information. Functions
11459
+ // that actually get deferred achieve this by going through the ParseSourceWithOffset code path.
11460
+ this->GetScanner()->Clear();
11461
+ this->GetScanner()->SetText(parseContext.pszSrc, pnodeFnc->cbMin /*+ this->m_scan.m_cMinTokMultiUnits*/, pnodeFnc->LengthInBytes(), pnodeFnc->ichMin, parseContext.isUtf8, parseContext.grfscr, pnodeFnc->lineNumber);
11462
+ this->GetScanner()->Scan();
11463
+
11453
11464
// Non-simple params (such as default) require a good amount of logic to put vars on appropriate scopes. ParseFncDecl handles it
11454
11465
// properly (both on defer and non-defer case). This is to avoid write duplicated logic here as well. Function with non-simple-param
11455
11466
// will remain deferred until they are called.
@@ -11601,7 +11612,7 @@ void Parser::FinishDeferredFunction(ParseNodeBlock * pnodeScopeList)
11601
11612
}
11602
11613
});
11603
11614
11604
- m_nextBlockId = saveNextBlockId ;
11615
+ this->RestoreContext(&parseContext) ;
11605
11616
}
11606
11617
11607
11618
void Parser::InitPids()
0 commit comments