Chromium Code Reviews| Index: src/parser.cc |
| diff --git a/src/parser.cc b/src/parser.cc |
| index 9507b69df6f0d661c4c5f5933882dc897233b2ad..e3a572a606704717018e7eac13e8cc9cbce51dd7 100644 |
| --- a/src/parser.cc |
| +++ b/src/parser.cc |
| @@ -1145,7 +1145,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 |
| @@ -1607,7 +1607,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); |
| @@ -2363,7 +2363,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()); |
|
Dmitry Lomov (no reviews)
2015/04/23 16:29:24
Here, instead of adding an unresolved proxy and th
arv (Not doing code reviews)
2015/04/23 16:52:52
I like this better. I doubt it matters for perform
|
| + 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); |
| @@ -2442,7 +2459,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()) { |
| @@ -2633,7 +2650,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); |
| @@ -4362,7 +4379,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); |
| } |
| @@ -4387,7 +4404,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(); |
| @@ -4439,7 +4456,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()); |