| 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 11 matching lines...) Expand all Loading... |
| 22 kFunctionNameIsStrictReserved, | 22 kFunctionNameIsStrictReserved, |
| 23 kSkipFunctionNameCheck, | 23 kSkipFunctionNameCheck, |
| 24 kFunctionNameValidityUnknown | 24 kFunctionNameValidityUnknown |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 enum AllowLabelledFunctionStatement { | 27 enum AllowLabelledFunctionStatement { |
| 28 kAllowLabelledFunctionStatement, | 28 kAllowLabelledFunctionStatement, |
| 29 kDisallowLabelledFunctionStatement, | 29 kDisallowLabelledFunctionStatement, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 enum class ParseFunctionFlags { |
| 33 kIsNormal = 0, |
| 34 kIsGenerator = 1, |
| 35 kIsAsync = 2, |
| 36 kIsDefault = 4 |
| 37 }; |
| 38 |
| 39 static inline ParseFunctionFlags operator|(ParseFunctionFlags lhs, |
| 40 ParseFunctionFlags rhs) { |
| 41 typedef unsigned char T; |
| 42 return static_cast<ParseFunctionFlags>(static_cast<T>(lhs) | |
| 43 static_cast<T>(rhs)); |
| 44 } |
| 45 |
| 46 static inline ParseFunctionFlags& operator|=(ParseFunctionFlags& lhs, |
| 47 const ParseFunctionFlags& rhs) { |
| 48 lhs = lhs | rhs; |
| 49 return lhs; |
| 50 } |
| 51 |
| 52 static inline bool operator&(ParseFunctionFlags bitfield, |
| 53 ParseFunctionFlags mask) { |
| 54 typedef unsigned char T; |
| 55 return static_cast<T>(bitfield) & static_cast<T>(mask); |
| 56 } |
| 57 |
| 32 struct FormalParametersBase { | 58 struct FormalParametersBase { |
| 33 explicit FormalParametersBase(Scope* scope) : scope(scope) {} | 59 explicit FormalParametersBase(Scope* scope) : scope(scope) {} |
| 34 Scope* scope; | 60 Scope* scope; |
| 35 bool has_rest = false; | 61 bool has_rest = false; |
| 36 bool is_simple = true; | 62 bool is_simple = true; |
| 37 int materialized_literals_count = 0; | 63 int materialized_literals_count = 0; |
| 38 }; | 64 }; |
| 39 | 65 |
| 40 | 66 |
| 41 // Common base class shared between parser and pre-parser. Traits encapsulate | 67 // Common base class shared between parser and pre-parser. Traits encapsulate |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 zone_(zone), | 136 zone_(zone), |
| 111 scanner_(scanner), | 137 scanner_(scanner), |
| 112 stack_overflow_(false), | 138 stack_overflow_(false), |
| 113 allow_lazy_(false), | 139 allow_lazy_(false), |
| 114 allow_natives_(false), | 140 allow_natives_(false), |
| 115 allow_tailcalls_(false), | 141 allow_tailcalls_(false), |
| 116 allow_harmony_restrictive_declarations_(false), | 142 allow_harmony_restrictive_declarations_(false), |
| 117 allow_harmony_do_expressions_(false), | 143 allow_harmony_do_expressions_(false), |
| 118 allow_harmony_for_in_(false), | 144 allow_harmony_for_in_(false), |
| 119 allow_harmony_function_name_(false), | 145 allow_harmony_function_name_(false), |
| 120 allow_harmony_function_sent_(false) {} | 146 allow_harmony_function_sent_(false), |
| 147 allow_harmony_async_await_(false) {} |
| 121 | 148 |
| 122 #define ALLOW_ACCESSORS(name) \ | 149 #define ALLOW_ACCESSORS(name) \ |
| 123 bool allow_##name() const { return allow_##name##_; } \ | 150 bool allow_##name() const { return allow_##name##_; } \ |
| 124 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 151 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 125 | 152 |
| 126 #define SCANNER_ACCESSORS(name) \ | 153 #define SCANNER_ACCESSORS(name) \ |
| 127 bool allow_##name() const { return scanner_->allow_##name(); } \ | 154 bool allow_##name() const { return scanner_->allow_##name(); } \ |
| 128 void set_allow_##name(bool allow) { \ | 155 void set_allow_##name(bool allow) { \ |
| 129 return scanner_->set_allow_##name(allow); \ | 156 return scanner_->set_allow_##name(allow); \ |
| 130 } | 157 } |
| 131 | 158 |
| 132 ALLOW_ACCESSORS(lazy); | 159 ALLOW_ACCESSORS(lazy); |
| 133 ALLOW_ACCESSORS(natives); | 160 ALLOW_ACCESSORS(natives); |
| 134 ALLOW_ACCESSORS(tailcalls); | 161 ALLOW_ACCESSORS(tailcalls); |
| 135 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 162 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
| 136 ALLOW_ACCESSORS(harmony_do_expressions); | 163 ALLOW_ACCESSORS(harmony_do_expressions); |
| 137 ALLOW_ACCESSORS(harmony_for_in); | 164 ALLOW_ACCESSORS(harmony_for_in); |
| 138 ALLOW_ACCESSORS(harmony_function_name); | 165 ALLOW_ACCESSORS(harmony_function_name); |
| 139 ALLOW_ACCESSORS(harmony_function_sent); | 166 ALLOW_ACCESSORS(harmony_function_sent); |
| 167 ALLOW_ACCESSORS(harmony_async_await); |
| 140 SCANNER_ACCESSORS(harmony_exponentiation_operator); | 168 SCANNER_ACCESSORS(harmony_exponentiation_operator); |
| 141 | 169 |
| 142 #undef SCANNER_ACCESSORS | 170 #undef SCANNER_ACCESSORS |
| 143 #undef ALLOW_ACCESSORS | 171 #undef ALLOW_ACCESSORS |
| 144 | 172 |
| 145 uintptr_t stack_limit() const { return stack_limit_; } | 173 uintptr_t stack_limit() const { return stack_limit_; } |
| 146 | 174 |
| 147 protected: | 175 protected: |
| 148 enum AllowRestrictedIdentifiers { | 176 enum AllowRestrictedIdentifiers { |
| 149 kAllowRestrictedIdentifiers, | 177 kAllowRestrictedIdentifiers, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 this_location_ = location; | 305 this_location_ = location; |
| 278 } | 306 } |
| 279 void set_super_location(Scanner::Location location) { | 307 void set_super_location(Scanner::Location location) { |
| 280 super_location_ = location; | 308 super_location_ = location; |
| 281 } | 309 } |
| 282 void set_return_location(Scanner::Location location) { | 310 void set_return_location(Scanner::Location location) { |
| 283 return_location_ = location; | 311 return_location_ = location; |
| 284 } | 312 } |
| 285 | 313 |
| 286 bool is_generator() const { return IsGeneratorFunction(kind_); } | 314 bool is_generator() const { return IsGeneratorFunction(kind_); } |
| 315 bool is_async_function() const { return IsAsyncFunction(kind_); } |
| 287 | 316 |
| 288 FunctionKind kind() const { return kind_; } | 317 FunctionKind kind() const { return kind_; } |
| 289 FunctionState* outer() const { return outer_function_state_; } | 318 FunctionState* outer() const { return outer_function_state_; } |
| 290 | 319 |
| 291 void set_generator_object_variable( | 320 void set_generator_object_variable( |
| 292 typename Traits::Type::GeneratorVariable* variable) { | 321 typename Traits::Type::GeneratorVariable* variable) { |
| 293 DCHECK(variable != NULL); | 322 DCHECK(variable != NULL); |
| 294 DCHECK(is_generator()); | 323 DCHECK(is_generator()); |
| 295 generator_object_variable_ = variable; | 324 generator_object_variable_ = variable; |
| 296 } | 325 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 return true; | 616 return true; |
| 588 } | 617 } |
| 589 return false; | 618 return false; |
| 590 } | 619 } |
| 591 | 620 |
| 592 bool PeekContextualKeyword(Vector<const char> keyword) { | 621 bool PeekContextualKeyword(Vector<const char> keyword) { |
| 593 return peek() == Token::IDENTIFIER && | 622 return peek() == Token::IDENTIFIER && |
| 594 scanner()->is_next_contextual_keyword(keyword); | 623 scanner()->is_next_contextual_keyword(keyword); |
| 595 } | 624 } |
| 596 | 625 |
| 626 bool PeekAheadContextualKeyword(Vector<const char> keyword) { |
| 627 return PeekAhead() == Token::IDENTIFIER && |
| 628 scanner()->is_next_next_contextual_keyword(keyword); |
| 629 } |
| 630 |
| 597 void ExpectMetaProperty(Vector<const char> property_name, | 631 void ExpectMetaProperty(Vector<const char> property_name, |
| 598 const char* full_name, int pos, bool* ok); | 632 const char* full_name, int pos, bool* ok); |
| 599 | 633 |
| 600 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { | 634 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { |
| 601 Expect(Token::IDENTIFIER, ok); | 635 Expect(Token::IDENTIFIER, ok); |
| 602 if (!*ok) return; | 636 if (!*ok) return; |
| 603 if (!scanner()->is_literal_contextual_keyword(keyword)) { | 637 if (!scanner()->is_literal_contextual_keyword(keyword)) { |
| 604 ReportUnexpectedToken(scanner()->current_token()); | 638 ReportUnexpectedToken(scanner()->current_token()); |
| 605 *ok = false; | 639 *ok = false; |
| 606 } | 640 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 return 0; // 0 precedence will terminate binary expression parsing | 711 return 0; // 0 precedence will terminate binary expression parsing |
| 678 return Token::Precedence(token); | 712 return Token::Precedence(token); |
| 679 } | 713 } |
| 680 | 714 |
| 681 typename Traits::Type::Factory* factory() { | 715 typename Traits::Type::Factory* factory() { |
| 682 return function_state_->factory(); | 716 return function_state_->factory(); |
| 683 } | 717 } |
| 684 | 718 |
| 685 LanguageMode language_mode() { return scope_->language_mode(); } | 719 LanguageMode language_mode() { return scope_->language_mode(); } |
| 686 bool is_generator() const { return function_state_->is_generator(); } | 720 bool is_generator() const { return function_state_->is_generator(); } |
| 721 bool is_async_function() const { |
| 722 return function_state_->is_async_function(); |
| 723 } |
| 687 | 724 |
| 688 // Report syntax errors. | 725 // Report syntax errors. |
| 689 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 726 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
| 690 ParseErrorType error_type = kSyntaxError) { | 727 ParseErrorType error_type = kSyntaxError) { |
| 691 Scanner::Location source_location = scanner()->location(); | 728 Scanner::Location source_location = scanner()->location(); |
| 692 Traits::ReportMessageAt(source_location, message, arg, error_type); | 729 Traits::ReportMessageAt(source_location, message, arg, error_type); |
| 693 } | 730 } |
| 694 | 731 |
| 695 void ReportMessageAt(Scanner::Location location, | 732 void ReportMessageAt(Scanner::Location location, |
| 696 MessageTemplate::Template message, | 733 MessageTemplate::Template message, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void ValidateFormalParameterInitializer( | 770 void ValidateFormalParameterInitializer( |
| 734 const ExpressionClassifier* classifier, bool* ok) { | 771 const ExpressionClassifier* classifier, bool* ok) { |
| 735 if (!classifier->is_valid_formal_parameter_initializer()) { | 772 if (!classifier->is_valid_formal_parameter_initializer()) { |
| 736 ReportClassifierError(classifier->formal_parameter_initializer_error()); | 773 ReportClassifierError(classifier->formal_parameter_initializer_error()); |
| 737 *ok = false; | 774 *ok = false; |
| 738 } | 775 } |
| 739 } | 776 } |
| 740 | 777 |
| 741 void ValidateBindingPattern(const ExpressionClassifier* classifier, | 778 void ValidateBindingPattern(const ExpressionClassifier* classifier, |
| 742 bool* ok) { | 779 bool* ok) { |
| 743 if (!classifier->is_valid_binding_pattern()) { | 780 if (!classifier->is_valid_binding_pattern() || |
| 744 ReportClassifierError(classifier->binding_pattern_error()); | 781 !classifier->is_valid_async_binding_pattern()) { |
| 782 const Scanner::Location& a = classifier->binding_pattern_error().location; |
| 783 const Scanner::Location& b = |
| 784 classifier->async_binding_pattern_error().location; |
| 785 if (a.beg_pos < 0 || (b.beg_pos >= 0 && a.beg_pos > b.beg_pos)) { |
| 786 ReportClassifierError(classifier->async_binding_pattern_error()); |
| 787 } else { |
| 788 ReportClassifierError(classifier->binding_pattern_error()); |
| 789 } |
| 745 *ok = false; | 790 *ok = false; |
| 746 } | 791 } |
| 747 } | 792 } |
| 748 | 793 |
| 749 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, | 794 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, |
| 750 bool* ok) { | 795 bool* ok) { |
| 751 if (!classifier->is_valid_assignment_pattern()) { | 796 if (!classifier->is_valid_assignment_pattern()) { |
| 752 ReportClassifierError(classifier->assignment_pattern_error()); | 797 ReportClassifierError(classifier->assignment_pattern_error()); |
| 753 *ok = false; | 798 *ok = false; |
| 754 } | 799 } |
| 755 } | 800 } |
| 756 | 801 |
| 757 void ValidateFormalParameters(const ExpressionClassifier* classifier, | 802 void ValidateFormalParameters(const ExpressionClassifier* classifier, |
| 758 LanguageMode language_mode, | 803 LanguageMode language_mode, |
| 759 bool allow_duplicates, bool* ok) { | 804 bool allow_duplicates, bool* ok) { |
| 760 if (!allow_duplicates && | 805 if (!allow_duplicates && |
| 761 !classifier->is_valid_formal_parameter_list_without_duplicates()) { | 806 !classifier->is_valid_formal_parameter_list_without_duplicates()) { |
| 762 ReportClassifierError(classifier->duplicate_formal_parameter_error()); | 807 ReportClassifierError(classifier->duplicate_formal_parameter_error()); |
| 763 *ok = false; | 808 *ok = false; |
| 764 } else if (is_strict(language_mode) && | 809 } else if (is_strict(language_mode) && |
| 765 !classifier->is_valid_strict_mode_formal_parameters()) { | 810 !classifier->is_valid_strict_mode_formal_parameters()) { |
| 766 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); | 811 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); |
| 767 *ok = false; | 812 *ok = false; |
| 768 } | 813 } |
| 769 } | 814 } |
| 770 | 815 |
| 771 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, | 816 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
| 772 ExpressionT expr, | 817 ExpressionT expr, |
| 773 bool parenthesized_formals, bool* ok) { | 818 bool parenthesized_formals, bool is_async, |
| 819 bool* ok) { |
| 774 if (classifier->is_valid_binding_pattern()) { | 820 if (classifier->is_valid_binding_pattern()) { |
| 775 // A simple arrow formal parameter: IDENTIFIER => BODY. | 821 // A simple arrow formal parameter: IDENTIFIER => BODY. |
| 776 if (!this->IsIdentifier(expr)) { | 822 if (!this->IsIdentifier(expr)) { |
| 777 Traits::ReportMessageAt(scanner()->location(), | 823 Traits::ReportMessageAt(scanner()->location(), |
| 778 MessageTemplate::kUnexpectedToken, | 824 MessageTemplate::kUnexpectedToken, |
| 779 Token::String(scanner()->current_token())); | 825 Token::String(scanner()->current_token())); |
| 780 *ok = false; | 826 *ok = false; |
| 781 } | 827 } |
| 782 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 828 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
| 783 // If after parsing the expr, we see an error but the expression is | 829 // If after parsing the expr, we see an error but the expression is |
| 784 // neither a valid binding pattern nor a valid parenthesized formal | 830 // neither a valid binding pattern nor a valid parenthesized formal |
| 785 // parameter list, show the "arrow formal parameters" error if the formals | 831 // parameter list, show the "arrow formal parameters" error if the formals |
| 786 // started with a parenthesis, and the binding pattern error otherwise. | 832 // started with a parenthesis, and the binding pattern error otherwise. |
| 787 const typename ExpressionClassifier::Error& error = | 833 const typename ExpressionClassifier::Error& error = |
| 788 parenthesized_formals ? classifier->arrow_formal_parameters_error() | 834 parenthesized_formals ? classifier->arrow_formal_parameters_error() |
| 789 : classifier->binding_pattern_error(); | 835 : classifier->binding_pattern_error(); |
| 790 ReportClassifierError(error); | 836 ReportClassifierError(error); |
| 791 *ok = false; | 837 *ok = false; |
| 792 } | 838 } |
| 839 if (is_async && !classifier->is_valid_async_arrow_formal_parameters()) { |
| 840 const typename ExpressionClassifier::Error& error = |
| 841 classifier->async_arrow_formal_parameters_error(); |
| 842 ReportClassifierError(error); |
| 843 *ok = false; |
| 844 } |
| 793 } | 845 } |
| 794 | 846 |
| 795 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { | 847 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { |
| 796 if (!classifier->is_valid_let_pattern()) { | 848 if (!classifier->is_valid_let_pattern()) { |
| 797 ReportClassifierError(classifier->let_pattern_error()); | 849 ReportClassifierError(classifier->let_pattern_error()); |
| 798 *ok = false; | 850 *ok = false; |
| 799 } | 851 } |
| 800 } | 852 } |
| 801 | 853 |
| 802 void CheckNoTailCallExpressions(const ExpressionClassifier* classifier, | 854 void CheckNoTailCallExpressions(const ExpressionClassifier* classifier, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 return ParseIdentifierOrStrictReservedWord(this->is_generator(), | 908 return ParseIdentifierOrStrictReservedWord(this->is_generator(), |
| 857 is_strict_reserved, ok); | 909 is_strict_reserved, ok); |
| 858 } | 910 } |
| 859 | 911 |
| 860 IdentifierT ParseIdentifierName(bool* ok); | 912 IdentifierT ParseIdentifierName(bool* ok); |
| 861 | 913 |
| 862 ExpressionT ParseRegExpLiteral(bool seen_equal, | 914 ExpressionT ParseRegExpLiteral(bool seen_equal, |
| 863 ExpressionClassifier* classifier, bool* ok); | 915 ExpressionClassifier* classifier, bool* ok); |
| 864 | 916 |
| 865 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 917 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
| 866 bool* ok); | 918 bool* is_async, bool* ok); |
| 919 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
| 920 bool* ok) { |
| 921 bool is_async; |
| 922 return ParsePrimaryExpression(classifier, &is_async, ok); |
| 923 } |
| 867 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 924 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 868 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, | 925 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, |
| 869 bool* ok); | 926 bool* ok); |
| 870 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); | 927 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); |
| 871 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 928 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 872 bool* is_computed_name, | 929 bool* is_await, bool* is_computed_name, |
| 873 ExpressionClassifier* classifier, bool* ok); | 930 ExpressionClassifier* classifier, bool* ok); |
| 874 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 931 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
| 875 ObjectLiteralPropertyT ParsePropertyDefinition( | 932 ObjectLiteralPropertyT ParsePropertyDefinition( |
| 876 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 933 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 877 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 934 MethodKind kind, bool* is_computed_name, bool* has_seen_constructor, |
| 878 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 935 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
| 879 typename Traits::Type::ExpressionList ParseArguments( | 936 typename Traits::Type::ExpressionList ParseArguments( |
| 937 Scanner::Location* first_spread_pos, bool maybe_arrow, |
| 938 ExpressionClassifier* classifier, bool* ok); |
| 939 typename Traits::Type::ExpressionList ParseArguments( |
| 880 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 940 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
| 881 bool* ok); | 941 bool* ok) { |
| 942 return ParseArguments(first_spread_pos, false, classifier, ok); |
| 943 } |
| 882 | 944 |
| 883 ExpressionT ParseAssignmentExpression(bool accept_IN, | 945 ExpressionT ParseAssignmentExpression(bool accept_IN, |
| 884 ExpressionClassifier* classifier, | 946 ExpressionClassifier* classifier, |
| 885 bool* ok); | 947 bool* ok); |
| 886 ExpressionT ParseYieldExpression(bool accept_IN, | 948 ExpressionT ParseYieldExpression(bool accept_IN, |
| 887 ExpressionClassifier* classifier, bool* ok); | 949 ExpressionClassifier* classifier, bool* ok); |
| 888 ExpressionT ParseTailCallExpression(ExpressionClassifier* classifier, | 950 ExpressionT ParseTailCallExpression(ExpressionClassifier* classifier, |
| 889 bool* ok); | 951 bool* ok); |
| 890 ExpressionT ParseConditionalExpression(bool accept_IN, | 952 ExpressionT ParseConditionalExpression(bool accept_IN, |
| 891 ExpressionClassifier* classifier, | 953 ExpressionClassifier* classifier, |
| 892 bool* ok); | 954 bool* ok); |
| 893 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 955 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
| 894 ExpressionClassifier* classifier, bool* ok); | 956 ExpressionClassifier* classifier, bool* ok); |
| 895 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 957 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
| 896 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 958 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
| 897 bool* ok); | 959 bool* ok); |
| 898 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 960 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
| 899 bool* ok); | 961 bool* ok); |
| 900 ExpressionT ParseMemberWithNewPrefixesExpression( | 962 ExpressionT ParseMemberWithNewPrefixesExpression( |
| 901 ExpressionClassifier* classifier, bool* ok); | 963 ExpressionClassifier* classifier, bool* is_async, bool* ok); |
| 902 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 964 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, |
| 965 bool* is_async, bool* ok); |
| 903 ExpressionT ParseMemberExpressionContinuation( | 966 ExpressionT ParseMemberExpressionContinuation( |
| 904 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 967 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
| 968 bool* ok); |
| 905 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, | 969 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, |
| 906 const FormalParametersT& parameters, | 970 const FormalParametersT& parameters, |
| 971 bool is_async, |
| 907 const ExpressionClassifier& classifier, | 972 const ExpressionClassifier& classifier, |
| 908 bool* ok); | 973 bool* ok); |
| 909 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 974 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
| 910 ExpressionClassifier* classifier, bool* ok); | 975 ExpressionClassifier* classifier, bool* ok); |
| 911 void AddTemplateExpression(ExpressionT); | 976 void AddTemplateExpression(ExpressionT); |
| 912 ExpressionT ParseSuperExpression(bool is_new, | 977 ExpressionT ParseSuperExpression(bool is_new, |
| 913 ExpressionClassifier* classifier, bool* ok); | 978 ExpressionClassifier* classifier, bool* ok); |
| 914 ExpressionT ParseNewTargetExpression(bool* ok); | 979 ExpressionT ParseNewTargetExpression(bool* ok); |
| 915 | 980 |
| 916 void ParseFormalParameter(FormalParametersT* parameters, | 981 void ParseFormalParameter(FormalParametersT* parameters, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 kAccessorProperty, | 1033 kAccessorProperty, |
| 969 kValueProperty, | 1034 kValueProperty, |
| 970 kMethodProperty | 1035 kMethodProperty |
| 971 }; | 1036 }; |
| 972 | 1037 |
| 973 class ObjectLiteralCheckerBase { | 1038 class ObjectLiteralCheckerBase { |
| 974 public: | 1039 public: |
| 975 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} | 1040 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} |
| 976 | 1041 |
| 977 virtual void CheckProperty(Token::Value property, PropertyKind type, | 1042 virtual void CheckProperty(Token::Value property, PropertyKind type, |
| 978 bool is_static, bool is_generator, bool* ok) = 0; | 1043 MethodKind method_type, bool* ok) = 0; |
| 979 | 1044 |
| 980 virtual ~ObjectLiteralCheckerBase() {} | 1045 virtual ~ObjectLiteralCheckerBase() {} |
| 981 | 1046 |
| 982 protected: | 1047 protected: |
| 983 ParserBase* parser() const { return parser_; } | 1048 ParserBase* parser() const { return parser_; } |
| 984 Scanner* scanner() const { return parser_->scanner(); } | 1049 Scanner* scanner() const { return parser_->scanner(); } |
| 985 | 1050 |
| 986 private: | 1051 private: |
| 987 ParserBase* parser_; | 1052 ParserBase* parser_; |
| 988 }; | 1053 }; |
| 989 | 1054 |
| 990 // Validation per ES6 object literals. | 1055 // Validation per ES6 object literals. |
| 991 class ObjectLiteralChecker : public ObjectLiteralCheckerBase { | 1056 class ObjectLiteralChecker : public ObjectLiteralCheckerBase { |
| 992 public: | 1057 public: |
| 993 explicit ObjectLiteralChecker(ParserBase* parser) | 1058 explicit ObjectLiteralChecker(ParserBase* parser) |
| 994 : ObjectLiteralCheckerBase(parser), has_seen_proto_(false) {} | 1059 : ObjectLiteralCheckerBase(parser), has_seen_proto_(false) {} |
| 995 | 1060 |
| 996 void CheckProperty(Token::Value property, PropertyKind type, bool is_static, | 1061 void CheckProperty(Token::Value property, PropertyKind type, |
| 997 bool is_generator, bool* ok) override; | 1062 MethodKind method_type, bool* ok) override; |
| 998 | 1063 |
| 999 private: | 1064 private: |
| 1000 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } | 1065 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } |
| 1001 | 1066 |
| 1002 bool has_seen_proto_; | 1067 bool has_seen_proto_; |
| 1003 }; | 1068 }; |
| 1004 | 1069 |
| 1005 // Validation per ES6 class literals. | 1070 // Validation per ES6 class literals. |
| 1006 class ClassLiteralChecker : public ObjectLiteralCheckerBase { | 1071 class ClassLiteralChecker : public ObjectLiteralCheckerBase { |
| 1007 public: | 1072 public: |
| 1008 explicit ClassLiteralChecker(ParserBase* parser) | 1073 explicit ClassLiteralChecker(ParserBase* parser) |
| 1009 : ObjectLiteralCheckerBase(parser), has_seen_constructor_(false) {} | 1074 : ObjectLiteralCheckerBase(parser), has_seen_constructor_(false) {} |
| 1010 | 1075 |
| 1011 void CheckProperty(Token::Value property, PropertyKind type, bool is_static, | 1076 void CheckProperty(Token::Value property, PropertyKind type, |
| 1012 bool is_generator, bool* ok) override; | 1077 MethodKind method_type, bool* ok) override; |
| 1013 | 1078 |
| 1014 private: | 1079 private: |
| 1015 bool IsConstructor() { | 1080 bool IsConstructor() { |
| 1016 return this->scanner()->LiteralMatches("constructor", 11); | 1081 return this->scanner()->LiteralMatches("constructor", 11); |
| 1017 } | 1082 } |
| 1018 bool IsPrototype() { | 1083 bool IsPrototype() { |
| 1019 return this->scanner()->LiteralMatches("prototype", 9); | 1084 return this->scanner()->LiteralMatches("prototype", 9); |
| 1020 } | 1085 } |
| 1021 | 1086 |
| 1022 bool has_seen_constructor_; | 1087 bool has_seen_constructor_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1039 bool stack_overflow_; | 1104 bool stack_overflow_; |
| 1040 | 1105 |
| 1041 bool allow_lazy_; | 1106 bool allow_lazy_; |
| 1042 bool allow_natives_; | 1107 bool allow_natives_; |
| 1043 bool allow_tailcalls_; | 1108 bool allow_tailcalls_; |
| 1044 bool allow_harmony_restrictive_declarations_; | 1109 bool allow_harmony_restrictive_declarations_; |
| 1045 bool allow_harmony_do_expressions_; | 1110 bool allow_harmony_do_expressions_; |
| 1046 bool allow_harmony_for_in_; | 1111 bool allow_harmony_for_in_; |
| 1047 bool allow_harmony_function_name_; | 1112 bool allow_harmony_function_name_; |
| 1048 bool allow_harmony_function_sent_; | 1113 bool allow_harmony_function_sent_; |
| 1114 bool allow_harmony_async_await_; |
| 1049 }; | 1115 }; |
| 1050 | 1116 |
| 1051 template <class Traits> | 1117 template <class Traits> |
| 1052 ParserBase<Traits>::FunctionState::FunctionState( | 1118 ParserBase<Traits>::FunctionState::FunctionState( |
| 1053 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1119 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
| 1054 FunctionKind kind, typename Traits::Type::Factory* factory) | 1120 FunctionKind kind, typename Traits::Type::Factory* factory) |
| 1055 : next_materialized_literal_index_(0), | 1121 : next_materialized_literal_index_(0), |
| 1056 expected_property_count_(0), | 1122 expected_property_count_(0), |
| 1057 this_location_(Scanner::Location::invalid()), | 1123 this_location_(Scanner::Location::invalid()), |
| 1058 return_location_(Scanner::Location::invalid()), | 1124 return_location_(Scanner::Location::invalid()), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 } | 1265 } |
| 1200 if (this->IsArguments(name)) { | 1266 if (this->IsArguments(name)) { |
| 1201 scope_->RecordArgumentsUsage(); | 1267 scope_->RecordArgumentsUsage(); |
| 1202 classifier->RecordStrictModeFormalParameterError( | 1268 classifier->RecordStrictModeFormalParameterError( |
| 1203 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1269 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
| 1204 if (is_strict(language_mode())) { | 1270 if (is_strict(language_mode())) { |
| 1205 classifier->RecordBindingPatternError( | 1271 classifier->RecordBindingPatternError( |
| 1206 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1272 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
| 1207 } | 1273 } |
| 1208 } | 1274 } |
| 1275 if (this->IsAwait(name)) { |
| 1276 if (is_async_function()) { |
| 1277 classifier->RecordPatternError( |
| 1278 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); |
| 1279 } |
| 1280 classifier->RecordAsyncArrowFormalParametersError( |
| 1281 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); |
| 1282 } |
| 1209 | 1283 |
| 1210 if (classifier->duplicate_finder() != nullptr && | 1284 if (classifier->duplicate_finder() != nullptr && |
| 1211 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1285 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
| 1212 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1286 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
| 1213 } | 1287 } |
| 1214 return name; | 1288 return name; |
| 1215 } else if (is_sloppy(language_mode()) && | 1289 } else if (is_sloppy(language_mode()) && |
| 1216 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1290 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
| 1217 next == Token::ESCAPED_STRICT_RESERVED_WORD || | 1291 next == Token::ESCAPED_STRICT_RESERVED_WORD || |
| 1218 next == Token::LET || next == Token::STATIC || | 1292 next == Token::LET || next == Token::STATIC || |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 #define DUMMY ) // to make indentation work | 1388 #define DUMMY ) // to make indentation work |
| 1315 #undef DUMMY | 1389 #undef DUMMY |
| 1316 | 1390 |
| 1317 // Used in functions where the return type is not ExpressionT. | 1391 // Used in functions where the return type is not ExpressionT. |
| 1318 #define CHECK_OK_CUSTOM(x) ok); \ | 1392 #define CHECK_OK_CUSTOM(x) ok); \ |
| 1319 if (!*ok) return this->x(); \ | 1393 if (!*ok) return this->x(); \ |
| 1320 ((void)0 | 1394 ((void)0 |
| 1321 #define DUMMY ) // to make indentation work | 1395 #define DUMMY ) // to make indentation work |
| 1322 #undef DUMMY | 1396 #undef DUMMY |
| 1323 | 1397 |
| 1324 | |
| 1325 template <class Traits> | 1398 template <class Traits> |
| 1326 typename ParserBase<Traits>::ExpressionT | 1399 typename ParserBase<Traits>::ExpressionT |
| 1327 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, | 1400 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| 1328 bool* ok) { | 1401 bool* is_async, bool* ok) { |
| 1329 // PrimaryExpression :: | 1402 // PrimaryExpression :: |
| 1330 // 'this' | 1403 // 'this' |
| 1331 // 'null' | 1404 // 'null' |
| 1332 // 'true' | 1405 // 'true' |
| 1333 // 'false' | 1406 // 'false' |
| 1334 // Identifier | 1407 // Identifier |
| 1335 // Number | 1408 // Number |
| 1336 // String | 1409 // String |
| 1337 // ArrayLiteral | 1410 // ArrayLiteral |
| 1338 // ObjectLiteral | 1411 // ObjectLiteral |
| 1339 // RegExpLiteral | 1412 // RegExpLiteral |
| 1340 // ClassLiteral | 1413 // ClassLiteral |
| 1341 // '(' Expression ')' | 1414 // '(' Expression ')' |
| 1342 // TemplateLiteral | 1415 // TemplateLiteral |
| 1343 // do Block | 1416 // do Block |
| 1417 // AsyncFunctionExpression |
| 1344 | 1418 |
| 1345 int beg_pos = peek_position(); | 1419 int beg_pos = peek_position(); |
| 1346 switch (peek()) { | 1420 switch (peek()) { |
| 1347 case Token::THIS: { | 1421 case Token::THIS: { |
| 1348 BindingPatternUnexpectedToken(classifier); | 1422 BindingPatternUnexpectedToken(classifier); |
| 1349 Consume(Token::THIS); | 1423 Consume(Token::THIS); |
| 1350 return this->ThisExpression(scope_, factory(), beg_pos); | 1424 return this->ThisExpression(scope_, factory(), beg_pos); |
| 1351 } | 1425 } |
| 1352 | 1426 |
| 1353 case Token::NULL_LITERAL: | 1427 case Token::NULL_LITERAL: |
| 1354 case Token::TRUE_LITERAL: | 1428 case Token::TRUE_LITERAL: |
| 1355 case Token::FALSE_LITERAL: | 1429 case Token::FALSE_LITERAL: |
| 1356 BindingPatternUnexpectedToken(classifier); | 1430 BindingPatternUnexpectedToken(classifier); |
| 1357 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); | 1431 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); |
| 1358 case Token::SMI: | 1432 case Token::SMI: |
| 1359 case Token::NUMBER: | 1433 case Token::NUMBER: |
| 1360 BindingPatternUnexpectedToken(classifier); | 1434 BindingPatternUnexpectedToken(classifier); |
| 1361 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); | 1435 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); |
| 1362 | 1436 |
| 1363 case Token::IDENTIFIER: | 1437 case Token::IDENTIFIER: |
| 1438 if (allow_harmony_async_await() && |
| 1439 PeekContextualKeyword(CStrVector("async")) && |
| 1440 !scanner()->HasAnyLineTerminatorAfterNext()) { |
| 1441 if (PeekAhead() == Token::FUNCTION) { |
| 1442 Consume(Token::IDENTIFIER); |
| 1443 return this->ParseAsyncFunctionExpression(CHECK_OK); |
| 1444 } |
| 1445 // CoverCallExpressionAndAsyncArrowHead |
| 1446 *is_async = true; |
| 1447 } |
| 1448 /* Falls through */ |
| 1364 case Token::LET: | 1449 case Token::LET: |
| 1365 case Token::STATIC: | 1450 case Token::STATIC: |
| 1366 case Token::YIELD: | 1451 case Token::YIELD: |
| 1367 case Token::AWAIT: | 1452 case Token::AWAIT: |
| 1368 case Token::ESCAPED_STRICT_RESERVED_WORD: | 1453 case Token::ESCAPED_STRICT_RESERVED_WORD: |
| 1369 case Token::FUTURE_STRICT_RESERVED_WORD: { | 1454 case Token::FUTURE_STRICT_RESERVED_WORD: { |
| 1370 // Using eval or arguments in this context is OK even in strict mode. | 1455 // Using eval or arguments in this context is OK even in strict mode. |
| 1371 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); | 1456 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); |
| 1372 return this->ExpressionFromIdentifier( | 1457 return this->ExpressionFromIdentifier( |
| 1373 name, beg_pos, scanner()->location().end_pos, scope_, factory()); | 1458 name, beg_pos, scanner()->location().end_pos, scope_, factory()); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 | 1709 |
| 1625 ExpressionT result = factory()->NewArrayLiteral(values, first_spread_index, | 1710 ExpressionT result = factory()->NewArrayLiteral(values, first_spread_index, |
| 1626 literal_index, pos); | 1711 literal_index, pos); |
| 1627 if (first_spread_index >= 0) { | 1712 if (first_spread_index >= 0) { |
| 1628 result = factory()->NewRewritableExpression(result); | 1713 result = factory()->NewRewritableExpression(result); |
| 1629 Traits::QueueNonPatternForRewriting(result); | 1714 Traits::QueueNonPatternForRewriting(result); |
| 1630 } | 1715 } |
| 1631 return result; | 1716 return result; |
| 1632 } | 1717 } |
| 1633 | 1718 |
| 1634 | |
| 1635 template <class Traits> | 1719 template <class Traits> |
| 1636 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( | 1720 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
| 1637 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name, | 1721 IdentifierT* name, bool* is_get, bool* is_set, bool* is_await, |
| 1638 ExpressionClassifier* classifier, bool* ok) { | 1722 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { |
| 1639 Token::Value token = peek(); | 1723 Token::Value token = peek(); |
| 1640 int pos = peek_position(); | 1724 int pos = peek_position(); |
| 1641 | 1725 |
| 1642 // For non computed property names we normalize the name a bit: | 1726 // For non computed property names we normalize the name a bit: |
| 1643 // | 1727 // |
| 1644 // "12" -> 12 | 1728 // "12" -> 12 |
| 1645 // 12.3 -> "12.3" | 1729 // 12.3 -> "12.3" |
| 1646 // 12.30 -> "12.3" | 1730 // 12.30 -> "12.3" |
| 1647 // identifier -> "identifier" | 1731 // identifier -> "identifier" |
| 1648 // | 1732 // |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1673 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); | 1757 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); |
| 1674 classifier->Accumulate(&computed_name_classifier, | 1758 classifier->Accumulate(&computed_name_classifier, |
| 1675 ExpressionClassifier::ExpressionProductions); | 1759 ExpressionClassifier::ExpressionProductions); |
| 1676 Expect(Token::RBRACK, CHECK_OK); | 1760 Expect(Token::RBRACK, CHECK_OK); |
| 1677 return expression; | 1761 return expression; |
| 1678 } | 1762 } |
| 1679 | 1763 |
| 1680 default: | 1764 default: |
| 1681 *name = ParseIdentifierName(CHECK_OK); | 1765 *name = ParseIdentifierName(CHECK_OK); |
| 1682 scanner()->IsGetOrSet(is_get, is_set); | 1766 scanner()->IsGetOrSet(is_get, is_set); |
| 1767 if (this->IsAwait(*name)) { |
| 1768 *is_await = true; |
| 1769 } |
| 1683 break; | 1770 break; |
| 1684 } | 1771 } |
| 1685 | 1772 |
| 1686 uint32_t index; | 1773 uint32_t index; |
| 1687 return this->IsArrayIndex(*name, &index) | 1774 return this->IsArrayIndex(*name, &index) |
| 1688 ? factory()->NewNumberLiteral(index, pos) | 1775 ? factory()->NewNumberLiteral(index, pos) |
| 1689 : factory()->NewStringLiteral(*name, pos); | 1776 : factory()->NewStringLiteral(*name, pos); |
| 1690 } | 1777 } |
| 1691 | 1778 |
| 1692 | |
| 1693 template <class Traits> | 1779 template <class Traits> |
| 1694 typename ParserBase<Traits>::ObjectLiteralPropertyT | 1780 typename ParserBase<Traits>::ObjectLiteralPropertyT |
| 1695 ParserBase<Traits>::ParsePropertyDefinition( | 1781 ParserBase<Traits>::ParsePropertyDefinition( |
| 1696 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1782 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 1697 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 1783 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, |
| 1698 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { | 1784 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { |
| 1699 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); | 1785 DCHECK(!in_class || IsStaticMethod(method_kind) || |
| 1786 has_seen_constructor != nullptr); |
| 1700 ExpressionT value = this->EmptyExpression(); | 1787 ExpressionT value = this->EmptyExpression(); |
| 1701 bool is_get = false; | 1788 bool is_get = false; |
| 1702 bool is_set = false; | 1789 bool is_set = false; |
| 1790 bool is_await = false; |
| 1703 bool is_generator = Check(Token::MUL); | 1791 bool is_generator = Check(Token::MUL); |
| 1792 bool is_async = false; |
| 1704 | 1793 |
| 1705 Token::Value name_token = peek(); | 1794 Token::Value name_token = peek(); |
| 1795 |
| 1796 if (is_generator) { |
| 1797 method_kind |= MethodKind::Generator; |
| 1798 } else if (allow_harmony_async_await() && |
| 1799 PeekContextualKeyword(CStrVector("async")) && |
| 1800 !scanner()->HasAnyLineTerminatorAfterNext() && |
| 1801 PeekAhead() != Token::LPAREN) { |
| 1802 method_kind |= MethodKind::Async; |
| 1803 is_async = true; |
| 1804 } |
| 1805 |
| 1706 int next_beg_pos = scanner()->peek_location().beg_pos; | 1806 int next_beg_pos = scanner()->peek_location().beg_pos; |
| 1707 int next_end_pos = scanner()->peek_location().end_pos; | 1807 int next_end_pos = scanner()->peek_location().end_pos; |
| 1708 ExpressionT name_expression = | 1808 ExpressionT name_expression = ParsePropertyName( |
| 1709 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier, | 1809 name, &is_get, &is_set, &is_await, is_computed_name, classifier, |
| 1710 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1810 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1711 | 1811 |
| 1712 if (fni_ != nullptr && !*is_computed_name) { | 1812 if (fni_ != nullptr && !*is_computed_name) { |
| 1713 this->PushLiteralName(fni_, *name); | 1813 this->PushLiteralName(fni_, *name); |
| 1714 } | 1814 } |
| 1715 | 1815 |
| 1716 if (!in_class && !is_generator) { | 1816 if (!in_class && !is_generator) { |
| 1717 DCHECK(!is_static); | 1817 DCHECK(!IsStaticMethod(method_kind)); |
| 1718 | 1818 |
| 1719 if (peek() == Token::COLON) { | 1819 if (peek() == Token::COLON) { |
| 1720 // PropertyDefinition | 1820 // PropertyDefinition |
| 1721 // PropertyName ':' AssignmentExpression | 1821 // PropertyName ':' AssignmentExpression |
| 1722 if (!*is_computed_name) { | 1822 if (!*is_computed_name) { |
| 1723 checker->CheckProperty(name_token, kValueProperty, false, false, | 1823 checker->CheckProperty(name_token, kValueProperty, MethodKind::None, |
| 1724 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1824 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1725 } | 1825 } |
| 1726 Consume(Token::COLON); | 1826 Consume(Token::COLON); |
| 1727 int beg_pos = peek_position(); | 1827 int beg_pos = peek_position(); |
| 1728 value = this->ParseAssignmentExpression( | 1828 value = this->ParseAssignmentExpression( |
| 1729 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1829 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1730 CheckDestructuringElement(value, classifier, beg_pos, | 1830 CheckDestructuringElement(value, classifier, beg_pos, |
| 1731 scanner()->location().end_pos); | 1831 scanner()->location().end_pos); |
| 1732 | 1832 |
| 1733 return factory()->NewObjectLiteralProperty(name_expression, value, false, | 1833 return factory()->NewObjectLiteralProperty( |
| 1734 *is_computed_name); | 1834 name_expression, value, MethodKind::None, *is_computed_name); |
| 1735 } | 1835 } |
| 1736 | 1836 |
| 1737 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), | 1837 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), |
| 1738 parsing_module_) && | 1838 parsing_module_) && |
| 1739 (peek() == Token::COMMA || peek() == Token::RBRACE || | 1839 (peek() == Token::COMMA || peek() == Token::RBRACE || |
| 1740 peek() == Token::ASSIGN)) { | 1840 peek() == Token::ASSIGN)) { |
| 1741 // PropertyDefinition | 1841 // PropertyDefinition |
| 1742 // IdentifierReference | 1842 // IdentifierReference |
| 1743 // CoverInitializedName | 1843 // CoverInitializedName |
| 1744 // | 1844 // |
| 1745 // CoverInitializedName | 1845 // CoverInitializedName |
| 1746 // IdentifierReference Initializer? | 1846 // IdentifierReference Initializer? |
| 1747 if (classifier->duplicate_finder() != nullptr && | 1847 if (classifier->duplicate_finder() != nullptr && |
| 1748 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1848 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
| 1749 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1849 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
| 1750 } | 1850 } |
| 1751 if (name_token == Token::LET) { | 1851 if (name_token == Token::LET) { |
| 1752 classifier->RecordLetPatternError( | 1852 classifier->RecordLetPatternError( |
| 1753 scanner()->location(), MessageTemplate::kLetInLexicalBinding); | 1853 scanner()->location(), MessageTemplate::kLetInLexicalBinding); |
| 1754 } | 1854 } |
| 1755 | 1855 if (is_await && is_async_function()) { |
| 1856 classifier->RecordPatternError( |
| 1857 Scanner::Location(next_beg_pos, next_end_pos), |
| 1858 MessageTemplate::kAwaitBindingIdentifier); |
| 1859 } |
| 1756 ExpressionT lhs = this->ExpressionFromIdentifier( | 1860 ExpressionT lhs = this->ExpressionFromIdentifier( |
| 1757 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1861 *name, next_beg_pos, next_end_pos, scope_, factory()); |
| 1758 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1862 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
| 1759 | 1863 |
| 1760 if (peek() == Token::ASSIGN) { | 1864 if (peek() == Token::ASSIGN) { |
| 1761 Consume(Token::ASSIGN); | 1865 Consume(Token::ASSIGN); |
| 1762 ExpressionClassifier rhs_classifier(this); | 1866 ExpressionClassifier rhs_classifier(this); |
| 1763 ExpressionT rhs = this->ParseAssignmentExpression( | 1867 ExpressionT rhs = this->ParseAssignmentExpression( |
| 1764 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1868 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1765 Traits::RewriteNonPattern(&rhs_classifier, | 1869 Traits::RewriteNonPattern(&rhs_classifier, |
| 1766 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1870 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1767 classifier->Accumulate(&rhs_classifier, | 1871 classifier->Accumulate(&rhs_classifier, |
| 1768 ExpressionClassifier::ExpressionProductions); | 1872 ExpressionClassifier::ExpressionProductions); |
| 1769 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1873 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
| 1770 RelocInfo::kNoPosition); | 1874 RelocInfo::kNoPosition); |
| 1771 classifier->RecordCoverInitializedNameError( | 1875 classifier->RecordCoverInitializedNameError( |
| 1772 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1876 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 1773 MessageTemplate::kInvalidCoverInitializedName); | 1877 MessageTemplate::kInvalidCoverInitializedName); |
| 1774 | 1878 |
| 1775 if (allow_harmony_function_name()) { | 1879 if (allow_harmony_function_name()) { |
| 1776 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); | 1880 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); |
| 1777 } | 1881 } |
| 1778 } else { | 1882 } else { |
| 1779 value = lhs; | 1883 value = lhs; |
| 1780 } | 1884 } |
| 1781 | 1885 |
| 1782 return factory()->NewObjectLiteralProperty( | 1886 return factory()->NewObjectLiteralProperty( |
| 1783 name_expression, value, ObjectLiteralProperty::COMPUTED, false, | 1887 name_expression, value, ObjectLiteralProperty::COMPUTED, |
| 1784 false); | 1888 MethodKind::None, false); |
| 1785 } | 1889 } |
| 1786 } | 1890 } |
| 1787 | 1891 |
| 1788 // Method definitions are never valid in patterns. | 1892 // Method definitions are never valid in patterns. |
| 1789 classifier->RecordPatternError( | 1893 classifier->RecordPatternError( |
| 1790 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1894 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 1791 MessageTemplate::kInvalidDestructuringTarget); | 1895 MessageTemplate::kInvalidDestructuringTarget); |
| 1792 | 1896 |
| 1897 if (IsAsyncMethod(method_kind)) { |
| 1898 DCHECK(!IsGeneratorMethod(method_kind)); |
| 1899 DCHECK(!is_get); |
| 1900 DCHECK(!is_set); |
| 1901 bool dont_care; |
| 1902 name_expression = ParsePropertyName( |
| 1903 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
| 1904 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1905 } |
| 1906 |
| 1793 if (is_generator || peek() == Token::LPAREN) { | 1907 if (is_generator || peek() == Token::LPAREN) { |
| 1794 // MethodDefinition | 1908 // MethodDefinition |
| 1795 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 1909 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
| 1796 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 1910 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
| 1797 if (!*is_computed_name) { | 1911 if (!*is_computed_name) { |
| 1798 checker->CheckProperty(name_token, kMethodProperty, is_static, | 1912 checker->CheckProperty(name_token, kMethodProperty, method_kind, |
| 1799 is_generator, | |
| 1800 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1913 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1801 } | 1914 } |
| 1802 | 1915 |
| 1803 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 1916 FunctionKind kind = is_generator |
| 1804 : FunctionKind::kConciseMethod; | 1917 ? FunctionKind::kConciseGeneratorMethod |
| 1918 : is_async ? FunctionKind::kAsyncConciseMethod |
| 1919 : FunctionKind::kConciseMethod; |
| 1805 | 1920 |
| 1806 if (in_class && !is_static && this->IsConstructor(*name)) { | 1921 if (in_class && !IsStaticMethod(method_kind) && |
| 1922 this->IsConstructor(*name)) { |
| 1807 *has_seen_constructor = true; | 1923 *has_seen_constructor = true; |
| 1808 kind = has_extends ? FunctionKind::kSubclassConstructor | 1924 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 1809 : FunctionKind::kBaseConstructor; | 1925 : FunctionKind::kBaseConstructor; |
| 1810 } | 1926 } |
| 1811 | 1927 |
| 1812 value = this->ParseFunctionLiteral( | 1928 value = this->ParseFunctionLiteral( |
| 1813 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 1929 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 1814 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, | 1930 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, |
| 1815 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1931 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1816 | 1932 |
| 1817 return factory()->NewObjectLiteralProperty(name_expression, value, | 1933 return factory()->NewObjectLiteralProperty(name_expression, value, |
| 1818 ObjectLiteralProperty::COMPUTED, | 1934 ObjectLiteralProperty::COMPUTED, |
| 1819 is_static, *is_computed_name); | 1935 method_kind, *is_computed_name); |
| 1820 } | 1936 } |
| 1821 | 1937 |
| 1822 if (in_class && name_token == Token::STATIC && !is_static) { | 1938 if (in_class && name_token == Token::STATIC && !IsMethod(method_kind)) { |
| 1823 // ClassElement (static) | 1939 // ClassElement (static) |
| 1824 // 'static' MethodDefinition | 1940 // 'static' MethodDefinition |
| 1825 *name = this->EmptyIdentifier(); | 1941 *name = this->EmptyIdentifier(); |
| 1826 ObjectLiteralPropertyT property = ParsePropertyDefinition( | 1942 ObjectLiteralPropertyT property = ParsePropertyDefinition( |
| 1827 checker, true, has_extends, true, is_computed_name, nullptr, classifier, | 1943 checker, true, has_extends, MethodKind::Static, is_computed_name, |
| 1828 name, ok); | 1944 nullptr, classifier, name, ok); |
| 1829 Traits::RewriteNonPattern(classifier, ok); | 1945 Traits::RewriteNonPattern(classifier, ok); |
| 1830 return property; | 1946 return property; |
| 1831 } | 1947 } |
| 1832 | 1948 |
| 1833 if (is_get || is_set) { | 1949 if (is_get || is_set) { |
| 1834 // MethodDefinition (Accessors) | 1950 // MethodDefinition (Accessors) |
| 1835 // get PropertyName '(' ')' '{' FunctionBody '}' | 1951 // get PropertyName '(' ')' '{' FunctionBody '}' |
| 1836 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 1952 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
| 1837 *name = this->EmptyIdentifier(); | 1953 *name = this->EmptyIdentifier(); |
| 1838 bool dont_care = false; | 1954 bool dont_care = false; |
| 1839 name_token = peek(); | 1955 name_token = peek(); |
| 1840 | 1956 |
| 1841 name_expression = ParsePropertyName( | 1957 name_expression = ParsePropertyName( |
| 1842 name, &dont_care, &dont_care, is_computed_name, classifier, | 1958 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
| 1843 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1959 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1844 | 1960 |
| 1845 if (!*is_computed_name) { | 1961 if (!*is_computed_name) { |
| 1846 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 1962 checker->CheckProperty(name_token, kAccessorProperty, method_kind, |
| 1847 is_generator, | |
| 1848 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1963 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1849 } | 1964 } |
| 1850 | 1965 |
| 1851 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 1966 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
| 1852 *name, scanner()->location(), kSkipFunctionNameCheck, | 1967 *name, scanner()->location(), kSkipFunctionNameCheck, |
| 1853 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, | 1968 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, |
| 1854 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, | 1969 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, |
| 1855 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1970 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1856 | 1971 |
| 1857 // Make sure the name expression is a string since we need a Name for | 1972 // Make sure the name expression is a string since we need a Name for |
| 1858 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this | 1973 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this |
| 1859 // statically we can skip the extra runtime check. | 1974 // statically we can skip the extra runtime check. |
| 1860 if (!*is_computed_name) { | 1975 if (!*is_computed_name) { |
| 1861 name_expression = | 1976 name_expression = |
| 1862 factory()->NewStringLiteral(*name, name_expression->position()); | 1977 factory()->NewStringLiteral(*name, name_expression->position()); |
| 1863 } | 1978 } |
| 1864 | 1979 |
| 1865 return factory()->NewObjectLiteralProperty( | 1980 return factory()->NewObjectLiteralProperty( |
| 1866 name_expression, value, | 1981 name_expression, value, |
| 1867 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 1982 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
| 1868 is_static, *is_computed_name); | 1983 method_kind, *is_computed_name); |
| 1869 } | 1984 } |
| 1870 | 1985 |
| 1871 Token::Value next = Next(); | 1986 Token::Value next = Next(); |
| 1872 ReportUnexpectedToken(next); | 1987 ReportUnexpectedToken(next); |
| 1873 *ok = false; | 1988 *ok = false; |
| 1874 return this->EmptyObjectLiteralProperty(); | 1989 return this->EmptyObjectLiteralProperty(); |
| 1875 } | 1990 } |
| 1876 | 1991 |
| 1877 | 1992 |
| 1878 template <class Traits> | 1993 template <class Traits> |
| 1879 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 1994 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
| 1880 ExpressionClassifier* classifier, bool* ok) { | 1995 ExpressionClassifier* classifier, bool* ok) { |
| 1881 // ObjectLiteral :: | 1996 // ObjectLiteral :: |
| 1882 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 1997 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
| 1883 | 1998 |
| 1884 int pos = peek_position(); | 1999 int pos = peek_position(); |
| 1885 typename Traits::Type::PropertyList properties = | 2000 typename Traits::Type::PropertyList properties = |
| 1886 this->NewPropertyList(4, zone_); | 2001 this->NewPropertyList(4, zone_); |
| 1887 int number_of_boilerplate_properties = 0; | 2002 int number_of_boilerplate_properties = 0; |
| 1888 bool has_computed_names = false; | 2003 bool has_computed_names = false; |
| 1889 ObjectLiteralChecker checker(this); | 2004 ObjectLiteralChecker checker(this); |
| 1890 | 2005 |
| 1891 Expect(Token::LBRACE, CHECK_OK); | 2006 Expect(Token::LBRACE, CHECK_OK); |
| 1892 | 2007 |
| 1893 while (peek() != Token::RBRACE) { | 2008 while (peek() != Token::RBRACE) { |
| 1894 FuncNameInferrer::State fni_state(fni_); | 2009 FuncNameInferrer::State fni_state(fni_); |
| 1895 | 2010 |
| 1896 const bool in_class = false; | 2011 const bool in_class = false; |
| 1897 const bool is_static = false; | |
| 1898 const bool has_extends = false; | 2012 const bool has_extends = false; |
| 1899 bool is_computed_name = false; | 2013 bool is_computed_name = false; |
| 1900 IdentifierT name = this->EmptyIdentifier(); | 2014 IdentifierT name = this->EmptyIdentifier(); |
| 1901 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 2015 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
| 1902 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, | 2016 &checker, in_class, has_extends, MethodKind::None, &is_computed_name, |
| 1903 classifier, &name, CHECK_OK); | 2017 NULL, classifier, &name, CHECK_OK); |
| 1904 | 2018 |
| 1905 if (is_computed_name) { | 2019 if (is_computed_name) { |
| 1906 has_computed_names = true; | 2020 has_computed_names = true; |
| 1907 } | 2021 } |
| 1908 | 2022 |
| 1909 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 2023 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
| 1910 if (!has_computed_names && this->IsBoilerplateProperty(property)) { | 2024 if (!has_computed_names && this->IsBoilerplateProperty(property)) { |
| 1911 number_of_boilerplate_properties++; | 2025 number_of_boilerplate_properties++; |
| 1912 } | 2026 } |
| 1913 properties->Add(property, zone()); | 2027 properties->Add(property, zone()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1927 | 2041 |
| 1928 // Computation of literal_index must happen before pre parse bailout. | 2042 // Computation of literal_index must happen before pre parse bailout. |
| 1929 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2043 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
| 1930 | 2044 |
| 1931 return factory()->NewObjectLiteral(properties, | 2045 return factory()->NewObjectLiteral(properties, |
| 1932 literal_index, | 2046 literal_index, |
| 1933 number_of_boilerplate_properties, | 2047 number_of_boilerplate_properties, |
| 1934 pos); | 2048 pos); |
| 1935 } | 2049 } |
| 1936 | 2050 |
| 1937 | |
| 1938 template <class Traits> | 2051 template <class Traits> |
| 1939 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2052 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
| 1940 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier, | 2053 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, |
| 1941 bool* ok) { | 2054 ExpressionClassifier* classifier, bool* ok) { |
| 1942 // Arguments :: | 2055 // Arguments :: |
| 1943 // '(' (AssignmentExpression)*[','] ')' | 2056 // '(' (AssignmentExpression)*[','] ')' |
| 1944 | 2057 |
| 1945 Scanner::Location spread_arg = Scanner::Location::invalid(); | 2058 Scanner::Location spread_arg = Scanner::Location::invalid(); |
| 1946 typename Traits::Type::ExpressionList result = | 2059 typename Traits::Type::ExpressionList result = |
| 1947 this->NewExpressionList(4, zone_); | 2060 this->NewExpressionList(4, zone_); |
| 1948 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2061 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
| 1949 bool done = (peek() == Token::RPAREN); | 2062 bool done = (peek() == Token::RPAREN); |
| 1950 bool was_unspread = false; | 2063 bool was_unspread = false; |
| 1951 int unspread_sequences_count = 0; | 2064 int unspread_sequences_count = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 } | 2100 } |
| 1988 } | 2101 } |
| 1989 Scanner::Location location = scanner_->location(); | 2102 Scanner::Location location = scanner_->location(); |
| 1990 if (Token::RPAREN != Next()) { | 2103 if (Token::RPAREN != Next()) { |
| 1991 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); | 2104 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); |
| 1992 *ok = false; | 2105 *ok = false; |
| 1993 return this->NullExpressionList(); | 2106 return this->NullExpressionList(); |
| 1994 } | 2107 } |
| 1995 *first_spread_arg_loc = spread_arg; | 2108 *first_spread_arg_loc = spread_arg; |
| 1996 | 2109 |
| 1997 if (spread_arg.IsValid()) { | 2110 if ((!maybe_arrow || peek() != Token::ARROW) && spread_arg.IsValid()) { |
| 1998 // Unspread parameter sequences are translated into array literals in the | 2111 // Unspread parameter sequences are translated into array literals in the |
| 1999 // parser. Ensure that the number of materialized literals matches between | 2112 // parser. Ensure that the number of materialized literals matches between |
| 2000 // the parser and preparser | 2113 // the parser and preparser |
| 2001 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); | 2114 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
| 2002 } | 2115 } |
| 2003 | 2116 |
| 2004 return result; | 2117 return result; |
| 2005 } | 2118 } |
| 2006 | 2119 |
| 2007 // Precedence = 2 | 2120 // Precedence = 2 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2019 int lhs_beg_pos = peek_position(); | 2132 int lhs_beg_pos = peek_position(); |
| 2020 | 2133 |
| 2021 if (peek() == Token::YIELD && is_generator()) { | 2134 if (peek() == Token::YIELD && is_generator()) { |
| 2022 return this->ParseYieldExpression(accept_IN, classifier, ok); | 2135 return this->ParseYieldExpression(accept_IN, classifier, ok); |
| 2023 } | 2136 } |
| 2024 | 2137 |
| 2025 FuncNameInferrer::State fni_state(fni_); | 2138 FuncNameInferrer::State fni_state(fni_); |
| 2026 ParserBase<Traits>::Checkpoint checkpoint(this); | 2139 ParserBase<Traits>::Checkpoint checkpoint(this); |
| 2027 ExpressionClassifier arrow_formals_classifier(this, | 2140 ExpressionClassifier arrow_formals_classifier(this, |
| 2028 classifier->duplicate_finder()); | 2141 classifier->duplicate_finder()); |
| 2142 |
| 2143 bool is_async = allow_harmony_async_await() && peek() == Token::IDENTIFIER && |
| 2144 PeekContextualKeyword(CStrVector("async")) && |
| 2145 !scanner()->HasAnyLineTerminatorAfterNext(); |
| 2146 |
| 2029 bool parenthesized_formals = peek() == Token::LPAREN; | 2147 bool parenthesized_formals = peek() == Token::LPAREN; |
| 2030 if (!parenthesized_formals) { | 2148 if (!is_async && !parenthesized_formals) { |
| 2031 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2149 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
| 2032 } | 2150 } |
| 2033 ExpressionT expression = this->ParseConditionalExpression( | 2151 ExpressionT expression = this->ParseConditionalExpression( |
| 2034 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2152 accept_IN, &arrow_formals_classifier, CHECK_OK); |
| 2153 |
| 2154 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { |
| 2155 // async Identifier => AsyncConciseBody |
| 2156 IdentifierT name = |
| 2157 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); |
| 2158 expression = this->ExpressionFromIdentifier( |
| 2159 name, position(), scanner()->location().end_pos, scope_, factory()); |
| 2160 } |
| 2161 |
| 2035 if (peek() == Token::ARROW) { | 2162 if (peek() == Token::ARROW) { |
| 2036 classifier->RecordPatternError(scanner()->peek_location(), | 2163 classifier->RecordPatternError(scanner()->peek_location(), |
| 2037 MessageTemplate::kUnexpectedToken, | 2164 MessageTemplate::kUnexpectedToken, |
| 2038 Token::String(Token::ARROW)); | 2165 Token::String(Token::ARROW)); |
| 2039 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2166 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
| 2040 parenthesized_formals, CHECK_OK); | 2167 parenthesized_formals, is_async, CHECK_OK); |
| 2041 // This reads strangely, but is correct: it checks whether any | 2168 // This reads strangely, but is correct: it checks whether any |
| 2042 // sub-expression of the parameter list failed to be a valid formal | 2169 // sub-expression of the parameter list failed to be a valid formal |
| 2043 // parameter initializer. Since YieldExpressions are banned anywhere | 2170 // parameter initializer. Since YieldExpressions are banned anywhere |
| 2044 // in an arrow parameter list, this is correct. | 2171 // in an arrow parameter list, this is correct. |
| 2045 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to | 2172 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to |
| 2046 // "YieldExpression", which is its only use. | 2173 // "YieldExpression", which is its only use. |
| 2047 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); | 2174 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); |
| 2175 |
| 2048 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); | 2176 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
| 2049 Scope* scope = | 2177 Scope* scope = |
| 2050 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); | 2178 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); |
| 2051 // Because the arrow's parameters were parsed in the outer scope, any | 2179 // Because the arrow's parameters were parsed in the outer scope, any |
| 2052 // usage flags that might have been triggered there need to be copied | 2180 // usage flags that might have been triggered there need to be copied |
| 2053 // to the arrow scope. | 2181 // to the arrow scope. |
| 2054 scope_->PropagateUsageFlagsToScope(scope); | 2182 scope_->PropagateUsageFlagsToScope(scope); |
| 2055 FormalParametersT parameters(scope); | 2183 FormalParametersT parameters(scope); |
| 2056 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 2184 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
| 2057 scope->SetHasNonSimpleParameters(); | 2185 scope->SetHasNonSimpleParameters(); |
| 2058 parameters.is_simple = false; | 2186 parameters.is_simple = false; |
| 2059 } | 2187 } |
| 2060 | 2188 |
| 2061 checkpoint.Restore(¶meters.materialized_literals_count); | 2189 checkpoint.Restore(¶meters.materialized_literals_count); |
| 2062 | 2190 |
| 2063 scope->set_start_position(lhs_beg_pos); | 2191 scope->set_start_position(lhs_beg_pos); |
| 2064 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2192 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2065 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2193 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
| 2066 &duplicate_loc, CHECK_OK); | 2194 &duplicate_loc, CHECK_OK); |
| 2067 if (duplicate_loc.IsValid()) { | 2195 if (duplicate_loc.IsValid()) { |
| 2068 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2196 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2069 duplicate_loc); | 2197 duplicate_loc); |
| 2070 } | 2198 } |
| 2071 expression = this->ParseArrowFunctionLiteral( | 2199 expression = this->ParseArrowFunctionLiteral( |
| 2072 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2200 accept_IN, parameters, is_async, arrow_formals_classifier, CHECK_OK); |
| 2073 | 2201 |
| 2074 if (fni_ != nullptr) fni_->Infer(); | 2202 if (fni_ != nullptr) fni_->Infer(); |
| 2075 | 2203 |
| 2076 return expression; | 2204 return expression; |
| 2077 } | 2205 } |
| 2078 | 2206 |
| 2079 if (this->IsValidReferenceExpression(expression)) { | 2207 if (this->IsValidReferenceExpression(expression)) { |
| 2080 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2208 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
| 2081 } | 2209 } |
| 2082 | 2210 |
| 2083 // "expression" was not itself an arrow function parameter list, but it might | 2211 // "expression" was not itself an arrow function parameter list, but it might |
| 2084 // form part of one. Propagate speculative formal parameter error locations. | 2212 // form part of one. Propagate speculative formal parameter error locations. |
| 2085 // Do not merge pending non-pattern expressions yet! | 2213 // Do not merge pending non-pattern expressions yet! |
| 2086 classifier->Accumulate( | 2214 classifier->Accumulate( |
| 2087 &arrow_formals_classifier, | 2215 &arrow_formals_classifier, |
| 2088 ExpressionClassifier::StandardProductions | | 2216 ExpressionClassifier::StandardProductions | |
| 2089 ExpressionClassifier::FormalParametersProductions | | 2217 ExpressionClassifier::FormalParametersProductions | |
| 2090 ExpressionClassifier::CoverInitializedNameProduction, | 2218 ExpressionClassifier::CoverInitializedNameProduction | |
| 2219 ExpressionClassifier::AsyncArrowFormalParametersProduction | |
| 2220 ExpressionClassifier::AsyncBindingPatternProduction, |
| 2091 false); | 2221 false); |
| 2092 | 2222 |
| 2093 if (!Token::IsAssignmentOp(peek())) { | 2223 if (!Token::IsAssignmentOp(peek())) { |
| 2094 // Parsed conditional expression only (no assignment). | 2224 // Parsed conditional expression only (no assignment). |
| 2095 // Now pending non-pattern expressions must be merged. | 2225 // Now pending non-pattern expressions must be merged. |
| 2096 classifier->MergeNonPatterns(&arrow_formals_classifier); | 2226 classifier->MergeNonPatterns(&arrow_formals_classifier); |
| 2097 return expression; | 2227 return expression; |
| 2098 } | 2228 } |
| 2099 | 2229 |
| 2100 // Now pending non-pattern expressions must be discarded. | 2230 // Now pending non-pattern expressions must be discarded. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2122 } | 2252 } |
| 2123 int pos = position(); | 2253 int pos = position(); |
| 2124 | 2254 |
| 2125 ExpressionClassifier rhs_classifier(this); | 2255 ExpressionClassifier rhs_classifier(this); |
| 2126 | 2256 |
| 2127 ExpressionT right = | 2257 ExpressionT right = |
| 2128 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); | 2258 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
| 2129 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); | 2259 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); |
| 2130 Traits::RewriteNonPattern(&rhs_classifier, CHECK_OK); | 2260 Traits::RewriteNonPattern(&rhs_classifier, CHECK_OK); |
| 2131 classifier->Accumulate( | 2261 classifier->Accumulate( |
| 2132 &rhs_classifier, ExpressionClassifier::ExpressionProductions | | 2262 &rhs_classifier, |
| 2133 ExpressionClassifier::CoverInitializedNameProduction); | 2263 ExpressionClassifier::ExpressionProductions | |
| 2264 ExpressionClassifier::CoverInitializedNameProduction | |
| 2265 ExpressionClassifier::AsyncArrowFormalParametersProduction); |
| 2134 | 2266 |
| 2135 // TODO(1231235): We try to estimate the set of properties set by | 2267 // TODO(1231235): We try to estimate the set of properties set by |
| 2136 // constructors. We define a new property whenever there is an | 2268 // constructors. We define a new property whenever there is an |
| 2137 // assignment to a property of 'this'. We should probably only add | 2269 // assignment to a property of 'this'. We should probably only add |
| 2138 // properties if we haven't seen them before. Otherwise we'll | 2270 // properties if we haven't seen them before. Otherwise we'll |
| 2139 // probably overestimate the number of properties. | 2271 // probably overestimate the number of properties. |
| 2140 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2272 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { |
| 2141 function_state_->AddProperty(); | 2273 function_state_->AddProperty(); |
| 2142 } | 2274 } |
| 2143 | 2275 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2394 // PostfixExpression | 2526 // PostfixExpression |
| 2395 // 'delete' UnaryExpression | 2527 // 'delete' UnaryExpression |
| 2396 // 'void' UnaryExpression | 2528 // 'void' UnaryExpression |
| 2397 // 'typeof' UnaryExpression | 2529 // 'typeof' UnaryExpression |
| 2398 // '++' UnaryExpression | 2530 // '++' UnaryExpression |
| 2399 // '--' UnaryExpression | 2531 // '--' UnaryExpression |
| 2400 // '+' UnaryExpression | 2532 // '+' UnaryExpression |
| 2401 // '-' UnaryExpression | 2533 // '-' UnaryExpression |
| 2402 // '~' UnaryExpression | 2534 // '~' UnaryExpression |
| 2403 // '!' UnaryExpression | 2535 // '!' UnaryExpression |
| 2536 // [+Await] AwaitExpression[?Yield] |
| 2404 | 2537 |
| 2405 Token::Value op = peek(); | 2538 Token::Value op = peek(); |
| 2406 if (Token::IsUnaryOp(op)) { | 2539 if (Token::IsUnaryOp(op)) { |
| 2407 BindingPatternUnexpectedToken(classifier); | 2540 BindingPatternUnexpectedToken(classifier); |
| 2408 ArrowFormalParametersUnexpectedToken(classifier); | 2541 ArrowFormalParametersUnexpectedToken(classifier); |
| 2409 | 2542 |
| 2410 op = Next(); | 2543 op = Next(); |
| 2411 int pos = position(); | 2544 int pos = position(); |
| 2412 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2545 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
| 2413 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2546 CheckNoTailCallExpressions(classifier, CHECK_OK); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2441 expression, beg_pos, scanner()->location().end_pos, | 2574 expression, beg_pos, scanner()->location().end_pos, |
| 2442 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2575 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
| 2443 this->MarkExpressionAsAssigned(expression); | 2576 this->MarkExpressionAsAssigned(expression); |
| 2444 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2577 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2445 | 2578 |
| 2446 return factory()->NewCountOperation(op, | 2579 return factory()->NewCountOperation(op, |
| 2447 true /* prefix */, | 2580 true /* prefix */, |
| 2448 expression, | 2581 expression, |
| 2449 position()); | 2582 position()); |
| 2450 | 2583 |
| 2584 } else if (is_async_function() && peek() == Token::AWAIT) { |
| 2585 int beg_pos = peek_position(); |
| 2586 switch (PeekAhead()) { |
| 2587 case Token::RPAREN: |
| 2588 case Token::RBRACK: |
| 2589 case Token::RBRACE: |
| 2590 case Token::ASSIGN: |
| 2591 case Token::COMMA: { |
| 2592 Next(); |
| 2593 IdentifierT name = this->GetSymbol(scanner()); |
| 2594 |
| 2595 // Possibly async arrow formals --- record ExpressionError just in case. |
| 2596 ExpressionUnexpectedToken(classifier); |
| 2597 classifier->RecordAsyncBindingPatternError( |
| 2598 Scanner::Location(beg_pos, scanner()->location().end_pos), |
| 2599 MessageTemplate::kAwaitBindingIdentifier); |
| 2600 classifier->RecordAsyncArrowFormalParametersError( |
| 2601 Scanner::Location(beg_pos, scanner()->location().end_pos), |
| 2602 MessageTemplate::kAwaitBindingIdentifier); |
| 2603 |
| 2604 return this->ExpressionFromIdentifier( |
| 2605 name, beg_pos, scanner()->location().end_pos, scope_, factory()); |
| 2606 } |
| 2607 default: |
| 2608 break; |
| 2609 } |
| 2610 Consume(Token::AWAIT); |
| 2611 |
| 2612 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); |
| 2613 classifier->RecordFormalParameterInitializerError( |
| 2614 Scanner::Location(beg_pos, scanner()->location().end_pos), |
| 2615 MessageTemplate::kAwaitExpressionFormalParameter); |
| 2616 |
| 2617 return Traits::RewriteAwaitExpression(value, beg_pos); |
| 2451 } else { | 2618 } else { |
| 2452 return this->ParsePostfixExpression(classifier, ok); | 2619 return this->ParsePostfixExpression(classifier, ok); |
| 2453 } | 2620 } |
| 2454 } | 2621 } |
| 2455 | 2622 |
| 2456 | 2623 |
| 2457 template <class Traits> | 2624 template <class Traits> |
| 2458 typename ParserBase<Traits>::ExpressionT | 2625 typename ParserBase<Traits>::ExpressionT |
| 2459 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, | 2626 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, |
| 2460 bool* ok) { | 2627 bool* ok) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2490 typename ParserBase<Traits>::ExpressionT | 2657 typename ParserBase<Traits>::ExpressionT |
| 2491 ParserBase<Traits>::ParseLeftHandSideExpression( | 2658 ParserBase<Traits>::ParseLeftHandSideExpression( |
| 2492 ExpressionClassifier* classifier, bool* ok) { | 2659 ExpressionClassifier* classifier, bool* ok) { |
| 2493 // LeftHandSideExpression :: | 2660 // LeftHandSideExpression :: |
| 2494 // (NewExpression | MemberExpression) ... | 2661 // (NewExpression | MemberExpression) ... |
| 2495 | 2662 |
| 2496 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { | 2663 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { |
| 2497 return this->ParseTailCallExpression(classifier, ok); | 2664 return this->ParseTailCallExpression(classifier, ok); |
| 2498 } | 2665 } |
| 2499 | 2666 |
| 2500 ExpressionT result = | 2667 bool is_async = false; |
| 2501 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2668 ExpressionT result = this->ParseMemberWithNewPrefixesExpression( |
| 2669 classifier, &is_async, CHECK_OK); |
| 2502 | 2670 |
| 2503 while (true) { | 2671 while (true) { |
| 2504 switch (peek()) { | 2672 switch (peek()) { |
| 2505 case Token::LBRACK: { | 2673 case Token::LBRACK: { |
| 2506 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2674 CheckNoTailCallExpressions(classifier, CHECK_OK); |
| 2507 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2675 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2508 BindingPatternUnexpectedToken(classifier); | 2676 BindingPatternUnexpectedToken(classifier); |
| 2509 ArrowFormalParametersUnexpectedToken(classifier); | 2677 ArrowFormalParametersUnexpectedToken(classifier); |
| 2510 Consume(Token::LBRACK); | 2678 Consume(Token::LBRACK); |
| 2511 int pos = position(); | 2679 int pos = position(); |
| 2512 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2680 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
| 2513 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2681 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2514 result = factory()->NewProperty(result, index, pos); | 2682 result = factory()->NewProperty(result, index, pos); |
| 2515 Expect(Token::RBRACK, CHECK_OK); | 2683 Expect(Token::RBRACK, CHECK_OK); |
| 2516 break; | 2684 break; |
| 2517 } | 2685 } |
| 2518 | 2686 |
| 2519 case Token::LPAREN: { | 2687 case Token::LPAREN: { |
| 2520 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2688 CheckNoTailCallExpressions(classifier, CHECK_OK); |
| 2689 int pos; |
| 2521 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2690 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2522 BindingPatternUnexpectedToken(classifier); | 2691 BindingPatternUnexpectedToken(classifier); |
| 2523 ArrowFormalParametersUnexpectedToken(classifier); | |
| 2524 | |
| 2525 int pos; | |
| 2526 if (scanner()->current_token() == Token::IDENTIFIER || | 2692 if (scanner()->current_token() == Token::IDENTIFIER || |
| 2527 scanner()->current_token() == Token::SUPER) { | 2693 scanner()->current_token() == Token::SUPER) { |
| 2528 // For call of an identifier we want to report position of | 2694 // For call of an identifier we want to report position of |
| 2529 // the identifier as position of the call in the stack trace. | 2695 // the identifier as position of the call in the stack trace. |
| 2530 pos = position(); | 2696 pos = position(); |
| 2531 } else { | 2697 } else { |
| 2532 // For other kinds of calls we record position of the parenthesis as | 2698 // For other kinds of calls we record position of the parenthesis as |
| 2533 // position of the call. Note that this is extremely important for | 2699 // position of the call. Note that this is extremely important for |
| 2534 // expressions of the form function(){...}() for which call position | 2700 // expressions of the form function(){...}() for which call position |
| 2535 // should not point to the closing brace otherwise it will intersect | 2701 // should not point to the closing brace otherwise it will intersect |
| 2536 // with positions recorded for function literal and confuse debugger. | 2702 // with positions recorded for function literal and confuse debugger. |
| 2537 pos = peek_position(); | 2703 pos = peek_position(); |
| 2538 // Also the trailing parenthesis are a hint that the function will | 2704 // Also the trailing parenthesis are a hint that the function will |
| 2539 // be called immediately. If we happen to have parsed a preceding | 2705 // be called immediately. If we happen to have parsed a preceding |
| 2540 // function literal eagerly, we can also compile it eagerly. | 2706 // function literal eagerly, we can also compile it eagerly. |
| 2541 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2707 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
| 2542 result->AsFunctionLiteral()->set_should_eager_compile(); | 2708 result->AsFunctionLiteral()->set_should_eager_compile(); |
| 2543 } | 2709 } |
| 2544 } | 2710 } |
| 2545 Scanner::Location spread_pos; | 2711 Scanner::Location spread_pos; |
| 2546 typename Traits::Type::ExpressionList args = | 2712 typename Traits::Type::ExpressionList args = |
| 2547 ParseArguments(&spread_pos, classifier, CHECK_OK); | 2713 ParseArguments(&spread_pos, is_async, classifier, CHECK_OK); |
| 2714 |
| 2715 if (V8_UNLIKELY(is_async && peek() == Token::ARROW)) { |
| 2716 if (args->length()) { |
| 2717 // async ( Arguments ) => ... |
| 2718 return Traits::ExpressionListToExpression(args); |
| 2719 } |
| 2720 // async () => ... |
| 2721 return factory()->NewEmptyParentheses(pos); |
| 2722 } |
| 2723 |
| 2724 ArrowFormalParametersUnexpectedToken(classifier); |
| 2548 | 2725 |
| 2549 // Keep track of eval() calls since they disable all local variable | 2726 // Keep track of eval() calls since they disable all local variable |
| 2550 // optimizations. | 2727 // optimizations. |
| 2551 // The calls that need special treatment are the | 2728 // The calls that need special treatment are the |
| 2552 // direct eval calls. These calls are all of the form eval(...), with | 2729 // direct eval calls. These calls are all of the form eval(...), with |
| 2553 // no explicit receiver. | 2730 // no explicit receiver. |
| 2554 // These calls are marked as potentially direct eval calls. Whether | 2731 // These calls are marked as potentially direct eval calls. Whether |
| 2555 // they are actually direct calls to eval is determined at run time. | 2732 // they are actually direct calls to eval is determined at run time. |
| 2556 this->CheckPossibleEvalCall(result, scope_); | 2733 this->CheckPossibleEvalCall(result, scope_); |
| 2557 | 2734 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); | 2775 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); |
| 2599 break; | 2776 break; |
| 2600 } | 2777 } |
| 2601 | 2778 |
| 2602 default: | 2779 default: |
| 2603 return result; | 2780 return result; |
| 2604 } | 2781 } |
| 2605 } | 2782 } |
| 2606 } | 2783 } |
| 2607 | 2784 |
| 2608 | |
| 2609 template <class Traits> | 2785 template <class Traits> |
| 2610 typename ParserBase<Traits>::ExpressionT | 2786 typename ParserBase<Traits>::ExpressionT |
| 2611 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( | 2787 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( |
| 2612 ExpressionClassifier* classifier, bool* ok) { | 2788 ExpressionClassifier* classifier, bool* is_async, bool* ok) { |
| 2613 // NewExpression :: | 2789 // NewExpression :: |
| 2614 // ('new')+ MemberExpression | 2790 // ('new')+ MemberExpression |
| 2615 // | 2791 // |
| 2616 // NewTarget :: | 2792 // NewTarget :: |
| 2617 // 'new' '.' 'target' | 2793 // 'new' '.' 'target' |
| 2618 | 2794 |
| 2619 // The grammar for new expressions is pretty warped. We can have several 'new' | 2795 // The grammar for new expressions is pretty warped. We can have several 'new' |
| 2620 // keywords following each other, and then a MemberExpression. When we see '(' | 2796 // keywords following each other, and then a MemberExpression. When we see '(' |
| 2621 // after the MemberExpression, it's associated with the rightmost unassociated | 2797 // after the MemberExpression, it's associated with the rightmost unassociated |
| 2622 // 'new' to create a NewExpression with arguments. However, a NewExpression | 2798 // 'new' to create a NewExpression with arguments. However, a NewExpression |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2635 ArrowFormalParametersUnexpectedToken(classifier); | 2811 ArrowFormalParametersUnexpectedToken(classifier); |
| 2636 Consume(Token::NEW); | 2812 Consume(Token::NEW); |
| 2637 int new_pos = position(); | 2813 int new_pos = position(); |
| 2638 ExpressionT result = this->EmptyExpression(); | 2814 ExpressionT result = this->EmptyExpression(); |
| 2639 if (peek() == Token::SUPER) { | 2815 if (peek() == Token::SUPER) { |
| 2640 const bool is_new = true; | 2816 const bool is_new = true; |
| 2641 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2817 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
| 2642 } else if (peek() == Token::PERIOD) { | 2818 } else if (peek() == Token::PERIOD) { |
| 2643 return ParseNewTargetExpression(CHECK_OK); | 2819 return ParseNewTargetExpression(CHECK_OK); |
| 2644 } else { | 2820 } else { |
| 2645 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2821 result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async, |
| 2822 CHECK_OK); |
| 2646 } | 2823 } |
| 2647 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2824 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2648 if (peek() == Token::LPAREN) { | 2825 if (peek() == Token::LPAREN) { |
| 2649 // NewExpression with arguments. | 2826 // NewExpression with arguments. |
| 2650 Scanner::Location spread_pos; | 2827 Scanner::Location spread_pos; |
| 2651 typename Traits::Type::ExpressionList args = | 2828 typename Traits::Type::ExpressionList args = |
| 2652 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2829 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
| 2653 | 2830 |
| 2654 if (spread_pos.IsValid()) { | 2831 if (spread_pos.IsValid()) { |
| 2655 args = Traits::PrepareSpreadArguments(args); | 2832 args = Traits::PrepareSpreadArguments(args); |
| 2656 result = Traits::SpreadCallNew(result, args, new_pos); | 2833 result = Traits::SpreadCallNew(result, args, new_pos); |
| 2657 } else { | 2834 } else { |
| 2658 result = factory()->NewCallNew(result, args, new_pos); | 2835 result = factory()->NewCallNew(result, args, new_pos); |
| 2659 } | 2836 } |
| 2660 // The expression can still continue with . or [ after the arguments. | 2837 // The expression can still continue with . or [ after the arguments. |
| 2661 result = | 2838 result = this->ParseMemberExpressionContinuation(result, is_async, |
| 2662 this->ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2839 classifier, CHECK_OK); |
| 2663 return result; | 2840 return result; |
| 2664 } | 2841 } |
| 2665 // NewExpression without arguments. | 2842 // NewExpression without arguments. |
| 2666 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2843 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
| 2667 new_pos); | 2844 new_pos); |
| 2668 } | 2845 } |
| 2669 // No 'new' or 'super' keyword. | 2846 // No 'new' or 'super' keyword. |
| 2670 return this->ParseMemberExpression(classifier, ok); | 2847 return this->ParseMemberExpression(classifier, is_async, ok); |
| 2671 } | 2848 } |
| 2672 | 2849 |
| 2673 | |
| 2674 template <class Traits> | 2850 template <class Traits> |
| 2675 typename ParserBase<Traits>::ExpressionT | 2851 typename ParserBase<Traits>::ExpressionT |
| 2676 ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, | 2852 ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, |
| 2677 bool* ok) { | 2853 bool* is_async, bool* ok) { |
| 2678 // MemberExpression :: | 2854 // MemberExpression :: |
| 2679 // (PrimaryExpression | FunctionLiteral | ClassLiteral) | 2855 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
| 2680 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* | 2856 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
| 2681 | 2857 |
| 2682 // The '[' Expression ']' and '.' Identifier parts are parsed by | 2858 // The '[' Expression ']' and '.' Identifier parts are parsed by |
| 2683 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 2859 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
| 2684 // caller. | 2860 // caller. |
| 2685 | 2861 |
| 2686 // Parse the initial primary or function expression. | 2862 // Parse the initial primary or function expression. |
| 2687 ExpressionT result = this->EmptyExpression(); | 2863 ExpressionT result = this->EmptyExpression(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2724 name, function_name_location, | 2900 name, function_name_location, |
| 2725 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 2901 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
| 2726 : kFunctionNameValidityUnknown, | 2902 : kFunctionNameValidityUnknown, |
| 2727 is_generator ? FunctionKind::kGeneratorFunction | 2903 is_generator ? FunctionKind::kGeneratorFunction |
| 2728 : FunctionKind::kNormalFunction, | 2904 : FunctionKind::kNormalFunction, |
| 2729 function_token_position, function_type, language_mode(), CHECK_OK); | 2905 function_token_position, function_type, language_mode(), CHECK_OK); |
| 2730 } else if (peek() == Token::SUPER) { | 2906 } else if (peek() == Token::SUPER) { |
| 2731 const bool is_new = false; | 2907 const bool is_new = false; |
| 2732 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2908 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
| 2733 } else { | 2909 } else { |
| 2734 result = ParsePrimaryExpression(classifier, CHECK_OK); | 2910 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); |
| 2735 } | 2911 } |
| 2736 | 2912 |
| 2737 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2913 result = |
| 2914 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); |
| 2738 return result; | 2915 return result; |
| 2739 } | 2916 } |
| 2740 | 2917 |
| 2741 | 2918 |
| 2742 template <class Traits> | 2919 template <class Traits> |
| 2743 typename ParserBase<Traits>::ExpressionT | 2920 typename ParserBase<Traits>::ExpressionT |
| 2744 ParserBase<Traits>::ParseSuperExpression(bool is_new, | 2921 ParserBase<Traits>::ParseSuperExpression(bool is_new, |
| 2745 ExpressionClassifier* classifier, | 2922 ExpressionClassifier* classifier, |
| 2746 bool* ok) { | 2923 bool* ok) { |
| 2747 Expect(Token::SUPER, CHECK_OK); | 2924 Expect(Token::SUPER, CHECK_OK); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 if (!scope_->ReceiverScope()->is_function_scope()) { | 2971 if (!scope_->ReceiverScope()->is_function_scope()) { |
| 2795 ReportMessageAt(scanner()->location(), | 2972 ReportMessageAt(scanner()->location(), |
| 2796 MessageTemplate::kUnexpectedNewTarget); | 2973 MessageTemplate::kUnexpectedNewTarget); |
| 2797 *ok = false; | 2974 *ok = false; |
| 2798 return this->EmptyExpression(); | 2975 return this->EmptyExpression(); |
| 2799 } | 2976 } |
| 2800 | 2977 |
| 2801 return this->NewTargetExpression(scope_, factory(), pos); | 2978 return this->NewTargetExpression(scope_, factory(), pos); |
| 2802 } | 2979 } |
| 2803 | 2980 |
| 2804 | |
| 2805 template <class Traits> | 2981 template <class Traits> |
| 2806 typename ParserBase<Traits>::ExpressionT | 2982 typename ParserBase<Traits>::ExpressionT |
| 2807 ParserBase<Traits>::ParseMemberExpressionContinuation( | 2983 ParserBase<Traits>::ParseMemberExpressionContinuation( |
| 2808 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) { | 2984 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
| 2985 bool* ok) { |
| 2809 // Parses this part of MemberExpression: | 2986 // Parses this part of MemberExpression: |
| 2810 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2987 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
| 2811 while (true) { | 2988 while (true) { |
| 2812 switch (peek()) { | 2989 switch (peek()) { |
| 2813 case Token::LBRACK: { | 2990 case Token::LBRACK: { |
| 2991 *is_async = false; |
| 2814 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2992 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2815 BindingPatternUnexpectedToken(classifier); | 2993 BindingPatternUnexpectedToken(classifier); |
| 2816 ArrowFormalParametersUnexpectedToken(classifier); | 2994 ArrowFormalParametersUnexpectedToken(classifier); |
| 2817 | 2995 |
| 2818 Consume(Token::LBRACK); | 2996 Consume(Token::LBRACK); |
| 2819 int pos = position(); | 2997 int pos = position(); |
| 2820 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2998 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
| 2821 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2999 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2822 expression = factory()->NewProperty(expression, index, pos); | 3000 expression = factory()->NewProperty(expression, index, pos); |
| 2823 if (fni_ != NULL) { | 3001 if (fni_ != NULL) { |
| 2824 this->PushPropertyName(fni_, index); | 3002 this->PushPropertyName(fni_, index); |
| 2825 } | 3003 } |
| 2826 Expect(Token::RBRACK, CHECK_OK); | 3004 Expect(Token::RBRACK, CHECK_OK); |
| 2827 break; | 3005 break; |
| 2828 } | 3006 } |
| 2829 case Token::PERIOD: { | 3007 case Token::PERIOD: { |
| 3008 *is_async = false; |
| 2830 Traits::RewriteNonPattern(classifier, CHECK_OK); | 3009 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2831 BindingPatternUnexpectedToken(classifier); | 3010 BindingPatternUnexpectedToken(classifier); |
| 2832 ArrowFormalParametersUnexpectedToken(classifier); | 3011 ArrowFormalParametersUnexpectedToken(classifier); |
| 2833 | 3012 |
| 2834 Consume(Token::PERIOD); | 3013 Consume(Token::PERIOD); |
| 2835 int pos = position(); | 3014 int pos = position(); |
| 2836 IdentifierT name = ParseIdentifierName(CHECK_OK); | 3015 IdentifierT name = ParseIdentifierName(CHECK_OK); |
| 2837 expression = factory()->NewProperty( | 3016 expression = factory()->NewProperty( |
| 2838 expression, factory()->NewStringLiteral(name, pos), pos); | 3017 expression, factory()->NewStringLiteral(name, pos), pos); |
| 2839 if (fni_ != NULL) { | 3018 if (fni_ != NULL) { |
| 2840 this->PushLiteralName(fni_, name); | 3019 this->PushLiteralName(fni_, name); |
| 2841 } | 3020 } |
| 2842 break; | 3021 break; |
| 2843 } | 3022 } |
| 2844 case Token::TEMPLATE_SPAN: | 3023 case Token::TEMPLATE_SPAN: |
| 2845 case Token::TEMPLATE_TAIL: { | 3024 case Token::TEMPLATE_TAIL: { |
| 3025 *is_async = false; |
| 2846 Traits::RewriteNonPattern(classifier, CHECK_OK); | 3026 Traits::RewriteNonPattern(classifier, CHECK_OK); |
| 2847 BindingPatternUnexpectedToken(classifier); | 3027 BindingPatternUnexpectedToken(classifier); |
| 2848 ArrowFormalParametersUnexpectedToken(classifier); | 3028 ArrowFormalParametersUnexpectedToken(classifier); |
| 2849 int pos; | 3029 int pos; |
| 2850 if (scanner()->current_token() == Token::IDENTIFIER) { | 3030 if (scanner()->current_token() == Token::IDENTIFIER) { |
| 2851 pos = position(); | 3031 pos = position(); |
| 2852 } else { | 3032 } else { |
| 2853 pos = peek_position(); | 3033 pos = peek_position(); |
| 2854 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 3034 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
| 2855 // If the tag function looks like an IIFE, set_parenthesized() to | 3035 // If the tag function looks like an IIFE, set_parenthesized() to |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3004 case Token::STATIC: | 3184 case Token::STATIC: |
| 3005 case Token::LET: // Yes, you can do let let = ... in sloppy mode | 3185 case Token::LET: // Yes, you can do let let = ... in sloppy mode |
| 3006 case Token::YIELD: | 3186 case Token::YIELD: |
| 3007 case Token::AWAIT: | 3187 case Token::AWAIT: |
| 3008 return true; | 3188 return true; |
| 3009 default: | 3189 default: |
| 3010 return false; | 3190 return false; |
| 3011 } | 3191 } |
| 3012 } | 3192 } |
| 3013 | 3193 |
| 3014 | |
| 3015 template <class Traits> | 3194 template <class Traits> |
| 3016 typename ParserBase<Traits>::ExpressionT | 3195 typename ParserBase<Traits>::ExpressionT |
| 3017 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3196 ParserBase<Traits>::ParseArrowFunctionLiteral( |
| 3018 bool accept_IN, const FormalParametersT& formal_parameters, | 3197 bool accept_IN, const FormalParametersT& formal_parameters, bool is_async, |
| 3019 const ExpressionClassifier& formals_classifier, bool* ok) { | 3198 const ExpressionClassifier& formals_classifier, bool* ok) { |
| 3020 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3199 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
| 3021 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3200 // ASI inserts `;` after arrow parameters if a line terminator is found. |
| 3022 // `=> ...` is never a valid expression, so report as syntax error. | 3201 // `=> ...` is never a valid expression, so report as syntax error. |
| 3023 // If next token is not `=>`, it's a syntax error anyways. | 3202 // If next token is not `=>`, it's a syntax error anyways. |
| 3024 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3203 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
| 3025 *ok = false; | 3204 *ok = false; |
| 3026 return this->EmptyExpression(); | 3205 return this->EmptyExpression(); |
| 3027 } | 3206 } |
| 3028 | 3207 |
| 3029 typename Traits::Type::StatementList body; | 3208 typename Traits::Type::StatementList body; |
| 3030 int num_parameters = formal_parameters.scope->num_parameters(); | 3209 int num_parameters = formal_parameters.scope->num_parameters(); |
| 3031 int materialized_literal_count = -1; | 3210 int materialized_literal_count = -1; |
| 3032 int expected_property_count = -1; | 3211 int expected_property_count = -1; |
| 3033 Scanner::Location super_loc; | 3212 Scanner::Location super_loc; |
| 3034 | 3213 |
| 3035 { | 3214 { |
| 3036 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3215 typename Traits::Type::Factory function_factory(ast_value_factory()); |
| 3037 FunctionState function_state(&function_state_, &scope_, | 3216 FunctionState function_state( |
| 3038 formal_parameters.scope, kArrowFunction, | 3217 &function_state_, &scope_, formal_parameters.scope, |
| 3039 &function_factory); | 3218 is_async ? kAsyncArrowFunction : kArrowFunction, &function_factory); |
| 3040 | 3219 |
| 3041 function_state.SkipMaterializedLiterals( | 3220 function_state.SkipMaterializedLiterals( |
| 3042 formal_parameters.materialized_literals_count); | 3221 formal_parameters.materialized_literals_count); |
| 3043 | 3222 |
| 3044 this->ReindexLiterals(formal_parameters); | 3223 this->ReindexLiterals(formal_parameters); |
| 3045 | 3224 |
| 3046 Expect(Token::ARROW, CHECK_OK); | 3225 Expect(Token::ARROW, CHECK_OK); |
| 3047 | 3226 |
| 3048 if (peek() == Token::LBRACE) { | 3227 if (peek() == Token::LBRACE) { |
| 3049 // Multiple statement body | 3228 // Multiple statement body |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3277 classifier->RecordAssignmentPatternError( | 3456 classifier->RecordAssignmentPatternError( |
| 3278 Scanner::Location(begin, end), | 3457 Scanner::Location(begin, end), |
| 3279 MessageTemplate::kInvalidDestructuringTarget); | 3458 MessageTemplate::kInvalidDestructuringTarget); |
| 3280 } | 3459 } |
| 3281 } | 3460 } |
| 3282 | 3461 |
| 3283 | 3462 |
| 3284 #undef CHECK_OK | 3463 #undef CHECK_OK |
| 3285 #undef CHECK_OK_CUSTOM | 3464 #undef CHECK_OK_CUSTOM |
| 3286 | 3465 |
| 3287 | |
| 3288 template <typename Traits> | 3466 template <typename Traits> |
| 3289 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3467 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| 3290 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3468 Token::Value property, PropertyKind type, MethodKind method_type, |
| 3291 bool* ok) { | 3469 bool* ok) { |
| 3292 DCHECK(!is_static); | 3470 DCHECK(!IsStaticMethod(method_type)); |
| 3293 DCHECK(!is_generator || type == kMethodProperty); | 3471 DCHECK(!IsMethod(method_type) || type == kMethodProperty); |
| 3294 | 3472 |
| 3295 if (property == Token::SMI || property == Token::NUMBER) return; | 3473 if (property == Token::SMI || property == Token::NUMBER) return; |
| 3296 | 3474 |
| 3297 if (type == kValueProperty && IsProto()) { | 3475 if (type == kValueProperty && IsProto()) { |
| 3298 if (has_seen_proto_) { | 3476 if (has_seen_proto_) { |
| 3299 this->parser()->ReportMessage(MessageTemplate::kDuplicateProto); | 3477 this->parser()->ReportMessage(MessageTemplate::kDuplicateProto); |
| 3300 *ok = false; | 3478 *ok = false; |
| 3301 return; | 3479 return; |
| 3302 } | 3480 } |
| 3303 has_seen_proto_ = true; | 3481 has_seen_proto_ = true; |
| 3304 return; | 3482 return; |
| 3305 } | 3483 } |
| 3306 } | 3484 } |
| 3307 | 3485 |
| 3308 | |
| 3309 template <typename Traits> | 3486 template <typename Traits> |
| 3310 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( | 3487 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( |
| 3311 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3488 Token::Value property, PropertyKind type, MethodKind method_type, |
| 3312 bool* ok) { | 3489 bool* ok) { |
| 3313 DCHECK(type == kMethodProperty || type == kAccessorProperty); | 3490 DCHECK(type == kMethodProperty || type == kAccessorProperty); |
| 3314 | 3491 |
| 3315 if (property == Token::SMI || property == Token::NUMBER) return; | 3492 if (property == Token::SMI || property == Token::NUMBER) return; |
| 3316 | 3493 |
| 3317 if (is_static) { | 3494 if (IsStaticMethod(method_type)) { |
| 3318 if (IsPrototype()) { | 3495 if (IsPrototype()) { |
| 3319 this->parser()->ReportMessage(MessageTemplate::kStaticPrototype); | 3496 this->parser()->ReportMessage(MessageTemplate::kStaticPrototype); |
| 3320 *ok = false; | 3497 *ok = false; |
| 3321 return; | 3498 return; |
| 3322 } | 3499 } |
| 3323 } else if (IsConstructor()) { | 3500 } else if (IsConstructor()) { |
| 3324 if (is_generator || type == kAccessorProperty) { | 3501 const bool is_generator = IsGeneratorMethod(method_type); |
| 3502 const bool is_async = IsAsyncMethod(method_type); |
| 3503 if (is_generator || is_async || type == kAccessorProperty) { |
| 3325 MessageTemplate::Template msg = | 3504 MessageTemplate::Template msg = |
| 3326 is_generator ? MessageTemplate::kConstructorIsGenerator | 3505 is_generator ? MessageTemplate::kConstructorIsGenerator |
| 3327 : MessageTemplate::kConstructorIsAccessor; | 3506 : is_async ? MessageTemplate::kConstructorIsAsync |
| 3507 : MessageTemplate::kConstructorIsAccessor; |
| 3328 this->parser()->ReportMessage(msg); | 3508 this->parser()->ReportMessage(msg); |
| 3329 *ok = false; | 3509 *ok = false; |
| 3330 return; | 3510 return; |
| 3331 } | 3511 } |
| 3332 if (has_seen_constructor_) { | 3512 if (has_seen_constructor_) { |
| 3333 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); | 3513 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); |
| 3334 *ok = false; | 3514 *ok = false; |
| 3335 return; | 3515 return; |
| 3336 } | 3516 } |
| 3337 has_seen_constructor_ = true; | 3517 has_seen_constructor_ = true; |
| 3338 return; | 3518 return; |
| 3339 } | 3519 } |
| 3340 } | 3520 } |
| 3341 | 3521 |
| 3342 | 3522 |
| 3343 } // namespace internal | 3523 } // namespace internal |
| 3344 } // namespace v8 | 3524 } // namespace v8 |
| 3345 | 3525 |
| 3346 #endif // V8_PARSING_PARSER_BASE_H | 3526 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |