Skip to content

Commit 653db92

Browse files
committed
[MERGE #5851 @boingoing] Parser m_nextFunctionId is set incorrectly when skipping over nested function with functions in parameter scope
Merge pull request #5851 from boingoing:skipped_function_correct_id Parser m_nextFunctionId is set incorrectly when skipping over nested function with functions in parameter scope We use the deferred stubs to skip over nested functions and as part of skipping them, we adjust m_nextFunctionId so that other nested functions following the one we just skipped will have their function ids set correctly. We use the RestorePoint in the deferred stub to advance m_nextFunctionId by the function id increment amount. That's all fine unless the function we want to skip has nested functions in the parameter scope. Default argument assignments, for example. In that case, parsing or skipping the functions in the parameter scope would have already advanced m_nextFunctionId and so we end up setting it too high here. When we subsequently try and undefer one of the functions below the skipped one (one of the functions with a wrong function id), it might have a function id greater than the count of functions in the bytecode cache. Executing that function hits an assert in the bitvector we use to mark functions executed.
2 parents 9b71022 + 2f38ca9 commit 653db92

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/Parser/Parse.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6175,6 +6175,11 @@ void Parser::ParseTopLevelDeferredFunc(ParseNodeFnc * pnodeFnc, ParseNodeFnc * p
61756175

61766176
this->GetScanner()->SeekTo(stub->restorePoint, m_nextFunctionId);
61776177

6178+
// If we already incremented m_nextFunctionId when we saw some functions in the parameter scope
6179+
// (in default argument assignment, for example), we want to remove the count of those so the
6180+
// function ids following the one we are skipping right now are correct.
6181+
*m_nextFunctionId -= pnodeFnc->nestedCount;
6182+
61786183
for (uint i = 0; i < stub->capturedNameCount; i++)
61796184
{
61806185
int stringId = stub->capturedNameSerializedIds[i];

test/Bugs/rlexe.xml

+7
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@
496496
<compile-flags>-force:deferparse -parserstatecache -useparserstatecache</compile-flags>
497497
</default>
498498
</test>
499+
<test>
500+
<default>
501+
<files>skipping_nested_deferred_incorrect_function_id.js</files>
502+
<tags>exclude_jshost</tags>
503+
<compile-flags>-force:deferparse -parserstatecache -useparserstatecache</compile-flags>
504+
</default>
505+
</test>
499506
<test>
500507
<default>
501508
<files>withSplitScope.js</files>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
function test0(){
7+
function a(b = function c() {}) { return () => { return 6; } };
8+
[0].reduce(function d() {}, 0);
9+
a()();
10+
}
11+
test0();
12+
13+
console.log("pass");

0 commit comments

Comments
 (0)