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

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: comments addressed 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
« no previous file with comments | « src/messages.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b54172f72c21cc6ccf320ed04877227804a5d134..3adaff8e89fdf45dcc4d122d839577b119941871 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2531,6 +2531,7 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
if (!first_declaration) Consume(Token::COMMA);
Expression* pattern;
+ int decl_pos = peek_position();
{
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
@@ -2549,6 +2550,8 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
}
}
+ bool is_pattern = pattern->IsObjectLiteral() || pattern->IsArrayLiteral();
+
Scanner::Location variable_loc = scanner()->location();
const AstRawString* single_name =
pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name()
@@ -2569,10 +2572,7 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
Expression* value = NULL;
// Harmony consts have non-optional initializers.
int initializer_position = RelocInfo::kNoPosition;
- if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST &&
- !is_for_iteration_variable)) {
- Expect(Token::ASSIGN, ok);
- if (!*ok) return;
+ if (Check(Token::ASSIGN)) {
ExpressionClassifier classifier;
value = ParseAssignmentExpression(var_context != kForStatement,
&classifier, ok);
@@ -2597,6 +2597,15 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
// End position of the initializer is after the assignment expression.
initializer_position = scanner()->location().end_pos;
} else {
+ if ((parsing_result->descriptor.mode == CONST || is_pattern) &&
+ !is_for_iteration_variable) {
+ ParserTraits::ReportMessageAt(
+ Scanner::Location(decl_pos, scanner()->location().end_pos),
+ MessageTemplate::kDeclarationMissingInitializer,
+ is_pattern ? "destructuring" : "const");
+ *ok = false;
+ return;
+ }
// End position of the initializer is after the variable.
initializer_position = position();
}
« no previous file with comments | « src/messages.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698