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

Unified Diff: src/parser.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/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b54172f72c21cc6ccf320ed04877227804a5d134..12547f05d8decdd04f19d60d2a2763ec7752def4 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2532,6 +2532,7 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
Expression* pattern;
{
+ int decl_pos = peek_position();
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
pattern = ParsePrimaryExpression(&pattern_classifier, ok);
@@ -2547,6 +2548,20 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
*ok = false;
return;
}
+
+ 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;
+ }
}
Scanner::Location variable_loc = scanner()->location();

Powered by Google App Engine
This is Rietveld 408576698