Skip to content

Commit 37c20aa

Browse files
committed
Fixes #5994 - When DeferParse is cancelled finish parsing of functions using already known offsets as some of the context information
used during original scanning may now be unavailable.
1 parent 49a3328 commit 37c20aa

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

lib/Parser/Parse.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11442,14 +11442,25 @@ ULONG Parser::GetDeferralThreshold(bool isProfileLoaded)
1144211442

1144311443
void Parser::FinishDeferredFunction(ParseNodeBlock * pnodeScopeList)
1144411444
{
11445-
uint saveNextBlockId = m_nextBlockId;
11445+
ParseContext parseContext;
11446+
this->CaptureContext(&parseContext);
11447+
1144611448
m_nextBlockId = pnodeScopeList->blockId + 1;
1144711449

1144811450
FinishFunctionsInScope(pnodeScopeList,
11449-
[this](ParseNodeFnc * pnodeFnc)
11451+
[this, &parseContext](ParseNodeFnc * pnodeFnc)
1145011452
{
1145111453
Assert(pnodeFnc->nop == knopFncDecl);
1145211454

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+
1145311464
// Non-simple params (such as default) require a good amount of logic to put vars on appropriate scopes. ParseFncDecl handles it
1145411465
// properly (both on defer and non-defer case). This is to avoid write duplicated logic here as well. Function with non-simple-param
1145511466
// will remain deferred until they are called.
@@ -11601,7 +11612,7 @@ void Parser::FinishDeferredFunction(ParseNodeBlock * pnodeScopeList)
1160111612
}
1160211613
});
1160311614

11604-
m_nextBlockId = saveNextBlockId;
11615+
this->RestoreContext(&parseContext);
1160511616
}
1160611617

1160711618
void Parser::InitPids()

test/es6/bug_issue_5994.baseline

Whitespace-only changes.

test/es6/bug_issue_5994.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/es6/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,4 +1511,11 @@
15111511
<compile-flags>-args summary -endargs</compile-flags>
15121512
</default>
15131513
</test>
1514+
<test>
1515+
<default>
1516+
<files>bug_issue_5994.js</files>
1517+
<compile-flags>-MuteHostErrorMsg</compile-flags>
1518+
<baseline>bug_issue_5994.baseline</baseline>
1519+
</default>
1520+
</test>
15141521
</regress-exe>

0 commit comments

Comments
 (0)