Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index af186270ee87307f13fd3694bf7c9de8aa78c9b3..bc4cffff37970ed2806e1190aacdd5d00f8bc0fa 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -1151,7 +1151,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, |
ExpressionClassifier classifier; |
Expression* expression = ParseArrowFunctionLiteral( |
scope, error_locs, has_rest, &classifier, &ok); |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, &ok); |
if (ok) { |
// Scanning must end at the same position that was recorded |
// previously. If not, parsing has been interrupted due to a stack |
@@ -1630,7 +1630,7 @@ Statement* Parser::ParseExportDefault(bool* ok) { |
int pos = peek_position(); |
ExpressionClassifier classifier; |
Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, CHECK_OK); |
ExpectSemicolon(CHECK_OK); |
result = factory()->NewExpressionStatement(expr, pos); |
@@ -2390,7 +2390,24 @@ Block* Parser::ParseVariableDeclarations( |
// Parse variable name. |
if (nvars > 0) Consume(Token::COMMA); |
- name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
+ |
+ { |
+ ExpressionClassifier pattern_classifier; |
+ Token::Value next = peek(); |
+ Expression* pattern = |
+ ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
+ ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
+ if (pattern->IsVariableProxy() && |
+ pattern->AsVariableProxy()->IsValidReferenceExpression()) { |
+ scope_->RemoveUnresolved(pattern->AsVariableProxy()); |
+ name = pattern->AsVariableProxy()->raw_name(); |
+ } else { |
+ ReportUnexpectedToken(next); |
+ *ok = false; |
+ return nullptr; |
+ } |
+ } |
+ |
if (!first_name) first_name = name; |
Scanner::Location variable_loc = scanner()->location(); |
if (fni_ != NULL) fni_->PushVariableName(name); |
@@ -2469,7 +2486,7 @@ Block* Parser::ParseVariableDeclarations( |
ExpressionClassifier classifier; |
value = ParseAssignmentExpression(var_context != kForStatement, |
&classifier, CHECK_OK); |
- // TODO(dslomov): check that expression is valid. |
+ ValidateExpression(&classifier, CHECK_OK); |
variable_loc.end_pos = scanner()->location().end_pos; |
if (first_initializer_loc && !first_initializer_loc->IsValid()) { |
@@ -2660,7 +2677,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
} else { |
expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); |
} |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, CHECK_OK); |
switch (peek()) { |
case Token::SEMICOLON: |
Consume(Token::SEMICOLON); |
@@ -4389,7 +4406,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
block_scope->set_start_position(scanner()->location().end_pos); |
ExpressionClassifier classifier; |
extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, CHECK_OK); |
} else { |
block_scope->set_start_position(scanner()->location().end_pos); |
} |
@@ -4414,7 +4431,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
ObjectLiteral::Property* property = ParsePropertyDefinition( |
&checker, in_class, has_extends, is_static, &is_computed_name, |
&has_seen_constructor, &classifier, CHECK_OK); |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, CHECK_OK); |
if (has_seen_constructor && constructor == NULL) { |
constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
@@ -4466,7 +4483,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { |
ExpressionClassifier classifier; |
ZoneList<Expression*>* args = |
ParseArguments(&spread_pos, &classifier, CHECK_OK); |
- // TODO(dslomov): report error if not a valid expression. |
+ ValidateExpression(&classifier, CHECK_OK); |
DCHECK(!spread_pos.IsValid()); |