Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index aeef700bfe7593a8369b4c4b5f0350fa8dc5b707..53f4800fd6f9b34afb30a37982dfad760b7483c9 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -682,8 +682,10 @@ class ParserBase : public Traits { |
| ArrowFormalParametersProduction = 1 << 4, |
| StandardProductions = (ExpressionProduction | BindingPatternProduction | |
| AssignmentPatternProduction), |
| + PatternProductions = |
| + BindingPatternProduction | AssignmentPatternProduction, |
| AllProductions = (StandardProductions | FormalParametersProduction | |
| - ArrowFormalParametersProduction) |
| + ArrowFormalParametersProduction), |
| }; |
| void Accumulate(const ExpressionClassifier& inner, |
| @@ -721,6 +723,18 @@ class ParserBase : public Traits { |
| } |
| } |
| + void AccumulateReclassifyingAsPattern(const ExpressionClassifier& inner) { |
| + Accumulate(inner, AllProductions & ~PatternProductions); |
| + if (!inner.is_valid_expression()) { |
| + if (is_valid_binding_pattern()) { |
| + binding_pattern_error_ = inner.expression_error(); |
| + } |
| + if (is_valid_assignment_pattern()) { |
| + assignment_pattern_error_ = inner.expression_error(); |
| + } |
| + } |
| + } |
| + |
| private: |
| Error expression_error_; |
| Error binding_pattern_error_; |
| @@ -793,6 +807,11 @@ class ParserBase : public Traits { |
| } |
| } |
| + void ExpressionUnexpectedToken(ExpressionClassifier* classifier) { |
| + classifier->RecordExpressionError( |
| + scanner()->peek_location(), "unexpected_token", Token::String(peek())); |
| + } |
| + |
| void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { |
| classifier->RecordBindingPatternError( |
| scanner()->peek_location(), "unexpected_token", Token::String(peek())); |
| @@ -2652,8 +2671,21 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| this->is_generator())) { |
| DCHECK(!*is_computed_name); |
| DCHECK(!is_static); |
| - value = this->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos, |
| - scope_, factory()); |
| + |
| + ExpressionT lhs = this->ExpressionFromIdentifier( |
| + name, next_beg_pos, next_end_pos, scope_, factory()); |
| + if (peek() == Token::ASSIGN) { |
| + this->ExpressionUnexpectedToken(classifier); |
| + Consume(Token::ASSIGN); |
| + ExpressionClassifier rhs_classifier; |
| + ExpressionT rhs = this->ParseAssignmentExpression( |
| + true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| + classifier->AccumulateReclassifyingAsPattern(rhs_classifier); |
| + value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
| + RelocInfo::kNoPosition); |
| + } else { |
| + value = lhs; |
| + } |
| return factory()->NewObjectLiteralProperty( |
| name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); |
| @@ -2873,9 +2905,16 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| expression = this->MarkExpressionAsAssigned(expression); |
| Token::Value op = Next(); // Get assignment operator. |
| + if (op != Token::ASSIGN) { |
| + classifier->RecordBindingPatternError( |
|
arv (Not doing code reviews)
2015/05/18 14:36:20
Just curious... Is the reason why you are not doin
Dmitry Lomov (no reviews)
2015/05/18 17:31:22
Yes.
|
| + scanner()->location(), "unexpected_token", Token::String(op)); |
| + } |
| int pos = position(); |
| + |
| + ExpressionClassifier rhs_classifier; |
| ExpressionT right = |
| - this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
| + this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
| + classifier->AccumulateReclassifyingAsPattern(rhs_classifier); |
| // TODO(1231235): We try to estimate the set of properties set by |
| // constructors. We define a new property whenever there is an |