Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1409)

Unified Diff: src/preparser.cc

Issue 1416753009: [parser] early error when declaration Pattern missing Initializer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 74e11b1d454b3b33a3f6bcadb18f91476a246f37..246b03a016133abae830abe1f9c02464e20f3baf 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -580,6 +580,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// Parse binding pattern.
if (nvars > 0) Consume(Token::COMMA);
{
+ int decl_pos = peek_position();
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
PreParserExpression pattern =
@@ -594,6 +595,20 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
*ok = false;
return Statement::Default();
}
+
+ bool is_for_iteration_variable =
+ var_context == kForStatement &&
+ (peek() == Token::IN || PeekContextualKeyword(CStrVector("of")));
+
+ if (!is_for_iteration_variable &&
+ (pattern.IsObjectLiteral() || pattern.IsArrayLiteral()) &&
+ peek() != Token::ASSIGN) {
+ ReportMessageAt(
+ Scanner::Location(decl_pos, scanner()->location().end_pos),
+ MessageTemplate::kInvalidDestructuringDeclaration);
+ *ok = false;
+ return Statement::Default();
+ }
}
Scanner::Location variable_loc = scanner()->location();

Powered by Google App Engine
This is Rietveld 408576698