| Index: src/parsing/parser-base.h
|
| diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
|
| index 679c2761a33c58fa491fb3d76bd8cff3b745874a..2955b0b9d9f1b563816d3c3bd1949dfffce8a381 100644
|
| --- a/src/parsing/parser-base.h
|
| +++ b/src/parsing/parser-base.h
|
| @@ -745,10 +745,9 @@ class ParserBase : public Traits {
|
| bool* ok);
|
|
|
| enum AssignmentExpressionFlags {
|
| - kIsLeftHandSide = 0,
|
| - kIsRightHandSide = 1 << 0,
|
| - kIsPatternElement = 1 << 1,
|
| - kIsPossibleArrowFormals = 1 << 2
|
| + kIsNormalAssignment = 0,
|
| + kIsPossiblePatternElement = 1 << 0,
|
| + kIsPossibleArrowFormals = 1 << 1
|
| };
|
|
|
| ExpressionT ParseAssignmentExpression(bool accept_IN, int flags,
|
| @@ -757,7 +756,7 @@ class ParserBase : public Traits {
|
| ExpressionT ParseAssignmentExpression(bool accept_IN,
|
| ExpressionClassifier* classifier,
|
| bool* ok) {
|
| - return ParseAssignmentExpression(accept_IN, kIsLeftHandSide, classifier,
|
| + return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier,
|
| ok);
|
| }
|
| ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok);
|
| @@ -1047,9 +1046,6 @@ typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
|
| if (!*ok) return Traits::EmptyIdentifier();
|
| ValidateBindingPattern(&classifier, ok);
|
| if (!*ok) return Traits::EmptyIdentifier();
|
| - } else {
|
| - ValidateExpression(&classifier, ok);
|
| - if (!*ok) return Traits::EmptyIdentifier();
|
| }
|
|
|
| return result;
|
| @@ -1365,7 +1361,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
|
| classifier, CHECK_OK);
|
| Expect(Token::RPAREN, CHECK_OK);
|
| if (peek() != Token::ARROW) {
|
| - ValidateExpression(classifier, CHECK_OK);
|
| expr->set_is_parenthesized();
|
| }
|
| return expr;
|
| @@ -1430,7 +1425,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
|
| bool accept_IN, bool* ok) {
|
| ExpressionClassifier classifier;
|
| ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK);
|
| - ValidateExpression(&classifier, CHECK_OK);
|
| + result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK);
|
| return result;
|
| }
|
|
|
| @@ -1438,7 +1433,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
|
| template <class Traits>
|
| typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
|
| bool accept_IN, ExpressionClassifier* classifier, bool* ok) {
|
| - return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok);
|
| + return ParseExpression(accept_IN, kIsNormalAssignment, classifier, ok);
|
| }
|
|
|
|
|
| @@ -1539,7 +1534,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
|
| MessageTemplate::kElementAfterRest);
|
| }
|
| } else {
|
| - elem = this->ParseAssignmentExpression(true, kIsPatternElement,
|
| + elem = this->ParseAssignmentExpression(true, kIsPossiblePatternElement,
|
| classifier, CHECK_OK);
|
| }
|
| values->Add(elem, zone_);
|
| @@ -1596,6 +1591,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
|
| ExpressionClassifier computed_name_classifier;
|
| ExpressionT expression =
|
| ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK);
|
| + expression = Traits::RewriteNonPattern(
|
| + expression, &computed_name_classifier, CHECK_OK);
|
| classifier->Accumulate(computed_name_classifier,
|
| ExpressionClassifier::ExpressionProductions);
|
| Expect(Token::RBRACK, CHECK_OK);
|
| @@ -1667,7 +1664,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
|
| }
|
| Consume(Token::COLON);
|
| value = this->ParseAssignmentExpression(
|
| - true, kIsPatternElement, classifier,
|
| + true, kIsPossiblePatternElement, classifier,
|
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
|
|
|
| return factory()->NewObjectLiteralProperty(name_expression, value, false,
|
| @@ -1709,6 +1706,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
|
| ExpressionClassifier rhs_classifier;
|
| ExpressionT rhs = this->ParseAssignmentExpression(
|
| true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
|
| + rhs = Traits::RewriteNonPattern(
|
| + rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
|
| classifier->Accumulate(rhs_classifier,
|
| ExpressionClassifier::ExpressionProductions);
|
| value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
|
| @@ -1773,9 +1772,12 @@ ParserBase<Traits>::ParsePropertyDefinition(
|
| // ClassElement (static)
|
| // 'static' MethodDefinition
|
| *name = this->EmptyIdentifier();
|
| - return ParsePropertyDefinition(checker, true, has_extends, true,
|
| - is_computed_name, nullptr, classifier, name,
|
| - ok);
|
| + ObjectLiteralPropertyT property = ParsePropertyDefinition(
|
| + checker, true, has_extends, true, is_computed_name, nullptr, classifier,
|
| + name, ok);
|
| + property = Traits::RewriteNonPatternObjectLiteralProperty(property,
|
| + classifier, ok);
|
| + return property;
|
| }
|
|
|
| if (is_get || is_set) {
|
| @@ -1914,6 +1916,8 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
|
|
|
| ExpressionT argument = this->ParseAssignmentExpression(
|
| true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
|
| + argument = Traits::RewriteNonPattern(argument, classifier,
|
| + CHECK_OK_CUSTOM(NullExpressionList));
|
| if (is_spread) {
|
| if (!spread_arg.IsValid()) {
|
| spread_arg.beg_pos = start_pos;
|
| @@ -1971,10 +1975,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
| // ArrowFunction
|
| // YieldExpression
|
| // LeftHandSideExpression AssignmentOperator AssignmentExpression
|
| - bool is_rhs = flags & kIsRightHandSide;
|
| - bool is_pattern_element = flags & kIsPatternElement;
|
| + bool maybe_pattern_element = flags & kIsPossiblePatternElement;
|
| + bool maybe_arrow_formals = flags & kIsPossibleArrowFormals;
|
| bool is_destructuring_assignment = false;
|
| - bool is_arrow_formals = flags & kIsPossibleArrowFormals;
|
| int lhs_beg_pos = peek_position();
|
|
|
| if (peek() == Token::YIELD && is_generator()) {
|
| @@ -2019,7 +2022,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
| }
|
| expression = this->ParseArrowFunctionLiteral(
|
| accept_IN, parameters, arrow_formals_classifier, CHECK_OK);
|
| - if (is_pattern_element) {
|
| + if (maybe_pattern_element) {
|
| classifier->RecordPatternError(
|
| Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
|
| MessageTemplate::kInvalidDestructuringTarget);
|
| @@ -2048,13 +2051,10 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
|
|
| if (!Token::IsAssignmentOp(peek())) {
|
| // Parsed conditional expression only (no assignment).
|
| - if (is_pattern_element) {
|
| + if (maybe_pattern_element) {
|
| CheckDestructuringElement(expression, classifier, lhs_beg_pos,
|
| scanner()->location().end_pos);
|
| - } else if (is_rhs && maybe_pattern) {
|
| - ValidateExpression(classifier, CHECK_OK);
|
| }
|
| -
|
| return expression;
|
| }
|
|
|
| @@ -2068,12 +2068,12 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
| classifier->ForgiveCoverInitializedNameError();
|
| ValidateAssignmentPattern(classifier, CHECK_OK);
|
| is_destructuring_assignment = true;
|
| - } else if (is_arrow_formals) {
|
| + } else if (maybe_arrow_formals) {
|
| expression = this->ClassifyAndRewriteReferenceExpression(
|
| classifier, expression, lhs_beg_pos, scanner()->location().end_pos,
|
| MessageTemplate::kInvalidLhsInAssignment);
|
| } else {
|
| - if (is_pattern_element) {
|
| + if (maybe_pattern_element) {
|
| CheckDestructuringElement(expression, classifier, lhs_beg_pos,
|
| scanner()->location().end_pos);
|
| }
|
| @@ -2094,11 +2094,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
|
|
| ExpressionClassifier rhs_classifier;
|
|
|
| - int rhs_flags = flags;
|
| - rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals);
|
| - rhs_flags |= kIsRightHandSide;
|
| - ExpressionT right = this->ParseAssignmentExpression(
|
| - accept_IN, rhs_flags, &rhs_classifier, CHECK_OK);
|
| + ExpressionT right =
|
| + this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
|
| + right = Traits::RewriteNonPattern(right, &rhs_classifier, CHECK_OK);
|
| classifier->Accumulate(
|
| rhs_classifier, ExpressionClassifier::ExpressionProductions |
|
| ExpressionClassifier::CoverInitializedNameProduction);
|
| @@ -2112,7 +2110,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
|
| function_state_->AddProperty();
|
| }
|
|
|
| - if (op != Token::ASSIGN && is_pattern_element) {
|
| + if (op != Token::ASSIGN && maybe_pattern_element) {
|
| classifier->RecordAssignmentPatternError(
|
| Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
|
| MessageTemplate::kInvalidDestructuringTarget);
|
| @@ -2180,6 +2178,8 @@ ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier,
|
| // Delegating yields require an RHS; fall through.
|
| default:
|
| expression = ParseAssignmentExpression(false, classifier, CHECK_OK);
|
| + expression =
|
| + Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
| break;
|
| }
|
| }
|
| @@ -2212,6 +2212,7 @@ ParserBase<Traits>::ParseConditionalExpression(bool accept_IN,
|
| ExpressionT expression =
|
| this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
|
| if (peek() != Token::CONDITIONAL) return expression;
|
| + expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
| ArrowFormalParametersUnexpectedToken(classifier);
|
| BindingPatternUnexpectedToken(classifier);
|
| Consume(Token::CONDITIONAL);
|
| @@ -2219,9 +2220,11 @@ ParserBase<Traits>::ParseConditionalExpression(bool accept_IN,
|
| // expressions we always accept the 'in' keyword; see ECMA-262,
|
| // section 11.12, page 58.
|
| ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK);
|
| + left = Traits::RewriteNonPattern(left, classifier, CHECK_OK);
|
| Expect(Token::COLON, CHECK_OK);
|
| ExpressionT right =
|
| ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
|
| + right = Traits::RewriteNonPattern(right, classifier, CHECK_OK);
|
| return factory()->NewConditional(expression, left, right, pos);
|
| }
|
|
|
| @@ -2237,6 +2240,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN,
|
| for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
|
| // prec1 >= 4
|
| while (Precedence(peek(), accept_IN) == prec1) {
|
| + x = Traits::RewriteNonPattern(x, classifier, CHECK_OK);
|
| BindingPatternUnexpectedToken(classifier);
|
| ArrowFormalParametersUnexpectedToken(classifier);
|
| Token::Value op = Next();
|
| @@ -2244,6 +2248,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN,
|
| int pos = position();
|
| ExpressionT y =
|
| ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK);
|
| + y = Traits::RewriteNonPattern(y, classifier, CHECK_OK);
|
|
|
| if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos,
|
| factory())) {
|
| @@ -2306,6 +2311,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
|
| op = Next();
|
| int pos = position();
|
| ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK);
|
| + expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
|
|
| if (op == Token::DELETE && is_strict(language_mode())) {
|
| if (is_strong(language_mode())) {
|
| @@ -2332,6 +2338,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
|
| expression, beg_pos, scanner()->location().end_pos,
|
| MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
|
| this->MarkExpressionAsAssigned(expression);
|
| + expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
|
|
| return factory()->NewCountOperation(op,
|
| true /* prefix */,
|
| @@ -2363,6 +2370,7 @@ ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier,
|
| expression, lhs_beg_pos, scanner()->location().end_pos,
|
| MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
|
| expression = this->MarkExpressionAsAssigned(expression);
|
| + expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
|
|
| Token::Value next = Next();
|
| expression =
|
| @@ -2393,12 +2401,14 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
|
| Consume(Token::LBRACK);
|
| int pos = position();
|
| ExpressionT index = ParseExpression(true, classifier, CHECK_OK);
|
| + index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
|
| result = factory()->NewProperty(result, index, pos);
|
| Expect(Token::RBRACK, CHECK_OK);
|
| break;
|
| }
|
|
|
| case Token::LPAREN: {
|
| + result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
|
| BindingPatternUnexpectedToken(classifier);
|
| ArrowFormalParametersUnexpectedToken(classifier);
|
|
|
| @@ -2526,6 +2536,7 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
|
| } else {
|
| result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK);
|
| }
|
| + result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
|
| if (peek() == Token::LPAREN) {
|
| // NewExpression with arguments.
|
| Scanner::Location spread_pos;
|
| @@ -2625,6 +2636,7 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
|
| Consume(Token::LBRACK);
|
| int pos = position();
|
| ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
|
| + index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
|
| left = factory()->NewProperty(this_expr, index, pos);
|
| if (fni_ != NULL) {
|
| this->PushPropertyName(fni_, index);
|
| @@ -2660,6 +2672,7 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
|
|
|
| ExpressionT right =
|
| this->ParseAssignmentExpression(true, classifier, CHECK_OK);
|
| + right = Traits::RewriteNonPattern(right, classifier, CHECK_OK);
|
| this->CheckAssigningFunctionLiteralToProperty(left, right);
|
| function_state_->AddProperty();
|
| if (fni_ != NULL) {
|
| @@ -2816,6 +2829,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
|
| Consume(Token::LBRACK);
|
| int pos = position();
|
| ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
|
| + index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
|
| expression = factory()->NewProperty(expression, index, pos);
|
| if (fni_ != NULL) {
|
| this->PushPropertyName(fni_, index);
|
| @@ -2896,7 +2910,7 @@ void ParserBase<Traits>::ParseFormalParameter(
|
| ExpressionClassifier init_classifier;
|
| initializer = ParseAssignmentExpression(true, &init_classifier, ok);
|
| if (!*ok) return;
|
| - ValidateExpression(&init_classifier, ok);
|
| + initializer = Traits::RewriteNonPattern(initializer, &init_classifier, ok);
|
| ValidateFormalParameterInitializer(&init_classifier, ok);
|
| if (!*ok) return;
|
| parameters->is_simple = false;
|
| @@ -3070,7 +3084,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
|
| ExpressionClassifier classifier;
|
| ExpressionT expression =
|
| ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
|
| - ValidateExpression(&classifier, CHECK_OK);
|
| + expression = Traits::RewriteNonPattern(expression, &classifier, CHECK_OK);
|
| body = this->NewStatementList(1, zone());
|
| this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK);
|
| body->Add(factory()->NewReturnStatement(expression, pos), zone());
|
| @@ -3176,6 +3190,7 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start,
|
|
|
| int expr_pos = peek_position();
|
| ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK);
|
| + expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
|
| Traits::AddTemplateExpression(&ts, expression);
|
|
|
| if (peek() != Token::RBRACE) {
|
|
|