Skip to content

Commit 80fb794

Browse files
committed
[MERGE #6003 @akroshg] Fixing TrackAssignment for destructuring syntax
Merge pull request #6003 from akroshg:track We got nullpointer AV as the destructuring syntax is erroneous and we will suppose to get an error. But we did track assignment before. Fixing this by delaying the trackassignment after error checks.
2 parents 95b7191 + bfae52d commit 80fb794

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/Parser/Parse.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13102,6 +13102,7 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1310213102
ParseNodePtr pnodeElem = nullptr;
1310313103
int parenCount = 0;
1310413104
bool seenRest = false;
13105+
IdentToken token;
1310513106

1310613107
// Save the Block ID prior to the increments, so we can restore it back.
1310713108
int originalCurrentBlockId = GetCurrentBlock()->blockId;
@@ -13173,7 +13174,6 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1317313174
if (!isDecl)
1317413175
{
1317513176
BOOL fCanAssign;
13176-
IdentToken token;
1317713177
// Look for postfix operator
1317813178
pnodeElem = ParsePostfixOperators<buildAST>(pnodeElem, TRUE, FALSE, FALSE, TRUE, &fCanAssign, &token);
1317913179
}
@@ -13190,7 +13190,6 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1319013190
else
1319113191
{
1319213192
BOOL fCanAssign;
13193-
IdentToken token;
1319413193
// We aren't declaring anything, so scan the ID reference manually.
1319513194
pnodeElem = ParseTerm<buildAST>(/* fAllowCall */ m_token.tk != tkSUPER, nullptr /*pNameHint*/, nullptr /*pHintLength*/, nullptr /*pShortNameOffset*/, &token, false,
1319613195
FALSE, &fCanAssign);
@@ -13202,7 +13201,10 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1320213201
Error(ERRInvalidAssignmentTarget);
1320313202
}
1320413203

13205-
TrackAssignment<buildAST>(pnodeElem, &token);
13204+
if (buildAST)
13205+
{
13206+
TrackAssignment<buildAST>(pnodeElem, nullptr);
13207+
}
1320613208

1320713209
if (buildAST)
1320813210
{
@@ -13217,7 +13219,6 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1321713219
{
1321813220
CheckStrictModeEvalArgumentsUsage(token.pid);
1321913221
}
13220-
token.tk = tkNone;
1322113222
}
1322213223
}
1322313224
}
@@ -13292,6 +13293,11 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1329213293
Error(ERRsyntax);
1329313294
}
1329413295

13296+
if (!buildAST && token.tk == tkID)
13297+
{
13298+
TrackAssignment<buildAST>(nullptr, &token);
13299+
}
13300+
1329513301
return pnodeElem;
1329613302
}
1329713303

test/es6/destructuring_bugs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,20 @@ var tests = [
508508
};
509509
test1();
510510
}
511+
},
512+
{
513+
name: "Destructuring expression : Array expression instead of name ",
514+
body: function () {
515+
function test1(){
516+
assert.throws(function () { eval("({a: b => []} = [2])") }, SyntaxError,
517+
"", "Unexpected operator in destructuring expression");
518+
519+
assert.throws(function () { eval("for([a => {}] in []);") }, SyntaxError,
520+
"", "Unexpected operator in destructuring expression");
521+
522+
};
523+
test1();
524+
}
511525
}
512526
];
513527

0 commit comments

Comments
 (0)