| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 738 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
| 739 ObjectLiteralPropertyT ParsePropertyDefinition( | 739 ObjectLiteralPropertyT ParsePropertyDefinition( |
| 740 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 740 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 741 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 741 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
| 742 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 742 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
| 743 typename Traits::Type::ExpressionList ParseArguments( | 743 typename Traits::Type::ExpressionList ParseArguments( |
| 744 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 744 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
| 745 bool* ok); | 745 bool* ok); |
| 746 | 746 |
| 747 enum AssignmentExpressionFlags { | 747 enum AssignmentExpressionFlags { |
| 748 kIsLeftHandSide = 0, | 748 kIsNormalAssignment = 0, |
| 749 kIsRightHandSide = 1 << 0, | 749 kIsPossiblePatternElement = 1 << 0, |
| 750 kIsPatternElement = 1 << 1, | 750 kIsPossibleArrowFormals = 1 << 1 |
| 751 kIsPossibleArrowFormals = 1 << 2 | |
| 752 }; | 751 }; |
| 753 | 752 |
| 754 ExpressionT ParseAssignmentExpression(bool accept_IN, int flags, | 753 ExpressionT ParseAssignmentExpression(bool accept_IN, int flags, |
| 755 ExpressionClassifier* classifier, | 754 ExpressionClassifier* classifier, |
| 756 bool* ok); | 755 bool* ok); |
| 757 ExpressionT ParseAssignmentExpression(bool accept_IN, | 756 ExpressionT ParseAssignmentExpression(bool accept_IN, |
| 758 ExpressionClassifier* classifier, | 757 ExpressionClassifier* classifier, |
| 759 bool* ok) { | 758 bool* ok) { |
| 760 return ParseAssignmentExpression(accept_IN, kIsLeftHandSide, classifier, | 759 return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier, |
| 761 ok); | 760 ok); |
| 762 } | 761 } |
| 763 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 762 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); |
| 764 ExpressionT ParseConditionalExpression(bool accept_IN, | 763 ExpressionT ParseConditionalExpression(bool accept_IN, |
| 765 ExpressionClassifier* classifier, | 764 ExpressionClassifier* classifier, |
| 766 bool* ok); | 765 bool* ok); |
| 767 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 766 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
| 768 ExpressionClassifier* classifier, bool* ok); | 767 ExpressionClassifier* classifier, bool* ok); |
| 769 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 768 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
| 770 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 769 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1039 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
| 1041 ExpressionClassifier classifier; | 1040 ExpressionClassifier classifier; |
| 1042 auto result = ParseAndClassifyIdentifier(&classifier, ok); | 1041 auto result = ParseAndClassifyIdentifier(&classifier, ok); |
| 1043 if (!*ok) return Traits::EmptyIdentifier(); | 1042 if (!*ok) return Traits::EmptyIdentifier(); |
| 1044 | 1043 |
| 1045 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { | 1044 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { |
| 1046 ValidateAssignmentPattern(&classifier, ok); | 1045 ValidateAssignmentPattern(&classifier, ok); |
| 1047 if (!*ok) return Traits::EmptyIdentifier(); | 1046 if (!*ok) return Traits::EmptyIdentifier(); |
| 1048 ValidateBindingPattern(&classifier, ok); | 1047 ValidateBindingPattern(&classifier, ok); |
| 1049 if (!*ok) return Traits::EmptyIdentifier(); | 1048 if (!*ok) return Traits::EmptyIdentifier(); |
| 1050 } else { | |
| 1051 ValidateExpression(&classifier, ok); | |
| 1052 if (!*ok) return Traits::EmptyIdentifier(); | |
| 1053 } | 1049 } |
| 1054 | 1050 |
| 1055 return result; | 1051 return result; |
| 1056 } | 1052 } |
| 1057 | 1053 |
| 1058 | 1054 |
| 1059 template <class Traits> | 1055 template <class Traits> |
| 1060 typename ParserBase<Traits>::IdentifierT | 1056 typename ParserBase<Traits>::IdentifierT |
| 1061 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 1057 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
| 1062 bool* ok) { | 1058 bool* ok) { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 Expect(Token::RPAREN, CHECK_OK); | 1354 Expect(Token::RPAREN, CHECK_OK); |
| 1359 return factory()->NewSpread(expr, ellipsis_pos); | 1355 return factory()->NewSpread(expr, ellipsis_pos); |
| 1360 } | 1356 } |
| 1361 // Heuristically try to detect immediately called functions before | 1357 // Heuristically try to detect immediately called functions before |
| 1362 // seeing the call parentheses. | 1358 // seeing the call parentheses. |
| 1363 parenthesized_function_ = (peek() == Token::FUNCTION); | 1359 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 1364 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, | 1360 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, |
| 1365 classifier, CHECK_OK); | 1361 classifier, CHECK_OK); |
| 1366 Expect(Token::RPAREN, CHECK_OK); | 1362 Expect(Token::RPAREN, CHECK_OK); |
| 1367 if (peek() != Token::ARROW) { | 1363 if (peek() != Token::ARROW) { |
| 1368 ValidateExpression(classifier, CHECK_OK); | |
| 1369 expr->set_is_parenthesized(); | 1364 expr->set_is_parenthesized(); |
| 1370 } | 1365 } |
| 1371 return expr; | 1366 return expr; |
| 1372 } | 1367 } |
| 1373 | 1368 |
| 1374 case Token::CLASS: { | 1369 case Token::CLASS: { |
| 1375 BindingPatternUnexpectedToken(classifier); | 1370 BindingPatternUnexpectedToken(classifier); |
| 1376 Consume(Token::CLASS); | 1371 Consume(Token::CLASS); |
| 1377 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 1372 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 1378 ReportMessage(MessageTemplate::kSloppyLexical); | 1373 ReportMessage(MessageTemplate::kSloppyLexical); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 *ok = false; | 1418 *ok = false; |
| 1424 return this->EmptyExpression(); | 1419 return this->EmptyExpression(); |
| 1425 } | 1420 } |
| 1426 | 1421 |
| 1427 | 1422 |
| 1428 template <class Traits> | 1423 template <class Traits> |
| 1429 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1424 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| 1430 bool accept_IN, bool* ok) { | 1425 bool accept_IN, bool* ok) { |
| 1431 ExpressionClassifier classifier; | 1426 ExpressionClassifier classifier; |
| 1432 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1427 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
| 1433 ValidateExpression(&classifier, CHECK_OK); | 1428 result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK); |
| 1434 return result; | 1429 return result; |
| 1435 } | 1430 } |
| 1436 | 1431 |
| 1437 | 1432 |
| 1438 template <class Traits> | 1433 template <class Traits> |
| 1439 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1434 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| 1440 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1435 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
| 1441 return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok); | 1436 return ParseExpression(accept_IN, kIsNormalAssignment, classifier, ok); |
| 1442 } | 1437 } |
| 1443 | 1438 |
| 1444 | 1439 |
| 1445 template <class Traits> | 1440 template <class Traits> |
| 1446 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1441 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| 1447 bool accept_IN, int flags, ExpressionClassifier* classifier, bool* ok) { | 1442 bool accept_IN, int flags, ExpressionClassifier* classifier, bool* ok) { |
| 1448 // Expression :: | 1443 // Expression :: |
| 1449 // AssignmentExpression | 1444 // AssignmentExpression |
| 1450 // Expression ',' AssignmentExpression | 1445 // Expression ',' AssignmentExpression |
| 1451 | 1446 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 CheckDestructuringElement(argument, classifier, start_pos, | 1527 CheckDestructuringElement(argument, classifier, start_pos, |
| 1533 scanner()->location().end_pos); | 1528 scanner()->location().end_pos); |
| 1534 } | 1529 } |
| 1535 | 1530 |
| 1536 if (peek() == Token::COMMA) { | 1531 if (peek() == Token::COMMA) { |
| 1537 classifier->RecordPatternError( | 1532 classifier->RecordPatternError( |
| 1538 Scanner::Location(start_pos, scanner()->location().end_pos), | 1533 Scanner::Location(start_pos, scanner()->location().end_pos), |
| 1539 MessageTemplate::kElementAfterRest); | 1534 MessageTemplate::kElementAfterRest); |
| 1540 } | 1535 } |
| 1541 } else { | 1536 } else { |
| 1542 elem = this->ParseAssignmentExpression(true, kIsPatternElement, | 1537 elem = this->ParseAssignmentExpression(true, kIsPossiblePatternElement, |
| 1543 classifier, CHECK_OK); | 1538 classifier, CHECK_OK); |
| 1544 } | 1539 } |
| 1545 values->Add(elem, zone_); | 1540 values->Add(elem, zone_); |
| 1546 if (peek() != Token::RBRACK) { | 1541 if (peek() != Token::RBRACK) { |
| 1547 Expect(Token::COMMA, CHECK_OK); | 1542 Expect(Token::COMMA, CHECK_OK); |
| 1548 } | 1543 } |
| 1549 } | 1544 } |
| 1550 Expect(Token::RBRACK, CHECK_OK); | 1545 Expect(Token::RBRACK, CHECK_OK); |
| 1551 | 1546 |
| 1552 // Update the scope information before the pre-parsing bailout. | 1547 // Update the scope information before the pre-parsing bailout. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 Consume(Token::NUMBER); | 1584 Consume(Token::NUMBER); |
| 1590 *name = this->GetNumberAsSymbol(scanner()); | 1585 *name = this->GetNumberAsSymbol(scanner()); |
| 1591 break; | 1586 break; |
| 1592 | 1587 |
| 1593 case Token::LBRACK: { | 1588 case Token::LBRACK: { |
| 1594 *is_computed_name = true; | 1589 *is_computed_name = true; |
| 1595 Consume(Token::LBRACK); | 1590 Consume(Token::LBRACK); |
| 1596 ExpressionClassifier computed_name_classifier; | 1591 ExpressionClassifier computed_name_classifier; |
| 1597 ExpressionT expression = | 1592 ExpressionT expression = |
| 1598 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); | 1593 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); |
| 1594 expression = Traits::RewriteNonPattern( |
| 1595 expression, &computed_name_classifier, CHECK_OK); |
| 1599 classifier->Accumulate(computed_name_classifier, | 1596 classifier->Accumulate(computed_name_classifier, |
| 1600 ExpressionClassifier::ExpressionProductions); | 1597 ExpressionClassifier::ExpressionProductions); |
| 1601 Expect(Token::RBRACK, CHECK_OK); | 1598 Expect(Token::RBRACK, CHECK_OK); |
| 1602 return expression; | 1599 return expression; |
| 1603 } | 1600 } |
| 1604 | 1601 |
| 1605 case Token::ESCAPED_KEYWORD: | 1602 case Token::ESCAPED_KEYWORD: |
| 1606 *is_escaped_keyword = true; | 1603 *is_escaped_keyword = true; |
| 1607 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); | 1604 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
| 1608 break; | 1605 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 | 1657 |
| 1661 if (peek() == Token::COLON) { | 1658 if (peek() == Token::COLON) { |
| 1662 // PropertyDefinition | 1659 // PropertyDefinition |
| 1663 // PropertyName ':' AssignmentExpression | 1660 // PropertyName ':' AssignmentExpression |
| 1664 if (!*is_computed_name) { | 1661 if (!*is_computed_name) { |
| 1665 checker->CheckProperty(name_token, kValueProperty, false, false, | 1662 checker->CheckProperty(name_token, kValueProperty, false, false, |
| 1666 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1663 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1667 } | 1664 } |
| 1668 Consume(Token::COLON); | 1665 Consume(Token::COLON); |
| 1669 value = this->ParseAssignmentExpression( | 1666 value = this->ParseAssignmentExpression( |
| 1670 true, kIsPatternElement, classifier, | 1667 true, kIsPossiblePatternElement, classifier, |
| 1671 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1668 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1672 | 1669 |
| 1673 return factory()->NewObjectLiteralProperty(name_expression, value, false, | 1670 return factory()->NewObjectLiteralProperty(name_expression, value, false, |
| 1674 *is_computed_name); | 1671 *is_computed_name); |
| 1675 } | 1672 } |
| 1676 | 1673 |
| 1677 if ((is_identifier || is_escaped_keyword) && | 1674 if ((is_identifier || is_escaped_keyword) && |
| 1678 (peek() == Token::COMMA || peek() == Token::RBRACE || | 1675 (peek() == Token::COMMA || peek() == Token::RBRACE || |
| 1679 peek() == Token::ASSIGN)) { | 1676 peek() == Token::ASSIGN)) { |
| 1680 // PropertyDefinition | 1677 // PropertyDefinition |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1702 | 1699 |
| 1703 ExpressionT lhs = this->ExpressionFromIdentifier( | 1700 ExpressionT lhs = this->ExpressionFromIdentifier( |
| 1704 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1701 *name, next_beg_pos, next_end_pos, scope_, factory()); |
| 1705 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1702 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
| 1706 | 1703 |
| 1707 if (peek() == Token::ASSIGN) { | 1704 if (peek() == Token::ASSIGN) { |
| 1708 Consume(Token::ASSIGN); | 1705 Consume(Token::ASSIGN); |
| 1709 ExpressionClassifier rhs_classifier; | 1706 ExpressionClassifier rhs_classifier; |
| 1710 ExpressionT rhs = this->ParseAssignmentExpression( | 1707 ExpressionT rhs = this->ParseAssignmentExpression( |
| 1711 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1708 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1709 rhs = Traits::RewriteNonPattern( |
| 1710 rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1712 classifier->Accumulate(rhs_classifier, | 1711 classifier->Accumulate(rhs_classifier, |
| 1713 ExpressionClassifier::ExpressionProductions); | 1712 ExpressionClassifier::ExpressionProductions); |
| 1714 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1713 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
| 1715 RelocInfo::kNoPosition); | 1714 RelocInfo::kNoPosition); |
| 1716 classifier->RecordCoverInitializedNameError( | 1715 classifier->RecordCoverInitializedNameError( |
| 1717 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1716 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 1718 MessageTemplate::kInvalidCoverInitializedName); | 1717 MessageTemplate::kInvalidCoverInitializedName); |
| 1719 } else { | 1718 } else { |
| 1720 value = lhs; | 1719 value = lhs; |
| 1721 } | 1720 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 | 1765 |
| 1767 return factory()->NewObjectLiteralProperty(name_expression, value, | 1766 return factory()->NewObjectLiteralProperty(name_expression, value, |
| 1768 ObjectLiteralProperty::COMPUTED, | 1767 ObjectLiteralProperty::COMPUTED, |
| 1769 is_static, *is_computed_name); | 1768 is_static, *is_computed_name); |
| 1770 } | 1769 } |
| 1771 | 1770 |
| 1772 if (in_class && name_is_static && !is_static) { | 1771 if (in_class && name_is_static && !is_static) { |
| 1773 // ClassElement (static) | 1772 // ClassElement (static) |
| 1774 // 'static' MethodDefinition | 1773 // 'static' MethodDefinition |
| 1775 *name = this->EmptyIdentifier(); | 1774 *name = this->EmptyIdentifier(); |
| 1776 return ParsePropertyDefinition(checker, true, has_extends, true, | 1775 ObjectLiteralPropertyT property = ParsePropertyDefinition( |
| 1777 is_computed_name, nullptr, classifier, name, | 1776 checker, true, has_extends, true, is_computed_name, nullptr, classifier, |
| 1778 ok); | 1777 name, ok); |
| 1778 property = Traits::RewriteNonPatternObjectLiteralProperty(property, |
| 1779 classifier, ok); |
| 1780 return property; |
| 1779 } | 1781 } |
| 1780 | 1782 |
| 1781 if (is_get || is_set) { | 1783 if (is_get || is_set) { |
| 1782 // MethodDefinition (Accessors) | 1784 // MethodDefinition (Accessors) |
| 1783 // get PropertyName '(' ')' '{' FunctionBody '}' | 1785 // get PropertyName '(' ')' '{' FunctionBody '}' |
| 1784 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 1786 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
| 1785 *name = this->EmptyIdentifier(); | 1787 *name = this->EmptyIdentifier(); |
| 1786 bool dont_care = false; | 1788 bool dont_care = false; |
| 1787 name_token = peek(); | 1789 name_token = peek(); |
| 1788 | 1790 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 1909 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
| 1908 bool done = (peek() == Token::RPAREN); | 1910 bool done = (peek() == Token::RPAREN); |
| 1909 bool was_unspread = false; | 1911 bool was_unspread = false; |
| 1910 int unspread_sequences_count = 0; | 1912 int unspread_sequences_count = 0; |
| 1911 while (!done) { | 1913 while (!done) { |
| 1912 int start_pos = peek_position(); | 1914 int start_pos = peek_position(); |
| 1913 bool is_spread = Check(Token::ELLIPSIS); | 1915 bool is_spread = Check(Token::ELLIPSIS); |
| 1914 | 1916 |
| 1915 ExpressionT argument = this->ParseAssignmentExpression( | 1917 ExpressionT argument = this->ParseAssignmentExpression( |
| 1916 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); | 1918 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
| 1919 argument = Traits::RewriteNonPattern(argument, classifier, |
| 1920 CHECK_OK_CUSTOM(NullExpressionList)); |
| 1917 if (is_spread) { | 1921 if (is_spread) { |
| 1918 if (!spread_arg.IsValid()) { | 1922 if (!spread_arg.IsValid()) { |
| 1919 spread_arg.beg_pos = start_pos; | 1923 spread_arg.beg_pos = start_pos; |
| 1920 spread_arg.end_pos = peek_position(); | 1924 spread_arg.end_pos = peek_position(); |
| 1921 } | 1925 } |
| 1922 argument = factory()->NewSpread(argument, start_pos); | 1926 argument = factory()->NewSpread(argument, start_pos); |
| 1923 } | 1927 } |
| 1924 result->Add(argument, zone_); | 1928 result->Add(argument, zone_); |
| 1925 | 1929 |
| 1926 // unspread_sequences_count is the number of sequences of parameters which | 1930 // unspread_sequences_count is the number of sequences of parameters which |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 template <class Traits> | 1968 template <class Traits> |
| 1965 typename ParserBase<Traits>::ExpressionT | 1969 typename ParserBase<Traits>::ExpressionT |
| 1966 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, | 1970 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, |
| 1967 ExpressionClassifier* classifier, | 1971 ExpressionClassifier* classifier, |
| 1968 bool* ok) { | 1972 bool* ok) { |
| 1969 // AssignmentExpression :: | 1973 // AssignmentExpression :: |
| 1970 // ConditionalExpression | 1974 // ConditionalExpression |
| 1971 // ArrowFunction | 1975 // ArrowFunction |
| 1972 // YieldExpression | 1976 // YieldExpression |
| 1973 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1977 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
| 1974 bool is_rhs = flags & kIsRightHandSide; | 1978 bool maybe_pattern_element = flags & kIsPossiblePatternElement; |
| 1975 bool is_pattern_element = flags & kIsPatternElement; | 1979 bool maybe_arrow_formals = flags & kIsPossibleArrowFormals; |
| 1976 bool is_destructuring_assignment = false; | 1980 bool is_destructuring_assignment = false; |
| 1977 bool is_arrow_formals = flags & kIsPossibleArrowFormals; | |
| 1978 int lhs_beg_pos = peek_position(); | 1981 int lhs_beg_pos = peek_position(); |
| 1979 | 1982 |
| 1980 if (peek() == Token::YIELD && is_generator()) { | 1983 if (peek() == Token::YIELD && is_generator()) { |
| 1981 return this->ParseYieldExpression(classifier, ok); | 1984 return this->ParseYieldExpression(classifier, ok); |
| 1982 } | 1985 } |
| 1983 | 1986 |
| 1984 FuncNameInferrer::State fni_state(fni_); | 1987 FuncNameInferrer::State fni_state(fni_); |
| 1985 ParserBase<Traits>::Checkpoint checkpoint(this); | 1988 ParserBase<Traits>::Checkpoint checkpoint(this); |
| 1986 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1989 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
| 1987 bool parenthesized_formals = peek() == Token::LPAREN; | 1990 bool parenthesized_formals = peek() == Token::LPAREN; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2012 scope->set_start_position(lhs_beg_pos); | 2015 scope->set_start_position(lhs_beg_pos); |
| 2013 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2016 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2014 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2017 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
| 2015 &duplicate_loc, CHECK_OK); | 2018 &duplicate_loc, CHECK_OK); |
| 2016 if (duplicate_loc.IsValid()) { | 2019 if (duplicate_loc.IsValid()) { |
| 2017 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2020 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2018 duplicate_loc); | 2021 duplicate_loc); |
| 2019 } | 2022 } |
| 2020 expression = this->ParseArrowFunctionLiteral( | 2023 expression = this->ParseArrowFunctionLiteral( |
| 2021 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2024 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
| 2022 if (is_pattern_element) { | 2025 if (maybe_pattern_element) { |
| 2023 classifier->RecordPatternError( | 2026 classifier->RecordPatternError( |
| 2024 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2027 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
| 2025 MessageTemplate::kInvalidDestructuringTarget); | 2028 MessageTemplate::kInvalidDestructuringTarget); |
| 2026 } | 2029 } |
| 2027 | 2030 |
| 2028 if (fni_ != nullptr) fni_->Infer(); | 2031 if (fni_ != nullptr) fni_->Infer(); |
| 2029 | 2032 |
| 2030 return expression; | 2033 return expression; |
| 2031 } | 2034 } |
| 2032 | 2035 |
| 2033 if (this->IsValidReferenceExpression(expression)) { | 2036 if (this->IsValidReferenceExpression(expression)) { |
| 2034 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2037 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
| 2035 } | 2038 } |
| 2036 | 2039 |
| 2037 // "expression" was not itself an arrow function parameter list, but it might | 2040 // "expression" was not itself an arrow function parameter list, but it might |
| 2038 // form part of one. Propagate speculative formal parameter error locations. | 2041 // form part of one. Propagate speculative formal parameter error locations. |
| 2039 classifier->Accumulate( | 2042 classifier->Accumulate( |
| 2040 arrow_formals_classifier, | 2043 arrow_formals_classifier, |
| 2041 ExpressionClassifier::StandardProductions | | 2044 ExpressionClassifier::StandardProductions | |
| 2042 ExpressionClassifier::FormalParametersProductions | | 2045 ExpressionClassifier::FormalParametersProductions | |
| 2043 ExpressionClassifier::CoverInitializedNameProduction); | 2046 ExpressionClassifier::CoverInitializedNameProduction); |
| 2044 | 2047 |
| 2045 bool maybe_pattern = | 2048 bool maybe_pattern = |
| 2046 (expression->IsObjectLiteral() || expression->IsArrayLiteral()) && | 2049 (expression->IsObjectLiteral() || expression->IsArrayLiteral()) && |
| 2047 !expression->is_parenthesized(); | 2050 !expression->is_parenthesized(); |
| 2048 | 2051 |
| 2049 if (!Token::IsAssignmentOp(peek())) { | 2052 if (!Token::IsAssignmentOp(peek())) { |
| 2050 // Parsed conditional expression only (no assignment). | 2053 // Parsed conditional expression only (no assignment). |
| 2051 if (is_pattern_element) { | 2054 if (maybe_pattern_element) { |
| 2052 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2055 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
| 2053 scanner()->location().end_pos); | 2056 scanner()->location().end_pos); |
| 2054 } else if (is_rhs && maybe_pattern) { | |
| 2055 ValidateExpression(classifier, CHECK_OK); | |
| 2056 } | 2057 } |
| 2057 | |
| 2058 return expression; | 2058 return expression; |
| 2059 } | 2059 } |
| 2060 | 2060 |
| 2061 if (!(allow_harmony_destructuring_bind() || | 2061 if (!(allow_harmony_destructuring_bind() || |
| 2062 allow_harmony_default_parameters())) { | 2062 allow_harmony_default_parameters())) { |
| 2063 BindingPatternUnexpectedToken(classifier); | 2063 BindingPatternUnexpectedToken(classifier); |
| 2064 } | 2064 } |
| 2065 | 2065 |
| 2066 if (allow_harmony_destructuring_assignment() && maybe_pattern && | 2066 if (allow_harmony_destructuring_assignment() && maybe_pattern && |
| 2067 peek() == Token::ASSIGN) { | 2067 peek() == Token::ASSIGN) { |
| 2068 classifier->ForgiveCoverInitializedNameError(); | 2068 classifier->ForgiveCoverInitializedNameError(); |
| 2069 ValidateAssignmentPattern(classifier, CHECK_OK); | 2069 ValidateAssignmentPattern(classifier, CHECK_OK); |
| 2070 is_destructuring_assignment = true; | 2070 is_destructuring_assignment = true; |
| 2071 } else if (is_arrow_formals) { | 2071 } else if (maybe_arrow_formals) { |
| 2072 expression = this->ClassifyAndRewriteReferenceExpression( | 2072 expression = this->ClassifyAndRewriteReferenceExpression( |
| 2073 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, | 2073 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, |
| 2074 MessageTemplate::kInvalidLhsInAssignment); | 2074 MessageTemplate::kInvalidLhsInAssignment); |
| 2075 } else { | 2075 } else { |
| 2076 if (is_pattern_element) { | 2076 if (maybe_pattern_element) { |
| 2077 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2077 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
| 2078 scanner()->location().end_pos); | 2078 scanner()->location().end_pos); |
| 2079 } | 2079 } |
| 2080 expression = this->CheckAndRewriteReferenceExpression( | 2080 expression = this->CheckAndRewriteReferenceExpression( |
| 2081 expression, lhs_beg_pos, scanner()->location().end_pos, | 2081 expression, lhs_beg_pos, scanner()->location().end_pos, |
| 2082 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2082 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
| 2083 } | 2083 } |
| 2084 | 2084 |
| 2085 expression = this->MarkExpressionAsAssigned(expression); | 2085 expression = this->MarkExpressionAsAssigned(expression); |
| 2086 | 2086 |
| 2087 Token::Value op = Next(); // Get assignment operator. | 2087 Token::Value op = Next(); // Get assignment operator. |
| 2088 if (op != Token::ASSIGN) { | 2088 if (op != Token::ASSIGN) { |
| 2089 classifier->RecordBindingPatternError(scanner()->location(), | 2089 classifier->RecordBindingPatternError(scanner()->location(), |
| 2090 MessageTemplate::kUnexpectedToken, | 2090 MessageTemplate::kUnexpectedToken, |
| 2091 Token::String(op)); | 2091 Token::String(op)); |
| 2092 } | 2092 } |
| 2093 int pos = position(); | 2093 int pos = position(); |
| 2094 | 2094 |
| 2095 ExpressionClassifier rhs_classifier; | 2095 ExpressionClassifier rhs_classifier; |
| 2096 | 2096 |
| 2097 int rhs_flags = flags; | 2097 ExpressionT right = |
| 2098 rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals); | 2098 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
| 2099 rhs_flags |= kIsRightHandSide; | 2099 right = Traits::RewriteNonPattern(right, &rhs_classifier, CHECK_OK); |
| 2100 ExpressionT right = this->ParseAssignmentExpression( | |
| 2101 accept_IN, rhs_flags, &rhs_classifier, CHECK_OK); | |
| 2102 classifier->Accumulate( | 2100 classifier->Accumulate( |
| 2103 rhs_classifier, ExpressionClassifier::ExpressionProductions | | 2101 rhs_classifier, ExpressionClassifier::ExpressionProductions | |
| 2104 ExpressionClassifier::CoverInitializedNameProduction); | 2102 ExpressionClassifier::CoverInitializedNameProduction); |
| 2105 | 2103 |
| 2106 // TODO(1231235): We try to estimate the set of properties set by | 2104 // TODO(1231235): We try to estimate the set of properties set by |
| 2107 // constructors. We define a new property whenever there is an | 2105 // constructors. We define a new property whenever there is an |
| 2108 // assignment to a property of 'this'. We should probably only add | 2106 // assignment to a property of 'this'. We should probably only add |
| 2109 // properties if we haven't seen them before. Otherwise we'll | 2107 // properties if we haven't seen them before. Otherwise we'll |
| 2110 // probably overestimate the number of properties. | 2108 // probably overestimate the number of properties. |
| 2111 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2109 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { |
| 2112 function_state_->AddProperty(); | 2110 function_state_->AddProperty(); |
| 2113 } | 2111 } |
| 2114 | 2112 |
| 2115 if (op != Token::ASSIGN && is_pattern_element) { | 2113 if (op != Token::ASSIGN && maybe_pattern_element) { |
| 2116 classifier->RecordAssignmentPatternError( | 2114 classifier->RecordAssignmentPatternError( |
| 2117 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2115 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
| 2118 MessageTemplate::kInvalidDestructuringTarget); | 2116 MessageTemplate::kInvalidDestructuringTarget); |
| 2119 } | 2117 } |
| 2120 | 2118 |
| 2121 this->CheckAssigningFunctionLiteralToProperty(expression, right); | 2119 this->CheckAssigningFunctionLiteralToProperty(expression, right); |
| 2122 | 2120 |
| 2123 if (fni_ != NULL) { | 2121 if (fni_ != NULL) { |
| 2124 // Check if the right hand side is a call to avoid inferring a | 2122 // Check if the right hand side is a call to avoid inferring a |
| 2125 // name if we're dealing with "a = function(){...}();"-like | 2123 // name if we're dealing with "a = function(){...}();"-like |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 // The above set of tokens is the complete set of tokens that can appear | 2171 // The above set of tokens is the complete set of tokens that can appear |
| 2174 // after an AssignmentExpression, and none of them can start an | 2172 // after an AssignmentExpression, and none of them can start an |
| 2175 // AssignmentExpression. This allows us to avoid looking for an RHS for | 2173 // AssignmentExpression. This allows us to avoid looking for an RHS for |
| 2176 // a Yield::kSuspend operation, given only one look-ahead token. | 2174 // a Yield::kSuspend operation, given only one look-ahead token. |
| 2177 if (kind == Yield::kSuspend) | 2175 if (kind == Yield::kSuspend) |
| 2178 break; | 2176 break; |
| 2179 DCHECK_EQ(Yield::kDelegating, kind); | 2177 DCHECK_EQ(Yield::kDelegating, kind); |
| 2180 // Delegating yields require an RHS; fall through. | 2178 // Delegating yields require an RHS; fall through. |
| 2181 default: | 2179 default: |
| 2182 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 2180 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); |
| 2181 expression = |
| 2182 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 2183 break; | 2183 break; |
| 2184 } | 2184 } |
| 2185 } | 2185 } |
| 2186 if (kind == Yield::kDelegating) { | 2186 if (kind == Yield::kDelegating) { |
| 2187 // var iterator = subject[Symbol.iterator](); | 2187 // var iterator = subject[Symbol.iterator](); |
| 2188 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2188 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
| 2189 // TODO(verwaest): Come up with a better solution. | 2189 // TODO(verwaest): Come up with a better solution. |
| 2190 expression = this->GetIterator(expression, factory(), pos + 1); | 2190 expression = this->GetIterator(expression, factory(), pos + 1); |
| 2191 } | 2191 } |
| 2192 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2192 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2205 bool* ok) { | 2205 bool* ok) { |
| 2206 // ConditionalExpression :: | 2206 // ConditionalExpression :: |
| 2207 // LogicalOrExpression | 2207 // LogicalOrExpression |
| 2208 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2208 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
| 2209 | 2209 |
| 2210 int pos = peek_position(); | 2210 int pos = peek_position(); |
| 2211 // We start using the binary expression parser for prec >= 4 only! | 2211 // We start using the binary expression parser for prec >= 4 only! |
| 2212 ExpressionT expression = | 2212 ExpressionT expression = |
| 2213 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2213 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
| 2214 if (peek() != Token::CONDITIONAL) return expression; | 2214 if (peek() != Token::CONDITIONAL) return expression; |
| 2215 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 2215 ArrowFormalParametersUnexpectedToken(classifier); | 2216 ArrowFormalParametersUnexpectedToken(classifier); |
| 2216 BindingPatternUnexpectedToken(classifier); | 2217 BindingPatternUnexpectedToken(classifier); |
| 2217 Consume(Token::CONDITIONAL); | 2218 Consume(Token::CONDITIONAL); |
| 2218 // In parsing the first assignment expression in conditional | 2219 // In parsing the first assignment expression in conditional |
| 2219 // expressions we always accept the 'in' keyword; see ECMA-262, | 2220 // expressions we always accept the 'in' keyword; see ECMA-262, |
| 2220 // section 11.12, page 58. | 2221 // section 11.12, page 58. |
| 2221 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2222 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
| 2223 left = Traits::RewriteNonPattern(left, classifier, CHECK_OK); |
| 2222 Expect(Token::COLON, CHECK_OK); | 2224 Expect(Token::COLON, CHECK_OK); |
| 2223 ExpressionT right = | 2225 ExpressionT right = |
| 2224 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2226 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
| 2227 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); |
| 2225 return factory()->NewConditional(expression, left, right, pos); | 2228 return factory()->NewConditional(expression, left, right, pos); |
| 2226 } | 2229 } |
| 2227 | 2230 |
| 2228 | 2231 |
| 2229 // Precedence >= 4 | 2232 // Precedence >= 4 |
| 2230 template <class Traits> | 2233 template <class Traits> |
| 2231 typename ParserBase<Traits>::ExpressionT | 2234 typename ParserBase<Traits>::ExpressionT |
| 2232 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2235 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
| 2233 ExpressionClassifier* classifier, | 2236 ExpressionClassifier* classifier, |
| 2234 bool* ok) { | 2237 bool* ok) { |
| 2235 DCHECK(prec >= 4); | 2238 DCHECK(prec >= 4); |
| 2236 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2239 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
| 2237 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2240 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
| 2238 // prec1 >= 4 | 2241 // prec1 >= 4 |
| 2239 while (Precedence(peek(), accept_IN) == prec1) { | 2242 while (Precedence(peek(), accept_IN) == prec1) { |
| 2243 x = Traits::RewriteNonPattern(x, classifier, CHECK_OK); |
| 2240 BindingPatternUnexpectedToken(classifier); | 2244 BindingPatternUnexpectedToken(classifier); |
| 2241 ArrowFormalParametersUnexpectedToken(classifier); | 2245 ArrowFormalParametersUnexpectedToken(classifier); |
| 2242 Token::Value op = Next(); | 2246 Token::Value op = Next(); |
| 2243 Scanner::Location op_location = scanner()->location(); | 2247 Scanner::Location op_location = scanner()->location(); |
| 2244 int pos = position(); | 2248 int pos = position(); |
| 2245 ExpressionT y = | 2249 ExpressionT y = |
| 2246 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2250 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); |
| 2251 y = Traits::RewriteNonPattern(y, classifier, CHECK_OK); |
| 2247 | 2252 |
| 2248 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2253 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
| 2249 factory())) { | 2254 factory())) { |
| 2250 continue; | 2255 continue; |
| 2251 } | 2256 } |
| 2252 | 2257 |
| 2253 // For now we distinguish between comparisons and other binary | 2258 // For now we distinguish between comparisons and other binary |
| 2254 // operations. (We could combine the two and get rid of this | 2259 // operations. (We could combine the two and get rid of this |
| 2255 // code and AST node eventually.) | 2260 // code and AST node eventually.) |
| 2256 if (Token::IsCompareOp(op)) { | 2261 if (Token::IsCompareOp(op)) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 // '!' UnaryExpression | 2304 // '!' UnaryExpression |
| 2300 | 2305 |
| 2301 Token::Value op = peek(); | 2306 Token::Value op = peek(); |
| 2302 if (Token::IsUnaryOp(op)) { | 2307 if (Token::IsUnaryOp(op)) { |
| 2303 BindingPatternUnexpectedToken(classifier); | 2308 BindingPatternUnexpectedToken(classifier); |
| 2304 ArrowFormalParametersUnexpectedToken(classifier); | 2309 ArrowFormalParametersUnexpectedToken(classifier); |
| 2305 | 2310 |
| 2306 op = Next(); | 2311 op = Next(); |
| 2307 int pos = position(); | 2312 int pos = position(); |
| 2308 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2313 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
| 2314 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 2309 | 2315 |
| 2310 if (op == Token::DELETE && is_strict(language_mode())) { | 2316 if (op == Token::DELETE && is_strict(language_mode())) { |
| 2311 if (is_strong(language_mode())) { | 2317 if (is_strong(language_mode())) { |
| 2312 ReportMessage(MessageTemplate::kStrongDelete); | 2318 ReportMessage(MessageTemplate::kStrongDelete); |
| 2313 *ok = false; | 2319 *ok = false; |
| 2314 return this->EmptyExpression(); | 2320 return this->EmptyExpression(); |
| 2315 } else if (this->IsIdentifier(expression)) { | 2321 } else if (this->IsIdentifier(expression)) { |
| 2316 // "delete identifier" is a syntax error in strict mode. | 2322 // "delete identifier" is a syntax error in strict mode. |
| 2317 ReportMessage(MessageTemplate::kStrictDelete); | 2323 ReportMessage(MessageTemplate::kStrictDelete); |
| 2318 *ok = false; | 2324 *ok = false; |
| 2319 return this->EmptyExpression(); | 2325 return this->EmptyExpression(); |
| 2320 } | 2326 } |
| 2321 } | 2327 } |
| 2322 | 2328 |
| 2323 // Allow Traits do rewrite the expression. | 2329 // Allow Traits do rewrite the expression. |
| 2324 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2330 return this->BuildUnaryExpression(expression, op, pos, factory()); |
| 2325 } else if (Token::IsCountOp(op)) { | 2331 } else if (Token::IsCountOp(op)) { |
| 2326 BindingPatternUnexpectedToken(classifier); | 2332 BindingPatternUnexpectedToken(classifier); |
| 2327 ArrowFormalParametersUnexpectedToken(classifier); | 2333 ArrowFormalParametersUnexpectedToken(classifier); |
| 2328 op = Next(); | 2334 op = Next(); |
| 2329 int beg_pos = peek_position(); | 2335 int beg_pos = peek_position(); |
| 2330 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2336 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
| 2331 expression = this->CheckAndRewriteReferenceExpression( | 2337 expression = this->CheckAndRewriteReferenceExpression( |
| 2332 expression, beg_pos, scanner()->location().end_pos, | 2338 expression, beg_pos, scanner()->location().end_pos, |
| 2333 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2339 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
| 2334 this->MarkExpressionAsAssigned(expression); | 2340 this->MarkExpressionAsAssigned(expression); |
| 2341 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 2335 | 2342 |
| 2336 return factory()->NewCountOperation(op, | 2343 return factory()->NewCountOperation(op, |
| 2337 true /* prefix */, | 2344 true /* prefix */, |
| 2338 expression, | 2345 expression, |
| 2339 position()); | 2346 position()); |
| 2340 | 2347 |
| 2341 } else { | 2348 } else { |
| 2342 return this->ParsePostfixExpression(classifier, ok); | 2349 return this->ParsePostfixExpression(classifier, ok); |
| 2343 } | 2350 } |
| 2344 } | 2351 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2356 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2363 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
| 2357 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 2364 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 2358 Token::IsCountOp(peek())) { | 2365 Token::IsCountOp(peek())) { |
| 2359 BindingPatternUnexpectedToken(classifier); | 2366 BindingPatternUnexpectedToken(classifier); |
| 2360 ArrowFormalParametersUnexpectedToken(classifier); | 2367 ArrowFormalParametersUnexpectedToken(classifier); |
| 2361 | 2368 |
| 2362 expression = this->CheckAndRewriteReferenceExpression( | 2369 expression = this->CheckAndRewriteReferenceExpression( |
| 2363 expression, lhs_beg_pos, scanner()->location().end_pos, | 2370 expression, lhs_beg_pos, scanner()->location().end_pos, |
| 2364 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 2371 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
| 2365 expression = this->MarkExpressionAsAssigned(expression); | 2372 expression = this->MarkExpressionAsAssigned(expression); |
| 2373 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 2366 | 2374 |
| 2367 Token::Value next = Next(); | 2375 Token::Value next = Next(); |
| 2368 expression = | 2376 expression = |
| 2369 factory()->NewCountOperation(next, | 2377 factory()->NewCountOperation(next, |
| 2370 false /* postfix */, | 2378 false /* postfix */, |
| 2371 expression, | 2379 expression, |
| 2372 position()); | 2380 position()); |
| 2373 } | 2381 } |
| 2374 return expression; | 2382 return expression; |
| 2375 } | 2383 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2386 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2394 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
| 2387 | 2395 |
| 2388 while (true) { | 2396 while (true) { |
| 2389 switch (peek()) { | 2397 switch (peek()) { |
| 2390 case Token::LBRACK: { | 2398 case Token::LBRACK: { |
| 2391 BindingPatternUnexpectedToken(classifier); | 2399 BindingPatternUnexpectedToken(classifier); |
| 2392 ArrowFormalParametersUnexpectedToken(classifier); | 2400 ArrowFormalParametersUnexpectedToken(classifier); |
| 2393 Consume(Token::LBRACK); | 2401 Consume(Token::LBRACK); |
| 2394 int pos = position(); | 2402 int pos = position(); |
| 2395 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2403 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
| 2404 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
| 2396 result = factory()->NewProperty(result, index, pos); | 2405 result = factory()->NewProperty(result, index, pos); |
| 2397 Expect(Token::RBRACK, CHECK_OK); | 2406 Expect(Token::RBRACK, CHECK_OK); |
| 2398 break; | 2407 break; |
| 2399 } | 2408 } |
| 2400 | 2409 |
| 2401 case Token::LPAREN: { | 2410 case Token::LPAREN: { |
| 2411 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); |
| 2402 BindingPatternUnexpectedToken(classifier); | 2412 BindingPatternUnexpectedToken(classifier); |
| 2403 ArrowFormalParametersUnexpectedToken(classifier); | 2413 ArrowFormalParametersUnexpectedToken(classifier); |
| 2404 | 2414 |
| 2405 if (is_strong(language_mode()) && this->IsIdentifier(result) && | 2415 if (is_strong(language_mode()) && this->IsIdentifier(result) && |
| 2406 this->IsEval(this->AsIdentifier(result))) { | 2416 this->IsEval(this->AsIdentifier(result))) { |
| 2407 ReportMessage(MessageTemplate::kStrongDirectEval); | 2417 ReportMessage(MessageTemplate::kStrongDirectEval); |
| 2408 *ok = false; | 2418 *ok = false; |
| 2409 return this->EmptyExpression(); | 2419 return this->EmptyExpression(); |
| 2410 } | 2420 } |
| 2411 int pos; | 2421 int pos; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2519 int new_pos = position(); | 2529 int new_pos = position(); |
| 2520 ExpressionT result = this->EmptyExpression(); | 2530 ExpressionT result = this->EmptyExpression(); |
| 2521 if (peek() == Token::SUPER) { | 2531 if (peek() == Token::SUPER) { |
| 2522 const bool is_new = true; | 2532 const bool is_new = true; |
| 2523 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2533 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
| 2524 } else if (peek() == Token::PERIOD) { | 2534 } else if (peek() == Token::PERIOD) { |
| 2525 return ParseNewTargetExpression(CHECK_OK); | 2535 return ParseNewTargetExpression(CHECK_OK); |
| 2526 } else { | 2536 } else { |
| 2527 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2537 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
| 2528 } | 2538 } |
| 2539 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); |
| 2529 if (peek() == Token::LPAREN) { | 2540 if (peek() == Token::LPAREN) { |
| 2530 // NewExpression with arguments. | 2541 // NewExpression with arguments. |
| 2531 Scanner::Location spread_pos; | 2542 Scanner::Location spread_pos; |
| 2532 typename Traits::Type::ExpressionList args = | 2543 typename Traits::Type::ExpressionList args = |
| 2533 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2544 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
| 2534 | 2545 |
| 2535 if (spread_pos.IsValid()) { | 2546 if (spread_pos.IsValid()) { |
| 2536 args = Traits::PrepareSpreadArguments(args); | 2547 args = Traits::PrepareSpreadArguments(args); |
| 2537 result = Traits::SpreadCallNew(result, args, new_pos); | 2548 result = Traits::SpreadCallNew(result, args, new_pos); |
| 2538 } else { | 2549 } else { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 int pos = position(); | 2629 int pos = position(); |
| 2619 function_state_->set_this_location(scanner()->location()); | 2630 function_state_->set_this_location(scanner()->location()); |
| 2620 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2631 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
| 2621 | 2632 |
| 2622 ExpressionT left = this->EmptyExpression(); | 2633 ExpressionT left = this->EmptyExpression(); |
| 2623 switch (peek()) { | 2634 switch (peek()) { |
| 2624 case Token::LBRACK: { | 2635 case Token::LBRACK: { |
| 2625 Consume(Token::LBRACK); | 2636 Consume(Token::LBRACK); |
| 2626 int pos = position(); | 2637 int pos = position(); |
| 2627 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2638 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
| 2639 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
| 2628 left = factory()->NewProperty(this_expr, index, pos); | 2640 left = factory()->NewProperty(this_expr, index, pos); |
| 2629 if (fni_ != NULL) { | 2641 if (fni_ != NULL) { |
| 2630 this->PushPropertyName(fni_, index); | 2642 this->PushPropertyName(fni_, index); |
| 2631 } | 2643 } |
| 2632 Expect(Token::RBRACK, CHECK_OK); | 2644 Expect(Token::RBRACK, CHECK_OK); |
| 2633 break; | 2645 break; |
| 2634 } | 2646 } |
| 2635 case Token::PERIOD: { | 2647 case Token::PERIOD: { |
| 2636 Consume(Token::PERIOD); | 2648 Consume(Token::PERIOD); |
| 2637 int pos = position(); | 2649 int pos = position(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2653 ReportMessageAt(function_state_->this_location(), | 2665 ReportMessageAt(function_state_->this_location(), |
| 2654 MessageTemplate::kStrongConstructorThis); | 2666 MessageTemplate::kStrongConstructorThis); |
| 2655 *ok = false; | 2667 *ok = false; |
| 2656 return this->EmptyExpression(); | 2668 return this->EmptyExpression(); |
| 2657 } | 2669 } |
| 2658 Consume(Token::ASSIGN); | 2670 Consume(Token::ASSIGN); |
| 2659 left = this->MarkExpressionAsAssigned(left); | 2671 left = this->MarkExpressionAsAssigned(left); |
| 2660 | 2672 |
| 2661 ExpressionT right = | 2673 ExpressionT right = |
| 2662 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2674 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| 2675 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); |
| 2663 this->CheckAssigningFunctionLiteralToProperty(left, right); | 2676 this->CheckAssigningFunctionLiteralToProperty(left, right); |
| 2664 function_state_->AddProperty(); | 2677 function_state_->AddProperty(); |
| 2665 if (fni_ != NULL) { | 2678 if (fni_ != NULL) { |
| 2666 // Check if the right hand side is a call to avoid inferring a | 2679 // Check if the right hand side is a call to avoid inferring a |
| 2667 // name if we're dealing with "this.a = function(){...}();"-like | 2680 // name if we're dealing with "this.a = function(){...}();"-like |
| 2668 // expression. | 2681 // expression. |
| 2669 if (!right->IsCall() && !right->IsCallNew()) { | 2682 if (!right->IsCall() && !right->IsCallNew()) { |
| 2670 fni_->Infer(); | 2683 fni_->Infer(); |
| 2671 } else { | 2684 } else { |
| 2672 fni_->RemoveLastFunction(); | 2685 fni_->RemoveLastFunction(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2809 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2822 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
| 2810 while (true) { | 2823 while (true) { |
| 2811 switch (peek()) { | 2824 switch (peek()) { |
| 2812 case Token::LBRACK: { | 2825 case Token::LBRACK: { |
| 2813 BindingPatternUnexpectedToken(classifier); | 2826 BindingPatternUnexpectedToken(classifier); |
| 2814 ArrowFormalParametersUnexpectedToken(classifier); | 2827 ArrowFormalParametersUnexpectedToken(classifier); |
| 2815 | 2828 |
| 2816 Consume(Token::LBRACK); | 2829 Consume(Token::LBRACK); |
| 2817 int pos = position(); | 2830 int pos = position(); |
| 2818 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2831 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
| 2832 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
| 2819 expression = factory()->NewProperty(expression, index, pos); | 2833 expression = factory()->NewProperty(expression, index, pos); |
| 2820 if (fni_ != NULL) { | 2834 if (fni_ != NULL) { |
| 2821 this->PushPropertyName(fni_, index); | 2835 this->PushPropertyName(fni_, index); |
| 2822 } | 2836 } |
| 2823 Expect(Token::RBRACK, CHECK_OK); | 2837 Expect(Token::RBRACK, CHECK_OK); |
| 2824 break; | 2838 break; |
| 2825 } | 2839 } |
| 2826 case Token::PERIOD: { | 2840 case Token::PERIOD: { |
| 2827 BindingPatternUnexpectedToken(classifier); | 2841 BindingPatternUnexpectedToken(classifier); |
| 2828 ArrowFormalParametersUnexpectedToken(classifier); | 2842 ArrowFormalParametersUnexpectedToken(classifier); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2889 ValidateFormalParameterInitializer(classifier, ok); | 2903 ValidateFormalParameterInitializer(classifier, ok); |
| 2890 if (!*ok) return; | 2904 if (!*ok) return; |
| 2891 classifier->RecordNonSimpleParameter(); | 2905 classifier->RecordNonSimpleParameter(); |
| 2892 } | 2906 } |
| 2893 | 2907 |
| 2894 ExpressionT initializer = Traits::EmptyExpression(); | 2908 ExpressionT initializer = Traits::EmptyExpression(); |
| 2895 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { | 2909 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
| 2896 ExpressionClassifier init_classifier; | 2910 ExpressionClassifier init_classifier; |
| 2897 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 2911 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
| 2898 if (!*ok) return; | 2912 if (!*ok) return; |
| 2899 ValidateExpression(&init_classifier, ok); | 2913 initializer = Traits::RewriteNonPattern(initializer, &init_classifier, ok); |
| 2900 ValidateFormalParameterInitializer(&init_classifier, ok); | 2914 ValidateFormalParameterInitializer(&init_classifier, ok); |
| 2901 if (!*ok) return; | 2915 if (!*ok) return; |
| 2902 parameters->is_simple = false; | 2916 parameters->is_simple = false; |
| 2903 classifier->RecordNonSimpleParameter(); | 2917 classifier->RecordNonSimpleParameter(); |
| 2904 } | 2918 } |
| 2905 | 2919 |
| 2906 Traits::AddFormalParameter(parameters, pattern, initializer, | 2920 Traits::AddFormalParameter(parameters, pattern, initializer, |
| 2907 scanner()->location().end_pos, is_rest); | 2921 scanner()->location().end_pos, is_rest); |
| 2908 } | 2922 } |
| 2909 | 2923 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3063 function_state.materialized_literal_count(); | 3077 function_state.materialized_literal_count(); |
| 3064 expected_property_count = function_state.expected_property_count(); | 3078 expected_property_count = function_state.expected_property_count(); |
| 3065 } | 3079 } |
| 3066 } else { | 3080 } else { |
| 3067 // Single-expression body | 3081 // Single-expression body |
| 3068 int pos = position(); | 3082 int pos = position(); |
| 3069 parenthesized_function_ = false; | 3083 parenthesized_function_ = false; |
| 3070 ExpressionClassifier classifier; | 3084 ExpressionClassifier classifier; |
| 3071 ExpressionT expression = | 3085 ExpressionT expression = |
| 3072 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); | 3086 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
| 3073 ValidateExpression(&classifier, CHECK_OK); | 3087 expression = Traits::RewriteNonPattern(expression, &classifier, CHECK_OK); |
| 3074 body = this->NewStatementList(1, zone()); | 3088 body = this->NewStatementList(1, zone()); |
| 3075 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3089 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
| 3076 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3090 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
| 3077 materialized_literal_count = function_state.materialized_literal_count(); | 3091 materialized_literal_count = function_state.materialized_literal_count(); |
| 3078 expected_property_count = function_state.expected_property_count(); | 3092 expected_property_count = function_state.expected_property_count(); |
| 3079 } | 3093 } |
| 3080 super_loc = function_state.super_location(); | 3094 super_loc = function_state.super_location(); |
| 3081 | 3095 |
| 3082 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3096 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
| 3083 | 3097 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3169 } else if (next == Token::ILLEGAL) { | 3183 } else if (next == Token::ILLEGAL) { |
| 3170 Traits::ReportMessageAt( | 3184 Traits::ReportMessageAt( |
| 3171 Scanner::Location(position() + 1, peek_position()), | 3185 Scanner::Location(position() + 1, peek_position()), |
| 3172 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 3186 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
| 3173 *ok = false; | 3187 *ok = false; |
| 3174 return Traits::EmptyExpression(); | 3188 return Traits::EmptyExpression(); |
| 3175 } | 3189 } |
| 3176 | 3190 |
| 3177 int expr_pos = peek_position(); | 3191 int expr_pos = peek_position(); |
| 3178 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); | 3192 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); |
| 3193 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
| 3179 Traits::AddTemplateExpression(&ts, expression); | 3194 Traits::AddTemplateExpression(&ts, expression); |
| 3180 | 3195 |
| 3181 if (peek() != Token::RBRACE) { | 3196 if (peek() != Token::RBRACE) { |
| 3182 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), | 3197 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), |
| 3183 MessageTemplate::kUnterminatedTemplateExpr); | 3198 MessageTemplate::kUnterminatedTemplateExpr); |
| 3184 *ok = false; | 3199 *ok = false; |
| 3185 return Traits::EmptyExpression(); | 3200 return Traits::EmptyExpression(); |
| 3186 } | 3201 } |
| 3187 | 3202 |
| 3188 // If we didn't die parsing that expression, our next token should be a | 3203 // If we didn't die parsing that expression, our next token should be a |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3356 return; | 3371 return; |
| 3357 } | 3372 } |
| 3358 has_seen_constructor_ = true; | 3373 has_seen_constructor_ = true; |
| 3359 return; | 3374 return; |
| 3360 } | 3375 } |
| 3361 } | 3376 } |
| 3362 } // namespace internal | 3377 } // namespace internal |
| 3363 } // namespace v8 | 3378 } // namespace v8 |
| 3364 | 3379 |
| 3365 #endif // V8_PARSING_PARSER_BASE_H | 3380 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |