Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 571fbf03a540e6b06266cd3561788fdeb96ebef1..06b845827c854dd30eabc6c62854d6e2b24fc22f 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -138,6 +138,9 @@ class ParserBase : public Traits { |
| return allow_harmony_rest_params_; |
| } |
| bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; } |
| + bool allow_harmony_destructuring() const { |
| + return allow_harmony_destructuring_; |
| + } |
| bool allow_strong_mode() const { return allow_strong_mode_; } |
| @@ -173,6 +176,10 @@ class ParserBase : public Traits { |
| allow_harmony_spreadcalls_ = allow; |
| } |
| void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } |
| + void set_allow_harmony_destructuring(bool allow) { |
| + allow_harmony_destructuring_ = allow; |
| + } |
| + |
| protected: |
| enum AllowRestrictedIdentifiers { |
| @@ -679,6 +686,10 @@ class ParserBase : public Traits { |
| } |
| } |
| + void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { |
|
rossberg
2015/04/27 17:20:24
Nit: is this function worth it, especially since i
arv (Not doing code reviews)
2015/04/27 17:56:55
I think it is worth it. The code gets much more re
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
+1 to arv.
Added more usages.
|
| + classifier->RecordBindingPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(peek())); |
| + } |
| // Recursive descent functions: |
| @@ -857,6 +868,7 @@ class ParserBase : public Traits { |
| bool allow_harmony_computed_property_names_; |
| bool allow_harmony_rest_params_; |
| bool allow_harmony_spreadcalls_; |
| + bool allow_harmony_destructuring_; |
| bool allow_strong_mode_; |
| }; |
| @@ -2192,6 +2204,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| Token::Value token = peek(); |
| switch (token) { |
| case Token::THIS: { |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::THIS); |
| if (is_strong(language_mode())) { |
| // Constructors' usages of 'this' in strong mode are parsed separately. |
| @@ -2210,8 +2223,15 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| case Token::NULL_LITERAL: |
| case Token::TRUE_LITERAL: |
| case Token::FALSE_LITERAL: |
| + BindingPatternUnexpectedToken(classifier); |
| + Next(); |
| + result = |
| + this->ExpressionFromLiteral(token, beg_pos, scanner(), factory()); |
| + break; |
| case Token::SMI: |
| case Token::NUMBER: |
| + classifier->RecordBindingPatternError(scanner()->location(), |
| + "unexpected_token_number"); |
| Next(); |
| result = |
| this->ExpressionFromLiteral(token, beg_pos, scanner(), factory()); |
| @@ -2230,6 +2250,8 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| } |
| case Token::STRING: { |
| + classifier->RecordBindingPatternError(scanner()->location(), |
| + "unexpected_token_string"); |
| Consume(Token::STRING); |
| result = this->ExpressionFromString(beg_pos, scanner(), factory()); |
| break; |
| @@ -2276,6 +2298,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| break; |
| case Token::CLASS: { |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::CLASS); |
| if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| ReportMessage("sloppy_lexical"); |
| @@ -2940,6 +2963,10 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier, |
| Token::Value op = peek(); |
| if (Token::IsUnaryOp(op)) { |
| + classifier->RecordBindingPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(op)); |
| + classifier->RecordAssignmentPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(op)); |
| op = Next(); |
| int pos = position(); |
| ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
| @@ -2960,6 +2987,10 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier, |
| // Allow Traits do rewrite the expression. |
| return this->BuildUnaryExpression(expression, op, pos, factory()); |
| } else if (Token::IsCountOp(op)) { |
| + classifier->RecordBindingPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(op)); |
| + classifier->RecordAssignmentPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(op)); |
| op = Next(); |
| Scanner::Location lhs_location = scanner()->peek_location(); |
| ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
| @@ -2990,6 +3021,11 @@ ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, |
| this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
| if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| Token::IsCountOp(peek())) { |
| + classifier->RecordBindingPatternError( |
|
arv (Not doing code reviews)
2015/04/27 17:56:55
Maybe introduce a RecordPatternError that does bot
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
On second thoughts, I removed all RecordAssignment
|
| + scanner()->location(), "unexpected_token", Token::String(peek())); |
| + classifier->RecordAssignmentPatternError( |
| + scanner()->location(), "unexpected_token", Token::String(peek())); |
| + |
| expression = this->CheckAndRewriteReferenceExpression( |
| expression, lhs_location, "invalid_lhs_in_postfix_op", CHECK_OK); |
| expression = this->MarkExpressionAsAssigned(expression); |
| @@ -3018,6 +3054,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression( |
| while (true) { |
| switch (peek()) { |
| case Token::LBRACK: { |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::LBRACK); |
| int pos = position(); |
| ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
| @@ -3027,6 +3064,8 @@ ParserBase<Traits>::ParseLeftHandSideExpression( |
| } |
| case Token::LPAREN: { |
| + BindingPatternUnexpectedToken(classifier); |
| + |
| if (is_strong(language_mode()) && this->IsIdentifier(result) && |
| this->IsEval(this->AsIdentifier(result))) { |
| ReportMessage("strong_direct_eval"); |
| @@ -3076,6 +3115,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression( |
| } |
| case Token::PERIOD: { |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::PERIOD); |
| int pos = position(); |
| IdentifierT name = ParseIdentifierName(CHECK_OK); |
| @@ -3114,6 +3154,7 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( |
| // new new foo().bar().baz means (new (new foo()).bar()).baz |
| if (peek() == Token::NEW) { |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::NEW); |
| int new_pos = position(); |
| ExpressionT result = this->EmptyExpression(); |
| @@ -3164,6 +3205,8 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, |
| // Parse the initial primary or function expression. |
| ExpressionT result = this->EmptyExpression(); |
| if (peek() == Token::FUNCTION) { |
| + BindingPatternUnexpectedToken(classifier); |
| + |
| Consume(Token::FUNCTION); |
| int function_token_position = position(); |
| bool is_generator = Check(Token::MUL); |
| @@ -3284,6 +3327,7 @@ ParserBase<Traits>::ParseStrongSuperCallExpression( |
| ExpressionClassifier* classifier, bool* ok) { |
| // SuperCallExpression :: (strong mode) |
| // 'super' '(' ExpressionList ')' |
| + BindingPatternUnexpectedToken(classifier); |
| Consume(Token::SUPER); |
| int pos = position(); |
| @@ -3380,6 +3424,8 @@ ParserBase<Traits>::ParseMemberExpressionContinuation( |
| while (true) { |
| switch (peek()) { |
| case Token::LBRACK: { |
| + BindingPatternUnexpectedToken(classifier); |
| + |
| Consume(Token::LBRACK); |
| int pos = position(); |
| ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
| @@ -3391,6 +3437,8 @@ ParserBase<Traits>::ParseMemberExpressionContinuation( |
| break; |
| } |
| case Token::PERIOD: { |
| + BindingPatternUnexpectedToken(classifier); |
| + |
| Consume(Token::PERIOD); |
| int pos = position(); |
| IdentifierT name = ParseIdentifierName(CHECK_OK); |
| @@ -3403,6 +3451,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation( |
| } |
| case Token::TEMPLATE_SPAN: |
| case Token::TEMPLATE_TAIL: { |
| + BindingPatternUnexpectedToken(classifier); |
| int pos; |
| if (scanner()->current_token() == Token::IDENTIFIER) { |
| pos = position(); |
| @@ -3549,6 +3598,9 @@ ParserBase<Traits>::ParseArrowFunctionLiteral( |
| FunctionState function_state(&function_state_, &scope_, scope, |
| kArrowFunction, &function_factory); |
| + if (peek() == Token::ARROW) { |
| + BindingPatternUnexpectedToken(classifier); |
| + } |
| Expect(Token::ARROW, CHECK_OK); |
| if (peek() == Token::LBRACE) { |