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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 this_location_ = location; | 293 this_location_ = location; |
266 } | 294 } |
267 void set_super_location(Scanner::Location location) { | 295 void set_super_location(Scanner::Location location) { |
268 super_location_ = location; | 296 super_location_ = location; |
269 } | 297 } |
270 void set_return_location(Scanner::Location location) { | 298 void set_return_location(Scanner::Location location) { |
271 return_location_ = location; | 299 return_location_ = location; |
272 } | 300 } |
273 | 301 |
274 bool is_generator() const { return IsGeneratorFunction(kind_); } | 302 bool is_generator() const { return IsGeneratorFunction(kind_); } |
303 bool is_async_function() const { return IsAsyncFunction(kind_); } | |
275 | 304 |
276 FunctionKind kind() const { return kind_; } | 305 FunctionKind kind() const { return kind_; } |
277 FunctionState* outer() const { return outer_function_state_; } | 306 FunctionState* outer() const { return outer_function_state_; } |
278 | 307 |
279 void set_generator_object_variable( | 308 void set_generator_object_variable( |
280 typename Traits::Type::GeneratorVariable* variable) { | 309 typename Traits::Type::GeneratorVariable* variable) { |
281 DCHECK(variable != NULL); | 310 DCHECK(variable != NULL); |
282 DCHECK(is_generator()); | 311 DCHECK(is_generator()); |
283 generator_object_variable_ = variable; | 312 generator_object_variable_ = variable; |
284 } | 313 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 return true; | 601 return true; |
573 } | 602 } |
574 return false; | 603 return false; |
575 } | 604 } |
576 | 605 |
577 bool PeekContextualKeyword(Vector<const char> keyword) { | 606 bool PeekContextualKeyword(Vector<const char> keyword) { |
578 return peek() == Token::IDENTIFIER && | 607 return peek() == Token::IDENTIFIER && |
579 scanner()->is_next_contextual_keyword(keyword); | 608 scanner()->is_next_contextual_keyword(keyword); |
580 } | 609 } |
581 | 610 |
611 bool PeekAheadContextualKeyword(Vector<const char> keyword) { | |
612 return PeekAhead() == Token::IDENTIFIER && | |
613 scanner()->is_next_next_contextual_keyword(keyword); | |
614 } | |
615 | |
582 void ExpectMetaProperty(Vector<const char> property_name, | 616 void ExpectMetaProperty(Vector<const char> property_name, |
583 const char* full_name, int pos, bool* ok); | 617 const char* full_name, int pos, bool* ok); |
584 | 618 |
585 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { | 619 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { |
586 Expect(Token::IDENTIFIER, ok); | 620 Expect(Token::IDENTIFIER, ok); |
587 if (!*ok) return; | 621 if (!*ok) return; |
588 if (!scanner()->is_literal_contextual_keyword(keyword)) { | 622 if (!scanner()->is_literal_contextual_keyword(keyword)) { |
589 ReportUnexpectedToken(scanner()->current_token()); | 623 ReportUnexpectedToken(scanner()->current_token()); |
590 *ok = false; | 624 *ok = false; |
591 } | 625 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 return 0; // 0 precedence will terminate binary expression parsing | 696 return 0; // 0 precedence will terminate binary expression parsing |
663 return Token::Precedence(token); | 697 return Token::Precedence(token); |
664 } | 698 } |
665 | 699 |
666 typename Traits::Type::Factory* factory() { | 700 typename Traits::Type::Factory* factory() { |
667 return function_state_->factory(); | 701 return function_state_->factory(); |
668 } | 702 } |
669 | 703 |
670 LanguageMode language_mode() { return scope_->language_mode(); } | 704 LanguageMode language_mode() { return scope_->language_mode(); } |
671 bool is_generator() const { return function_state_->is_generator(); } | 705 bool is_generator() const { return function_state_->is_generator(); } |
706 bool is_async_function() const { | |
707 return function_state_->is_async_function(); | |
708 } | |
672 | 709 |
673 // Report syntax errors. | 710 // Report syntax errors. |
674 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 711 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
675 ParseErrorType error_type = kSyntaxError) { | 712 ParseErrorType error_type = kSyntaxError) { |
676 Scanner::Location source_location = scanner()->location(); | 713 Scanner::Location source_location = scanner()->location(); |
677 Traits::ReportMessageAt(source_location, message, arg, error_type); | 714 Traits::ReportMessageAt(source_location, message, arg, error_type); |
678 } | 715 } |
679 | 716 |
680 void ReportMessageAt(Scanner::Location location, | 717 void ReportMessageAt(Scanner::Location location, |
681 MessageTemplate::Template message, | 718 MessageTemplate::Template message, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 void ValidateFormalParameterInitializer( | 755 void ValidateFormalParameterInitializer( |
719 const ExpressionClassifier* classifier, bool* ok) { | 756 const ExpressionClassifier* classifier, bool* ok) { |
720 if (!classifier->is_valid_formal_parameter_initializer()) { | 757 if (!classifier->is_valid_formal_parameter_initializer()) { |
721 ReportClassifierError(classifier->formal_parameter_initializer_error()); | 758 ReportClassifierError(classifier->formal_parameter_initializer_error()); |
722 *ok = false; | 759 *ok = false; |
723 } | 760 } |
724 } | 761 } |
725 | 762 |
726 void ValidateBindingPattern(const ExpressionClassifier* classifier, | 763 void ValidateBindingPattern(const ExpressionClassifier* classifier, |
727 bool* ok) { | 764 bool* ok) { |
728 if (!classifier->is_valid_binding_pattern()) { | 765 if (!classifier->is_valid_binding_pattern() || |
729 ReportClassifierError(classifier->binding_pattern_error()); | 766 !classifier->is_valid_async_binding_pattern()) { |
767 const Scanner::Location& a = classifier->binding_pattern_error().location; | |
768 const Scanner::Location& b = | |
769 classifier->async_binding_pattern_error().location; | |
770 if (a.beg_pos < 0 || (b.beg_pos >= 0 && a.beg_pos > b.beg_pos)) { | |
771 ReportClassifierError(classifier->async_binding_pattern_error()); | |
772 } else { | |
773 ReportClassifierError(classifier->binding_pattern_error()); | |
774 } | |
730 *ok = false; | 775 *ok = false; |
731 } | 776 } |
732 } | 777 } |
733 | 778 |
734 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, | 779 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, |
735 bool* ok) { | 780 bool* ok) { |
736 if (!classifier->is_valid_assignment_pattern()) { | 781 if (!classifier->is_valid_assignment_pattern()) { |
737 ReportClassifierError(classifier->assignment_pattern_error()); | 782 ReportClassifierError(classifier->assignment_pattern_error()); |
738 *ok = false; | 783 *ok = false; |
739 } | 784 } |
740 } | 785 } |
741 | 786 |
742 void ValidateFormalParameters(const ExpressionClassifier* classifier, | 787 void ValidateFormalParameters(const ExpressionClassifier* classifier, |
743 LanguageMode language_mode, | 788 LanguageMode language_mode, |
744 bool allow_duplicates, bool* ok) { | 789 bool allow_duplicates, bool* ok) { |
745 if (!allow_duplicates && | 790 if (!allow_duplicates && |
746 !classifier->is_valid_formal_parameter_list_without_duplicates()) { | 791 !classifier->is_valid_formal_parameter_list_without_duplicates()) { |
747 ReportClassifierError(classifier->duplicate_formal_parameter_error()); | 792 ReportClassifierError(classifier->duplicate_formal_parameter_error()); |
748 *ok = false; | 793 *ok = false; |
749 } else if (is_strict(language_mode) && | 794 } else if (is_strict(language_mode) && |
750 !classifier->is_valid_strict_mode_formal_parameters()) { | 795 !classifier->is_valid_strict_mode_formal_parameters()) { |
751 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); | 796 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); |
752 *ok = false; | 797 *ok = false; |
753 } | 798 } |
754 } | 799 } |
755 | 800 |
756 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, | 801 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
757 ExpressionT expr, | 802 ExpressionT expr, |
758 bool parenthesized_formals, bool* ok) { | 803 bool parenthesized_formals, bool is_async, |
804 bool* ok) { | |
759 if (classifier->is_valid_binding_pattern()) { | 805 if (classifier->is_valid_binding_pattern()) { |
760 // A simple arrow formal parameter: IDENTIFIER => BODY. | 806 // A simple arrow formal parameter: IDENTIFIER => BODY. |
761 if (!this->IsIdentifier(expr)) { | 807 if (!this->IsIdentifier(expr)) { |
762 Traits::ReportMessageAt(scanner()->location(), | 808 Traits::ReportMessageAt(scanner()->location(), |
763 MessageTemplate::kUnexpectedToken, | 809 MessageTemplate::kUnexpectedToken, |
764 Token::String(scanner()->current_token())); | 810 Token::String(scanner()->current_token())); |
765 *ok = false; | 811 *ok = false; |
766 } | 812 } |
767 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 813 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
768 // If after parsing the expr, we see an error but the expression is | 814 // If after parsing the expr, we see an error but the expression is |
769 // neither a valid binding pattern nor a valid parenthesized formal | 815 // neither a valid binding pattern nor a valid parenthesized formal |
770 // parameter list, show the "arrow formal parameters" error if the formals | 816 // parameter list, show the "arrow formal parameters" error if the formals |
771 // started with a parenthesis, and the binding pattern error otherwise. | 817 // started with a parenthesis, and the binding pattern error otherwise. |
772 const typename ExpressionClassifier::Error& error = | 818 const typename ExpressionClassifier::Error& error = |
773 parenthesized_formals ? classifier->arrow_formal_parameters_error() | 819 parenthesized_formals ? classifier->arrow_formal_parameters_error() |
774 : classifier->binding_pattern_error(); | 820 : classifier->binding_pattern_error(); |
775 ReportClassifierError(error); | 821 ReportClassifierError(error); |
776 *ok = false; | 822 *ok = false; |
777 } | 823 } |
824 if (is_async && !classifier->is_valid_async_arrow_formal_parameters()) { | |
825 const typename ExpressionClassifier::Error& error = | |
826 classifier->async_arrow_formal_parameters_error(); | |
827 ReportClassifierError(error); | |
828 *ok = false; | |
829 } | |
778 } | 830 } |
779 | 831 |
780 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { | 832 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { |
781 if (!classifier->is_valid_let_pattern()) { | 833 if (!classifier->is_valid_let_pattern()) { |
782 ReportClassifierError(classifier->let_pattern_error()); | 834 ReportClassifierError(classifier->let_pattern_error()); |
783 *ok = false; | 835 *ok = false; |
784 } | 836 } |
785 } | 837 } |
786 | 838 |
787 void CheckNoTailCallExpressions(const ExpressionClassifier* classifier, | 839 void CheckNoTailCallExpressions(const ExpressionClassifier* classifier, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 return ParseIdentifierOrStrictReservedWord(this->is_generator(), | 893 return ParseIdentifierOrStrictReservedWord(this->is_generator(), |
842 is_strict_reserved, ok); | 894 is_strict_reserved, ok); |
843 } | 895 } |
844 | 896 |
845 IdentifierT ParseIdentifierName(bool* ok); | 897 IdentifierT ParseIdentifierName(bool* ok); |
846 | 898 |
847 ExpressionT ParseRegExpLiteral(bool seen_equal, | 899 ExpressionT ParseRegExpLiteral(bool seen_equal, |
848 ExpressionClassifier* classifier, bool* ok); | 900 ExpressionClassifier* classifier, bool* ok); |
849 | 901 |
850 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 902 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
851 bool* ok); | 903 bool* is_async, bool* ok); |
904 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | |
905 bool* ok) { | |
906 bool is_async; | |
907 return ParsePrimaryExpression(classifier, &is_async, ok); | |
908 } | |
852 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 909 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
853 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, | 910 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, |
854 bool* ok); | 911 bool* ok); |
855 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); | 912 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); |
856 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 913 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
857 bool* is_computed_name, | 914 bool* is_await, bool* is_computed_name, |
858 ExpressionClassifier* classifier, bool* ok); | 915 ExpressionClassifier* classifier, bool* ok); |
859 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 916 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
860 ObjectLiteralPropertyT ParsePropertyDefinition( | 917 ObjectLiteralPropertyT ParsePropertyDefinition( |
861 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 918 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
862 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 919 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
863 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 920 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
864 typename Traits::Type::ExpressionList ParseArguments( | 921 typename Traits::Type::ExpressionList ParseArguments( |
922 Scanner::Location* first_spread_pos, bool maybe_arrow, | |
923 ExpressionClassifier* classifier, bool* ok); | |
924 typename Traits::Type::ExpressionList ParseArguments( | |
865 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 925 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
866 bool* ok); | 926 bool* ok) { |
927 return ParseArguments(first_spread_pos, false, classifier, ok); | |
928 } | |
867 | 929 |
868 ExpressionT ParseAssignmentExpression(bool accept_IN, | 930 ExpressionT ParseAssignmentExpression(bool accept_IN, |
869 ExpressionClassifier* classifier, | 931 ExpressionClassifier* classifier, |
870 bool* ok); | 932 bool* ok); |
871 ExpressionT ParseYieldExpression(bool accept_IN, | 933 ExpressionT ParseYieldExpression(bool accept_IN, |
872 ExpressionClassifier* classifier, bool* ok); | 934 ExpressionClassifier* classifier, bool* ok); |
873 ExpressionT ParseTailCallExpression(ExpressionClassifier* classifier, | 935 ExpressionT ParseTailCallExpression(ExpressionClassifier* classifier, |
874 bool* ok); | 936 bool* ok); |
875 ExpressionT ParseConditionalExpression(bool accept_IN, | 937 ExpressionT ParseConditionalExpression(bool accept_IN, |
876 ExpressionClassifier* classifier, | 938 ExpressionClassifier* classifier, |
877 bool* ok); | 939 bool* ok); |
878 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 940 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
879 ExpressionClassifier* classifier, bool* ok); | 941 ExpressionClassifier* classifier, bool* ok); |
880 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 942 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
881 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 943 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
882 bool* ok); | 944 bool* ok); |
883 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 945 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
884 bool* ok); | 946 bool* ok); |
885 ExpressionT ParseMemberWithNewPrefixesExpression( | 947 ExpressionT ParseMemberWithNewPrefixesExpression( |
886 ExpressionClassifier* classifier, bool* ok); | 948 ExpressionClassifier* classifier, bool* is_async, bool* ok); |
887 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 949 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, |
950 bool* is_async, bool* ok); | |
888 ExpressionT ParseMemberExpressionContinuation( | 951 ExpressionT ParseMemberExpressionContinuation( |
889 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 952 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
953 bool* ok); | |
890 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, | 954 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, |
891 const FormalParametersT& parameters, | 955 const FormalParametersT& parameters, |
956 bool is_async, | |
892 const ExpressionClassifier& classifier, | 957 const ExpressionClassifier& classifier, |
893 bool* ok); | 958 bool* ok); |
894 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 959 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
895 ExpressionClassifier* classifier, bool* ok); | 960 ExpressionClassifier* classifier, bool* ok); |
896 void AddTemplateExpression(ExpressionT); | 961 void AddTemplateExpression(ExpressionT); |
897 ExpressionT ParseSuperExpression(bool is_new, | 962 ExpressionT ParseSuperExpression(bool is_new, |
898 ExpressionClassifier* classifier, bool* ok); | 963 ExpressionClassifier* classifier, bool* ok); |
899 ExpressionT ParseNewTargetExpression(bool* ok); | 964 ExpressionT ParseNewTargetExpression(bool* ok); |
900 | 965 |
901 void ParseFormalParameter(FormalParametersT* parameters, | 966 void ParseFormalParameter(FormalParametersT* parameters, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 bool stack_overflow_; | 1089 bool stack_overflow_; |
1025 | 1090 |
1026 bool allow_lazy_; | 1091 bool allow_lazy_; |
1027 bool allow_natives_; | 1092 bool allow_natives_; |
1028 bool allow_tailcalls_; | 1093 bool allow_tailcalls_; |
1029 bool allow_harmony_restrictive_declarations_; | 1094 bool allow_harmony_restrictive_declarations_; |
1030 bool allow_harmony_do_expressions_; | 1095 bool allow_harmony_do_expressions_; |
1031 bool allow_harmony_for_in_; | 1096 bool allow_harmony_for_in_; |
1032 bool allow_harmony_function_name_; | 1097 bool allow_harmony_function_name_; |
1033 bool allow_harmony_function_sent_; | 1098 bool allow_harmony_function_sent_; |
1099 bool allow_harmony_async_await_; | |
1034 }; | 1100 }; |
1035 | 1101 |
1036 template <class Traits> | 1102 template <class Traits> |
1037 ParserBase<Traits>::FunctionState::FunctionState( | 1103 ParserBase<Traits>::FunctionState::FunctionState( |
1038 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1104 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
1039 FunctionKind kind, typename Traits::Type::Factory* factory) | 1105 FunctionKind kind, typename Traits::Type::Factory* factory) |
1040 : next_materialized_literal_index_(0), | 1106 : next_materialized_literal_index_(0), |
1041 expected_property_count_(0), | 1107 expected_property_count_(0), |
1042 this_location_(Scanner::Location::invalid()), | 1108 this_location_(Scanner::Location::invalid()), |
1043 return_location_(Scanner::Location::invalid()), | 1109 return_location_(Scanner::Location::invalid()), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 } | 1250 } |
1185 if (this->IsArguments(name)) { | 1251 if (this->IsArguments(name)) { |
1186 scope_->RecordArgumentsUsage(); | 1252 scope_->RecordArgumentsUsage(); |
1187 classifier->RecordStrictModeFormalParameterError( | 1253 classifier->RecordStrictModeFormalParameterError( |
1188 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1254 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1189 if (is_strict(language_mode())) { | 1255 if (is_strict(language_mode())) { |
1190 classifier->RecordBindingPatternError( | 1256 classifier->RecordBindingPatternError( |
1191 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1257 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1192 } | 1258 } |
1193 } | 1259 } |
1260 if (this->IsAwait(name)) { | |
1261 if (is_async_function()) { | |
1262 classifier->RecordPatternError( | |
1263 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); | |
1264 } | |
1265 classifier->RecordAsyncArrowFormalParametersError( | |
1266 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); | |
1267 } | |
1194 | 1268 |
1195 if (classifier->duplicate_finder() != nullptr && | 1269 if (classifier->duplicate_finder() != nullptr && |
1196 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1270 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
1197 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1271 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
1198 } | 1272 } |
1199 return name; | 1273 return name; |
1200 } else if (is_sloppy(language_mode()) && | 1274 } else if (is_sloppy(language_mode()) && |
1201 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1275 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
1202 next == Token::ESCAPED_STRICT_RESERVED_WORD || | 1276 next == Token::ESCAPED_STRICT_RESERVED_WORD || |
1203 next == Token::LET || next == Token::STATIC || | 1277 next == Token::LET || next == Token::STATIC || |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 #define DUMMY ) // to make indentation work | 1373 #define DUMMY ) // to make indentation work |
1300 #undef DUMMY | 1374 #undef DUMMY |
1301 | 1375 |
1302 // Used in functions where the return type is not ExpressionT. | 1376 // Used in functions where the return type is not ExpressionT. |
1303 #define CHECK_OK_CUSTOM(x) ok); \ | 1377 #define CHECK_OK_CUSTOM(x) ok); \ |
1304 if (!*ok) return this->x(); \ | 1378 if (!*ok) return this->x(); \ |
1305 ((void)0 | 1379 ((void)0 |
1306 #define DUMMY ) // to make indentation work | 1380 #define DUMMY ) // to make indentation work |
1307 #undef DUMMY | 1381 #undef DUMMY |
1308 | 1382 |
1309 | |
1310 template <class Traits> | 1383 template <class Traits> |
1311 typename ParserBase<Traits>::ExpressionT | 1384 typename ParserBase<Traits>::ExpressionT |
1312 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, | 1385 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
1313 bool* ok) { | 1386 bool* is_async, bool* ok) { |
1314 // PrimaryExpression :: | 1387 // PrimaryExpression :: |
1315 // 'this' | 1388 // 'this' |
1316 // 'null' | 1389 // 'null' |
1317 // 'true' | 1390 // 'true' |
1318 // 'false' | 1391 // 'false' |
1319 // Identifier | 1392 // Identifier |
1320 // Number | 1393 // Number |
1321 // String | 1394 // String |
1322 // ArrayLiteral | 1395 // ArrayLiteral |
1323 // ObjectLiteral | 1396 // ObjectLiteral |
1324 // RegExpLiteral | 1397 // RegExpLiteral |
1325 // ClassLiteral | 1398 // ClassLiteral |
1326 // '(' Expression ')' | 1399 // '(' Expression ')' |
1327 // TemplateLiteral | 1400 // TemplateLiteral |
1328 // do Block | 1401 // do Block |
1402 // AsyncFunctionExpression | |
1329 | 1403 |
1330 int beg_pos = peek_position(); | 1404 int beg_pos = peek_position(); |
1331 switch (peek()) { | 1405 switch (peek()) { |
1332 case Token::THIS: { | 1406 case Token::THIS: { |
1333 BindingPatternUnexpectedToken(classifier); | 1407 BindingPatternUnexpectedToken(classifier); |
1334 Consume(Token::THIS); | 1408 Consume(Token::THIS); |
1335 return this->ThisExpression(scope_, factory(), beg_pos); | 1409 return this->ThisExpression(scope_, factory(), beg_pos); |
1336 } | 1410 } |
1337 | 1411 |
1338 case Token::NULL_LITERAL: | 1412 case Token::NULL_LITERAL: |
1339 case Token::TRUE_LITERAL: | 1413 case Token::TRUE_LITERAL: |
1340 case Token::FALSE_LITERAL: | 1414 case Token::FALSE_LITERAL: |
1341 BindingPatternUnexpectedToken(classifier); | 1415 BindingPatternUnexpectedToken(classifier); |
1342 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); | 1416 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); |
1343 case Token::SMI: | 1417 case Token::SMI: |
1344 case Token::NUMBER: | 1418 case Token::NUMBER: |
1345 BindingPatternUnexpectedToken(classifier); | 1419 BindingPatternUnexpectedToken(classifier); |
1346 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); | 1420 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); |
1347 | 1421 |
1348 case Token::IDENTIFIER: | 1422 case Token::IDENTIFIER: |
1423 if (allow_harmony_async_await() && | |
1424 PeekContextualKeyword(CStrVector("async")) && | |
1425 !scanner()->HasAnyLineTerminatorAfterNext()) { | |
1426 if (PeekAhead() == Token::FUNCTION) { | |
1427 Consume(Token::IDENTIFIER); | |
1428 return this->ParseAsyncFunctionExpression(CHECK_OK); | |
1429 } | |
1430 // CoverCallExpressionAndAsyncArrowHead | |
1431 *is_async = true; | |
1432 } | |
1433 /* Falls through */ | |
1349 case Token::LET: | 1434 case Token::LET: |
1350 case Token::STATIC: | 1435 case Token::STATIC: |
1351 case Token::YIELD: | 1436 case Token::YIELD: |
1352 case Token::AWAIT: | 1437 case Token::AWAIT: |
1353 case Token::ESCAPED_STRICT_RESERVED_WORD: | 1438 case Token::ESCAPED_STRICT_RESERVED_WORD: |
1354 case Token::FUTURE_STRICT_RESERVED_WORD: { | 1439 case Token::FUTURE_STRICT_RESERVED_WORD: { |
1355 // Using eval or arguments in this context is OK even in strict mode. | 1440 // Using eval or arguments in this context is OK even in strict mode. |
1356 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); | 1441 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); |
1357 return this->ExpressionFromIdentifier( | 1442 return this->ExpressionFromIdentifier( |
1358 name, beg_pos, scanner()->location().end_pos, scope_, factory()); | 1443 name, beg_pos, scanner()->location().end_pos, scope_, factory()); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1609 | 1694 |
1610 ExpressionT result = factory()->NewArrayLiteral(values, first_spread_index, | 1695 ExpressionT result = factory()->NewArrayLiteral(values, first_spread_index, |
1611 literal_index, pos); | 1696 literal_index, pos); |
1612 if (first_spread_index >= 0) { | 1697 if (first_spread_index >= 0) { |
1613 result = factory()->NewRewritableExpression(result); | 1698 result = factory()->NewRewritableExpression(result); |
1614 Traits::QueueNonPatternForRewriting(result); | 1699 Traits::QueueNonPatternForRewriting(result); |
1615 } | 1700 } |
1616 return result; | 1701 return result; |
1617 } | 1702 } |
1618 | 1703 |
1619 | |
1620 template <class Traits> | 1704 template <class Traits> |
1621 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( | 1705 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
1622 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name, | 1706 IdentifierT* name, bool* is_get, bool* is_set, bool* is_await, |
1623 ExpressionClassifier* classifier, bool* ok) { | 1707 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { |
1624 Token::Value token = peek(); | 1708 Token::Value token = peek(); |
1625 int pos = peek_position(); | 1709 int pos = peek_position(); |
1626 | 1710 |
1627 // For non computed property names we normalize the name a bit: | 1711 // For non computed property names we normalize the name a bit: |
1628 // | 1712 // |
1629 // "12" -> 12 | 1713 // "12" -> 12 |
1630 // 12.3 -> "12.3" | 1714 // 12.3 -> "12.3" |
1631 // 12.30 -> "12.3" | 1715 // 12.30 -> "12.3" |
1632 // identifier -> "identifier" | 1716 // identifier -> "identifier" |
1633 // | 1717 // |
(...skipping 24 matching lines...) Expand all Loading... | |
1658 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); | 1742 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); |
1659 classifier->Accumulate(&computed_name_classifier, | 1743 classifier->Accumulate(&computed_name_classifier, |
1660 ExpressionClassifier::ExpressionProductions); | 1744 ExpressionClassifier::ExpressionProductions); |
1661 Expect(Token::RBRACK, CHECK_OK); | 1745 Expect(Token::RBRACK, CHECK_OK); |
1662 return expression; | 1746 return expression; |
1663 } | 1747 } |
1664 | 1748 |
1665 default: | 1749 default: |
1666 *name = ParseIdentifierName(CHECK_OK); | 1750 *name = ParseIdentifierName(CHECK_OK); |
1667 scanner()->IsGetOrSet(is_get, is_set); | 1751 scanner()->IsGetOrSet(is_get, is_set); |
1752 if (this->IsAwait(*name)) { | |
1753 *is_await = true; | |
1754 } | |
1668 break; | 1755 break; |
1669 } | 1756 } |
1670 | 1757 |
1671 uint32_t index; | 1758 uint32_t index; |
1672 return this->IsArrayIndex(*name, &index) | 1759 return this->IsArrayIndex(*name, &index) |
1673 ? factory()->NewNumberLiteral(index, pos) | 1760 ? factory()->NewNumberLiteral(index, pos) |
1674 : factory()->NewStringLiteral(*name, pos); | 1761 : factory()->NewStringLiteral(*name, pos); |
1675 } | 1762 } |
1676 | 1763 |
1677 | 1764 |
1678 template <class Traits> | 1765 template <class Traits> |
1679 typename ParserBase<Traits>::ObjectLiteralPropertyT | 1766 typename ParserBase<Traits>::ObjectLiteralPropertyT |
1680 ParserBase<Traits>::ParsePropertyDefinition( | 1767 ParserBase<Traits>::ParsePropertyDefinition( |
1681 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1768 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
1682 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 1769 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
1683 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { | 1770 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { |
1684 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); | 1771 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); |
1685 ExpressionT value = this->EmptyExpression(); | 1772 ExpressionT value = this->EmptyExpression(); |
1686 bool is_get = false; | 1773 bool is_get = false; |
1687 bool is_set = false; | 1774 bool is_set = false; |
1775 bool is_await = false; | |
1688 bool is_generator = Check(Token::MUL); | 1776 bool is_generator = Check(Token::MUL); |
1689 | 1777 |
1690 Token::Value name_token = peek(); | 1778 Token::Value name_token = peek(); |
1779 | |
1780 bool is_async = allow_harmony_async_await() && !is_generator && | |
1781 name_token == Token::IDENTIFIER && | |
1782 PeekContextualKeyword(CStrVector("async")) && | |
1783 !scanner()->HasAnyLineTerminatorAfterNext() && | |
1784 PeekAhead() != Token::LPAREN; | |
1785 | |
1691 int next_beg_pos = scanner()->peek_location().beg_pos; | 1786 int next_beg_pos = scanner()->peek_location().beg_pos; |
1692 int next_end_pos = scanner()->peek_location().end_pos; | 1787 int next_end_pos = scanner()->peek_location().end_pos; |
1693 ExpressionT name_expression = | 1788 ExpressionT name_expression = ParsePropertyName( |
1694 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier, | 1789 name, &is_get, &is_set, &is_await, is_computed_name, classifier, |
1695 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1790 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1696 | 1791 |
1697 if (fni_ != nullptr && !*is_computed_name) { | 1792 if (fni_ != nullptr && !*is_computed_name) { |
1698 this->PushLiteralName(fni_, *name); | 1793 this->PushLiteralName(fni_, *name); |
1699 } | 1794 } |
1700 | 1795 |
1701 if (!in_class && !is_generator) { | 1796 if (!in_class && !is_generator) { |
1702 DCHECK(!is_static); | 1797 DCHECK(!is_static); |
1703 | 1798 |
1704 if (peek() == Token::COLON) { | 1799 if (peek() == Token::COLON) { |
1705 // PropertyDefinition | 1800 // PropertyDefinition |
(...skipping 24 matching lines...) Expand all Loading... | |
1730 // CoverInitializedName | 1825 // CoverInitializedName |
1731 // IdentifierReference Initializer? | 1826 // IdentifierReference Initializer? |
1732 if (classifier->duplicate_finder() != nullptr && | 1827 if (classifier->duplicate_finder() != nullptr && |
1733 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 1828 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
1734 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 1829 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
1735 } | 1830 } |
1736 if (name_token == Token::LET) { | 1831 if (name_token == Token::LET) { |
1737 classifier->RecordLetPatternError( | 1832 classifier->RecordLetPatternError( |
1738 scanner()->location(), MessageTemplate::kLetInLexicalBinding); | 1833 scanner()->location(), MessageTemplate::kLetInLexicalBinding); |
1739 } | 1834 } |
1740 | 1835 if (is_await && is_async_function()) { |
1836 classifier->RecordPatternError( | |
1837 Scanner::Location(next_beg_pos, next_end_pos), | |
1838 MessageTemplate::kAwaitBindingIdentifier); | |
1839 } | |
1741 ExpressionT lhs = this->ExpressionFromIdentifier( | 1840 ExpressionT lhs = this->ExpressionFromIdentifier( |
1742 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1841 *name, next_beg_pos, next_end_pos, scope_, factory()); |
1743 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1842 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1744 | 1843 |
1745 if (peek() == Token::ASSIGN) { | 1844 if (peek() == Token::ASSIGN) { |
1746 Consume(Token::ASSIGN); | 1845 Consume(Token::ASSIGN); |
1747 ExpressionClassifier rhs_classifier(this); | 1846 ExpressionClassifier rhs_classifier(this); |
1748 ExpressionT rhs = this->ParseAssignmentExpression( | 1847 ExpressionT rhs = this->ParseAssignmentExpression( |
1749 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1848 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1750 Traits::RewriteNonPattern(&rhs_classifier, | 1849 Traits::RewriteNonPattern(&rhs_classifier, |
(...skipping 17 matching lines...) Expand all Loading... | |
1768 name_expression, value, ObjectLiteralProperty::COMPUTED, false, | 1867 name_expression, value, ObjectLiteralProperty::COMPUTED, false, |
1769 false); | 1868 false); |
1770 } | 1869 } |
1771 } | 1870 } |
1772 | 1871 |
1773 // Method definitions are never valid in patterns. | 1872 // Method definitions are never valid in patterns. |
1774 classifier->RecordPatternError( | 1873 classifier->RecordPatternError( |
1775 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1874 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
1776 MessageTemplate::kInvalidDestructuringTarget); | 1875 MessageTemplate::kInvalidDestructuringTarget); |
1777 | 1876 |
1877 if (is_async) { | |
1878 DCHECK(!is_generator); | |
1879 DCHECK(!is_get); | |
1880 DCHECK(!is_set); | |
1881 bool dont_care; | |
1882 name_expression = ParsePropertyName( | |
1883 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, | |
1884 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
1885 } | |
1886 | |
1778 if (is_generator || peek() == Token::LPAREN) { | 1887 if (is_generator || peek() == Token::LPAREN) { |
1779 // MethodDefinition | 1888 // MethodDefinition |
1780 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 1889 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
1781 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 1890 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
1782 if (!*is_computed_name) { | 1891 if (!*is_computed_name) { |
1783 checker->CheckProperty(name_token, kMethodProperty, is_static, | 1892 checker->CheckProperty(name_token, kMethodProperty, is_static, |
1784 is_generator, | 1893 is_generator, |
1785 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1894 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1786 } | 1895 } |
1787 | 1896 |
1788 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 1897 FunctionKind kind = is_generator |
1789 : FunctionKind::kConciseMethod; | 1898 ? FunctionKind::kConciseGeneratorMethod |
1899 : is_async ? FunctionKind::kAsyncConciseMethod | |
1900 : FunctionKind::kConciseMethod; | |
1790 | 1901 |
1791 if (in_class && !is_static && this->IsConstructor(*name)) { | 1902 if (in_class && !is_static && this->IsConstructor(*name)) { |
1792 *has_seen_constructor = true; | 1903 *has_seen_constructor = true; |
1793 kind = has_extends ? FunctionKind::kSubclassConstructor | 1904 kind = has_extends ? FunctionKind::kSubclassConstructor |
1794 : FunctionKind::kBaseConstructor; | 1905 : FunctionKind::kBaseConstructor; |
1795 } | 1906 } |
1796 | 1907 |
1797 value = this->ParseFunctionLiteral( | 1908 value = this->ParseFunctionLiteral( |
1798 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 1909 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
1799 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, | 1910 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, |
(...skipping 17 matching lines...) Expand all Loading... | |
1817 | 1928 |
1818 if (is_get || is_set) { | 1929 if (is_get || is_set) { |
1819 // MethodDefinition (Accessors) | 1930 // MethodDefinition (Accessors) |
1820 // get PropertyName '(' ')' '{' FunctionBody '}' | 1931 // get PropertyName '(' ')' '{' FunctionBody '}' |
1821 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 1932 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
1822 *name = this->EmptyIdentifier(); | 1933 *name = this->EmptyIdentifier(); |
1823 bool dont_care = false; | 1934 bool dont_care = false; |
1824 name_token = peek(); | 1935 name_token = peek(); |
1825 | 1936 |
1826 name_expression = ParsePropertyName( | 1937 name_expression = ParsePropertyName( |
1827 name, &dont_care, &dont_care, is_computed_name, classifier, | 1938 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
1828 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1939 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1829 | 1940 |
1830 if (!*is_computed_name) { | 1941 if (!*is_computed_name) { |
1831 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 1942 checker->CheckProperty(name_token, kAccessorProperty, is_static, |
1832 is_generator, | 1943 is_generator, |
1833 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1944 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1834 } | 1945 } |
1835 | 1946 |
1836 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 1947 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
1837 *name, scanner()->location(), kSkipFunctionNameCheck, | 1948 *name, scanner()->location(), kSkipFunctionNameCheck, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1912 | 2023 |
1913 // Computation of literal_index must happen before pre parse bailout. | 2024 // Computation of literal_index must happen before pre parse bailout. |
1914 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2025 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1915 | 2026 |
1916 return factory()->NewObjectLiteral(properties, | 2027 return factory()->NewObjectLiteral(properties, |
1917 literal_index, | 2028 literal_index, |
1918 number_of_boilerplate_properties, | 2029 number_of_boilerplate_properties, |
1919 pos); | 2030 pos); |
1920 } | 2031 } |
1921 | 2032 |
1922 | |
1923 template <class Traits> | 2033 template <class Traits> |
1924 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2034 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
1925 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier, | 2035 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, |
1926 bool* ok) { | 2036 ExpressionClassifier* classifier, bool* ok) { |
1927 // Arguments :: | 2037 // Arguments :: |
1928 // '(' (AssignmentExpression)*[','] ')' | 2038 // '(' (AssignmentExpression)*[','] ')' |
1929 | 2039 |
1930 Scanner::Location spread_arg = Scanner::Location::invalid(); | 2040 Scanner::Location spread_arg = Scanner::Location::invalid(); |
1931 typename Traits::Type::ExpressionList result = | 2041 typename Traits::Type::ExpressionList result = |
1932 this->NewExpressionList(4, zone_); | 2042 this->NewExpressionList(4, zone_); |
1933 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2043 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
1934 bool done = (peek() == Token::RPAREN); | 2044 bool done = (peek() == Token::RPAREN); |
1935 bool was_unspread = false; | 2045 bool was_unspread = false; |
1936 int unspread_sequences_count = 0; | 2046 int unspread_sequences_count = 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1972 } | 2082 } |
1973 } | 2083 } |
1974 Scanner::Location location = scanner_->location(); | 2084 Scanner::Location location = scanner_->location(); |
1975 if (Token::RPAREN != Next()) { | 2085 if (Token::RPAREN != Next()) { |
1976 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); | 2086 ReportMessageAt(location, MessageTemplate::kUnterminatedArgList); |
1977 *ok = false; | 2087 *ok = false; |
1978 return this->NullExpressionList(); | 2088 return this->NullExpressionList(); |
1979 } | 2089 } |
1980 *first_spread_arg_loc = spread_arg; | 2090 *first_spread_arg_loc = spread_arg; |
1981 | 2091 |
1982 if (spread_arg.IsValid()) { | 2092 if ((!maybe_arrow || peek() != Token::ARROW) && spread_arg.IsValid()) { |
1983 // Unspread parameter sequences are translated into array literals in the | 2093 // Unspread parameter sequences are translated into array literals in the |
1984 // parser. Ensure that the number of materialized literals matches between | 2094 // parser. Ensure that the number of materialized literals matches between |
1985 // the parser and preparser | 2095 // the parser and preparser |
1986 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); | 2096 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
1987 } | 2097 } |
1988 | 2098 |
1989 return result; | 2099 return result; |
1990 } | 2100 } |
1991 | 2101 |
1992 // Precedence = 2 | 2102 // Precedence = 2 |
(...skipping 11 matching lines...) Expand all Loading... | |
2004 int lhs_beg_pos = peek_position(); | 2114 int lhs_beg_pos = peek_position(); |
2005 | 2115 |
2006 if (peek() == Token::YIELD && is_generator()) { | 2116 if (peek() == Token::YIELD && is_generator()) { |
2007 return this->ParseYieldExpression(accept_IN, classifier, ok); | 2117 return this->ParseYieldExpression(accept_IN, classifier, ok); |
2008 } | 2118 } |
2009 | 2119 |
2010 FuncNameInferrer::State fni_state(fni_); | 2120 FuncNameInferrer::State fni_state(fni_); |
2011 ParserBase<Traits>::Checkpoint checkpoint(this); | 2121 ParserBase<Traits>::Checkpoint checkpoint(this); |
2012 ExpressionClassifier arrow_formals_classifier(this, | 2122 ExpressionClassifier arrow_formals_classifier(this, |
2013 classifier->duplicate_finder()); | 2123 classifier->duplicate_finder()); |
2124 | |
2125 bool is_async = allow_harmony_async_await() && peek() == Token::IDENTIFIER && | |
2126 PeekContextualKeyword(CStrVector("async")) && | |
2127 !scanner()->HasAnyLineTerminatorAfterNext(); | |
2128 | |
2014 bool parenthesized_formals = peek() == Token::LPAREN; | 2129 bool parenthesized_formals = peek() == Token::LPAREN; |
2015 if (!parenthesized_formals) { | 2130 if (!is_async && !parenthesized_formals) { |
2016 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2131 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
2017 } | 2132 } |
2018 ExpressionT expression = this->ParseConditionalExpression( | 2133 ExpressionT expression = this->ParseConditionalExpression( |
2019 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2134 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2135 | |
2136 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { | |
2137 // async Identifier => AsyncConciseBody | |
2138 IdentifierT name = | |
2139 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); | |
2140 expression = this->ExpressionFromIdentifier( | |
2141 name, position(), scanner()->location().end_pos, scope_, factory()); | |
2142 } | |
2143 | |
2020 if (peek() == Token::ARROW) { | 2144 if (peek() == Token::ARROW) { |
2021 classifier->RecordPatternError(scanner()->peek_location(), | 2145 classifier->RecordPatternError(scanner()->peek_location(), |
2022 MessageTemplate::kUnexpectedToken, | 2146 MessageTemplate::kUnexpectedToken, |
2023 Token::String(Token::ARROW)); | 2147 Token::String(Token::ARROW)); |
2024 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2148 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
2025 parenthesized_formals, CHECK_OK); | 2149 parenthesized_formals, is_async, CHECK_OK); |
2026 // This reads strangely, but is correct: it checks whether any | 2150 // This reads strangely, but is correct: it checks whether any |
2027 // sub-expression of the parameter list failed to be a valid formal | 2151 // sub-expression of the parameter list failed to be a valid formal |
2028 // parameter initializer. Since YieldExpressions are banned anywhere | 2152 // parameter initializer. Since YieldExpressions are banned anywhere |
2029 // in an arrow parameter list, this is correct. | 2153 // in an arrow parameter list, this is correct. |
2030 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to | 2154 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to |
2031 // "YieldExpression", which is its only use. | 2155 // "YieldExpression", which is its only use. |
2032 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); | 2156 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); |
2157 | |
2033 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); | 2158 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
2034 Scope* scope = | 2159 Scope* scope = |
2035 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); | 2160 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); |
2036 // Because the arrow's parameters were parsed in the outer scope, any | 2161 // Because the arrow's parameters were parsed in the outer scope, any |
2037 // usage flags that might have been triggered there need to be copied | 2162 // usage flags that might have been triggered there need to be copied |
2038 // to the arrow scope. | 2163 // to the arrow scope. |
2039 scope_->PropagateUsageFlagsToScope(scope); | 2164 scope_->PropagateUsageFlagsToScope(scope); |
2040 FormalParametersT parameters(scope); | 2165 FormalParametersT parameters(scope); |
2041 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 2166 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
2042 scope->SetHasNonSimpleParameters(); | 2167 scope->SetHasNonSimpleParameters(); |
2043 parameters.is_simple = false; | 2168 parameters.is_simple = false; |
2044 } | 2169 } |
2045 | 2170 |
2046 checkpoint.Restore(¶meters.materialized_literals_count); | 2171 checkpoint.Restore(¶meters.materialized_literals_count); |
2047 | 2172 |
2048 scope->set_start_position(lhs_beg_pos); | 2173 scope->set_start_position(lhs_beg_pos); |
2049 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2174 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2050 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2175 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
2051 &duplicate_loc, CHECK_OK); | 2176 &duplicate_loc, CHECK_OK); |
2052 if (duplicate_loc.IsValid()) { | 2177 if (duplicate_loc.IsValid()) { |
2053 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2178 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2054 duplicate_loc); | 2179 duplicate_loc); |
2055 } | 2180 } |
2056 expression = this->ParseArrowFunctionLiteral( | 2181 expression = this->ParseArrowFunctionLiteral( |
2057 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2182 accept_IN, parameters, is_async, arrow_formals_classifier, CHECK_OK); |
2058 | 2183 |
2059 if (fni_ != nullptr) fni_->Infer(); | 2184 if (fni_ != nullptr) fni_->Infer(); |
2060 | 2185 |
2061 return expression; | 2186 return expression; |
2062 } | 2187 } |
2063 | 2188 |
2064 if (this->IsValidReferenceExpression(expression)) { | 2189 if (this->IsValidReferenceExpression(expression)) { |
2065 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2190 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
2066 } | 2191 } |
2067 | 2192 |
2068 // "expression" was not itself an arrow function parameter list, but it might | 2193 // "expression" was not itself an arrow function parameter list, but it might |
2069 // form part of one. Propagate speculative formal parameter error locations. | 2194 // form part of one. Propagate speculative formal parameter error locations. |
2070 // Do not merge pending non-pattern expressions yet! | 2195 // Do not merge pending non-pattern expressions yet! |
2071 classifier->Accumulate( | 2196 classifier->Accumulate( |
2072 &arrow_formals_classifier, | 2197 &arrow_formals_classifier, |
2073 ExpressionClassifier::StandardProductions | | 2198 ExpressionClassifier::StandardProductions | |
2074 ExpressionClassifier::FormalParametersProductions | | 2199 ExpressionClassifier::FormalParametersProductions | |
2075 ExpressionClassifier::CoverInitializedNameProduction, | 2200 ExpressionClassifier::CoverInitializedNameProduction | |
2201 ExpressionClassifier::AsyncArrowFormalParametersProduction, | |
2076 false); | 2202 false); |
2077 | 2203 |
2078 if (!Token::IsAssignmentOp(peek())) { | 2204 if (!Token::IsAssignmentOp(peek())) { |
2079 // Parsed conditional expression only (no assignment). | 2205 // Parsed conditional expression only (no assignment). |
2080 // Now pending non-pattern expressions must be merged. | 2206 // Now pending non-pattern expressions must be merged. |
2081 classifier->MergeNonPatterns(&arrow_formals_classifier); | 2207 classifier->MergeNonPatterns(&arrow_formals_classifier); |
2082 return expression; | 2208 return expression; |
2083 } | 2209 } |
2084 | 2210 |
2085 // Now pending non-pattern expressions must be discarded. | 2211 // Now pending non-pattern expressions must be discarded. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2368 // PostfixExpression | 2494 // PostfixExpression |
2369 // 'delete' UnaryExpression | 2495 // 'delete' UnaryExpression |
2370 // 'void' UnaryExpression | 2496 // 'void' UnaryExpression |
2371 // 'typeof' UnaryExpression | 2497 // 'typeof' UnaryExpression |
2372 // '++' UnaryExpression | 2498 // '++' UnaryExpression |
2373 // '--' UnaryExpression | 2499 // '--' UnaryExpression |
2374 // '+' UnaryExpression | 2500 // '+' UnaryExpression |
2375 // '-' UnaryExpression | 2501 // '-' UnaryExpression |
2376 // '~' UnaryExpression | 2502 // '~' UnaryExpression |
2377 // '!' UnaryExpression | 2503 // '!' UnaryExpression |
2504 // [+Await] AwaitExpression[?Yield] | |
2378 | 2505 |
2379 Token::Value op = peek(); | 2506 Token::Value op = peek(); |
2380 if (Token::IsUnaryOp(op)) { | 2507 if (Token::IsUnaryOp(op)) { |
2381 BindingPatternUnexpectedToken(classifier); | 2508 BindingPatternUnexpectedToken(classifier); |
2382 ArrowFormalParametersUnexpectedToken(classifier); | 2509 ArrowFormalParametersUnexpectedToken(classifier); |
2383 | 2510 |
2384 op = Next(); | 2511 op = Next(); |
2385 int pos = position(); | 2512 int pos = position(); |
2386 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2513 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
2387 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2514 CheckNoTailCallExpressions(classifier, CHECK_OK); |
(...skipping 27 matching lines...) Expand all Loading... | |
2415 expression, beg_pos, scanner()->location().end_pos, | 2542 expression, beg_pos, scanner()->location().end_pos, |
2416 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2543 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2417 this->MarkExpressionAsAssigned(expression); | 2544 this->MarkExpressionAsAssigned(expression); |
2418 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2545 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2419 | 2546 |
2420 return factory()->NewCountOperation(op, | 2547 return factory()->NewCountOperation(op, |
2421 true /* prefix */, | 2548 true /* prefix */, |
2422 expression, | 2549 expression, |
2423 position()); | 2550 position()); |
2424 | 2551 |
2552 } else if (is_async_function() && peek() == Token::AWAIT) { | |
2553 int beg_pos = peek_position(); | |
2554 switch (PeekAhead()) { | |
2555 case Token::RPAREN: | |
2556 case Token::RBRACK: | |
2557 case Token::RBRACE: | |
2558 case Token::ASSIGN: | |
2559 case Token::COMMA: { | |
2560 Next(); | |
2561 IdentifierT name = this->GetSymbol(scanner()); | |
2562 | |
2563 // Possibly async arrow formals --- record ExpressionError just in case. | |
2564 ExpressionUnexpectedToken(classifier); | |
2565 classifier->RecordAsyncBindingPatternError( | |
2566 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2567 MessageTemplate::kAwaitBindingIdentifier); | |
2568 classifier->RecordAsyncArrowFormalParametersError( | |
2569 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2570 MessageTemplate::kAwaitBindingIdentifier); | |
2571 | |
2572 return this->ExpressionFromIdentifier( | |
2573 name, beg_pos, scanner()->location().end_pos, scope_, factory()); | |
2574 } | |
2575 default: | |
2576 break; | |
2577 } | |
2578 Consume(Token::AWAIT); | |
2579 | |
2580 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); | |
2581 classifier->RecordFormalParameterInitializerError( | |
2582 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2583 MessageTemplate::kAwaitExpressionFormalParameter); | |
2584 | |
2585 return Traits::RewriteAwaitExpression(value, beg_pos); | |
2425 } else { | 2586 } else { |
2426 return this->ParsePostfixExpression(classifier, ok); | 2587 return this->ParsePostfixExpression(classifier, ok); |
2427 } | 2588 } |
2428 } | 2589 } |
2429 | 2590 |
2430 | 2591 |
2431 template <class Traits> | 2592 template <class Traits> |
2432 typename ParserBase<Traits>::ExpressionT | 2593 typename ParserBase<Traits>::ExpressionT |
2433 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, | 2594 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, |
2434 bool* ok) { | 2595 bool* ok) { |
(...skipping 29 matching lines...) Expand all Loading... | |
2464 typename ParserBase<Traits>::ExpressionT | 2625 typename ParserBase<Traits>::ExpressionT |
2465 ParserBase<Traits>::ParseLeftHandSideExpression( | 2626 ParserBase<Traits>::ParseLeftHandSideExpression( |
2466 ExpressionClassifier* classifier, bool* ok) { | 2627 ExpressionClassifier* classifier, bool* ok) { |
2467 // LeftHandSideExpression :: | 2628 // LeftHandSideExpression :: |
2468 // (NewExpression | MemberExpression) ... | 2629 // (NewExpression | MemberExpression) ... |
2469 | 2630 |
2470 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { | 2631 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { |
2471 return this->ParseTailCallExpression(classifier, ok); | 2632 return this->ParseTailCallExpression(classifier, ok); |
2472 } | 2633 } |
2473 | 2634 |
2474 ExpressionT result = | 2635 bool is_async = false; |
2475 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2636 ExpressionT result = this->ParseMemberWithNewPrefixesExpression( |
2637 classifier, &is_async, CHECK_OK); | |
2476 | 2638 |
2477 while (true) { | 2639 while (true) { |
2478 switch (peek()) { | 2640 switch (peek()) { |
2479 case Token::LBRACK: { | 2641 case Token::LBRACK: { |
2480 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2642 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2481 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2643 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2482 BindingPatternUnexpectedToken(classifier); | 2644 BindingPatternUnexpectedToken(classifier); |
2483 ArrowFormalParametersUnexpectedToken(classifier); | 2645 ArrowFormalParametersUnexpectedToken(classifier); |
2484 Consume(Token::LBRACK); | 2646 Consume(Token::LBRACK); |
2485 int pos = position(); | 2647 int pos = position(); |
2486 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2648 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
2487 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2649 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2488 result = factory()->NewProperty(result, index, pos); | 2650 result = factory()->NewProperty(result, index, pos); |
2489 Expect(Token::RBRACK, CHECK_OK); | 2651 Expect(Token::RBRACK, CHECK_OK); |
2490 break; | 2652 break; |
2491 } | 2653 } |
2492 | 2654 |
2493 case Token::LPAREN: { | 2655 case Token::LPAREN: { |
2494 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2656 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2657 int pos; | |
2495 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2658 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2496 BindingPatternUnexpectedToken(classifier); | 2659 BindingPatternUnexpectedToken(classifier); |
2497 ArrowFormalParametersUnexpectedToken(classifier); | |
2498 | |
2499 int pos; | |
2500 if (scanner()->current_token() == Token::IDENTIFIER || | 2660 if (scanner()->current_token() == Token::IDENTIFIER || |
2501 scanner()->current_token() == Token::SUPER) { | 2661 scanner()->current_token() == Token::SUPER) { |
2502 // For call of an identifier we want to report position of | 2662 // For call of an identifier we want to report position of |
2503 // the identifier as position of the call in the stack trace. | 2663 // the identifier as position of the call in the stack trace. |
2504 pos = position(); | 2664 pos = position(); |
2505 } else { | 2665 } else { |
2506 // For other kinds of calls we record position of the parenthesis as | 2666 // For other kinds of calls we record position of the parenthesis as |
2507 // position of the call. Note that this is extremely important for | 2667 // position of the call. Note that this is extremely important for |
2508 // expressions of the form function(){...}() for which call position | 2668 // expressions of the form function(){...}() for which call position |
2509 // should not point to the closing brace otherwise it will intersect | 2669 // should not point to the closing brace otherwise it will intersect |
2510 // with positions recorded for function literal and confuse debugger. | 2670 // with positions recorded for function literal and confuse debugger. |
2511 pos = peek_position(); | 2671 pos = peek_position(); |
2512 // Also the trailing parenthesis are a hint that the function will | 2672 // Also the trailing parenthesis are a hint that the function will |
2513 // be called immediately. If we happen to have parsed a preceding | 2673 // be called immediately. If we happen to have parsed a preceding |
2514 // function literal eagerly, we can also compile it eagerly. | 2674 // function literal eagerly, we can also compile it eagerly. |
2515 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2675 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2516 result->AsFunctionLiteral()->set_should_eager_compile(); | 2676 result->AsFunctionLiteral()->set_should_eager_compile(); |
2517 } | 2677 } |
2518 } | 2678 } |
2519 Scanner::Location spread_pos; | 2679 Scanner::Location spread_pos; |
2520 typename Traits::Type::ExpressionList args = | 2680 typename Traits::Type::ExpressionList args = |
2521 ParseArguments(&spread_pos, classifier, CHECK_OK); | 2681 ParseArguments(&spread_pos, is_async, classifier, CHECK_OK); |
2682 | |
2683 if (V8_UNLIKELY(is_async && peek() == Token::ARROW)) { | |
2684 if (args->length()) { | |
2685 // async ( Arguments ) => ... | |
2686 return Traits::ExpressionListToExpression(args); | |
2687 } | |
2688 // async () => ... | |
2689 return factory()->NewEmptyParentheses(pos); | |
2690 } | |
2691 | |
2692 ArrowFormalParametersUnexpectedToken(classifier); | |
2522 | 2693 |
2523 // Keep track of eval() calls since they disable all local variable | 2694 // Keep track of eval() calls since they disable all local variable |
2524 // optimizations. | 2695 // optimizations. |
2525 // The calls that need special treatment are the | 2696 // The calls that need special treatment are the |
2526 // direct eval calls. These calls are all of the form eval(...), with | 2697 // direct eval calls. These calls are all of the form eval(...), with |
2527 // no explicit receiver. | 2698 // no explicit receiver. |
2528 // These calls are marked as potentially direct eval calls. Whether | 2699 // These calls are marked as potentially direct eval calls. Whether |
2529 // they are actually direct calls to eval is determined at run time. | 2700 // they are actually direct calls to eval is determined at run time. |
2530 this->CheckPossibleEvalCall(result, scope_); | 2701 this->CheckPossibleEvalCall(result, scope_); |
2531 | 2702 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2572 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); | 2743 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); |
2573 break; | 2744 break; |
2574 } | 2745 } |
2575 | 2746 |
2576 default: | 2747 default: |
2577 return result; | 2748 return result; |
2578 } | 2749 } |
2579 } | 2750 } |
2580 } | 2751 } |
2581 | 2752 |
2582 | |
2583 template <class Traits> | 2753 template <class Traits> |
2584 typename ParserBase<Traits>::ExpressionT | 2754 typename ParserBase<Traits>::ExpressionT |
2585 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( | 2755 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( |
2586 ExpressionClassifier* classifier, bool* ok) { | 2756 ExpressionClassifier* classifier, bool* is_async, bool* ok) { |
2587 // NewExpression :: | 2757 // NewExpression :: |
2588 // ('new')+ MemberExpression | 2758 // ('new')+ MemberExpression |
2589 // | 2759 // |
2590 // NewTarget :: | 2760 // NewTarget :: |
2591 // 'new' '.' 'target' | 2761 // 'new' '.' 'target' |
2592 | 2762 |
2593 // The grammar for new expressions is pretty warped. We can have several 'new' | 2763 // The grammar for new expressions is pretty warped. We can have several 'new' |
2594 // keywords following each other, and then a MemberExpression. When we see '(' | 2764 // keywords following each other, and then a MemberExpression. When we see '(' |
2595 // after the MemberExpression, it's associated with the rightmost unassociated | 2765 // after the MemberExpression, it's associated with the rightmost unassociated |
2596 // 'new' to create a NewExpression with arguments. However, a NewExpression | 2766 // 'new' to create a NewExpression with arguments. However, a NewExpression |
(...skipping 12 matching lines...) Expand all Loading... | |
2609 ArrowFormalParametersUnexpectedToken(classifier); | 2779 ArrowFormalParametersUnexpectedToken(classifier); |
2610 Consume(Token::NEW); | 2780 Consume(Token::NEW); |
2611 int new_pos = position(); | 2781 int new_pos = position(); |
2612 ExpressionT result = this->EmptyExpression(); | 2782 ExpressionT result = this->EmptyExpression(); |
2613 if (peek() == Token::SUPER) { | 2783 if (peek() == Token::SUPER) { |
2614 const bool is_new = true; | 2784 const bool is_new = true; |
2615 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2785 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2616 } else if (peek() == Token::PERIOD) { | 2786 } else if (peek() == Token::PERIOD) { |
2617 return ParseNewTargetExpression(CHECK_OK); | 2787 return ParseNewTargetExpression(CHECK_OK); |
2618 } else { | 2788 } else { |
2619 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2789 result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async, |
2790 CHECK_OK); | |
2620 } | 2791 } |
2621 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2792 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2622 if (peek() == Token::LPAREN) { | 2793 if (peek() == Token::LPAREN) { |
2623 // NewExpression with arguments. | 2794 // NewExpression with arguments. |
2624 Scanner::Location spread_pos; | 2795 Scanner::Location spread_pos; |
2625 typename Traits::Type::ExpressionList args = | 2796 typename Traits::Type::ExpressionList args = |
2626 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2797 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
2627 | 2798 |
2628 if (spread_pos.IsValid()) { | 2799 if (spread_pos.IsValid()) { |
2629 args = Traits::PrepareSpreadArguments(args); | 2800 args = Traits::PrepareSpreadArguments(args); |
2630 result = Traits::SpreadCallNew(result, args, new_pos); | 2801 result = Traits::SpreadCallNew(result, args, new_pos); |
2631 } else { | 2802 } else { |
2632 result = factory()->NewCallNew(result, args, new_pos); | 2803 result = factory()->NewCallNew(result, args, new_pos); |
2633 } | 2804 } |
2634 // The expression can still continue with . or [ after the arguments. | 2805 // The expression can still continue with . or [ after the arguments. |
2635 result = | 2806 result = this->ParseMemberExpressionContinuation(result, is_async, |
2636 this->ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2807 classifier, CHECK_OK); |
2637 return result; | 2808 return result; |
2638 } | 2809 } |
2639 // NewExpression without arguments. | 2810 // NewExpression without arguments. |
2640 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2811 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
2641 new_pos); | 2812 new_pos); |
2642 } | 2813 } |
2643 // No 'new' or 'super' keyword. | 2814 // No 'new' or 'super' keyword. |
2644 return this->ParseMemberExpression(classifier, ok); | 2815 return this->ParseMemberExpression(classifier, is_async, ok); |
2645 } | 2816 } |
2646 | 2817 |
2647 | |
2648 template <class Traits> | 2818 template <class Traits> |
2649 typename ParserBase<Traits>::ExpressionT | 2819 typename ParserBase<Traits>::ExpressionT |
2650 ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, | 2820 ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, |
2651 bool* ok) { | 2821 bool* is_async, bool* ok) { |
2652 // MemberExpression :: | 2822 // MemberExpression :: |
2653 // (PrimaryExpression | FunctionLiteral | ClassLiteral) | 2823 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
2654 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* | 2824 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
2655 | 2825 |
2656 // The '[' Expression ']' and '.' Identifier parts are parsed by | 2826 // The '[' Expression ']' and '.' Identifier parts are parsed by |
2657 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 2827 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
2658 // caller. | 2828 // caller. |
2659 | 2829 |
2660 // Parse the initial primary or function expression. | 2830 // Parse the initial primary or function expression. |
2661 ExpressionT result = this->EmptyExpression(); | 2831 ExpressionT result = this->EmptyExpression(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2698 name, function_name_location, | 2868 name, function_name_location, |
2699 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 2869 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
2700 : kFunctionNameValidityUnknown, | 2870 : kFunctionNameValidityUnknown, |
2701 is_generator ? FunctionKind::kGeneratorFunction | 2871 is_generator ? FunctionKind::kGeneratorFunction |
2702 : FunctionKind::kNormalFunction, | 2872 : FunctionKind::kNormalFunction, |
2703 function_token_position, function_type, language_mode(), CHECK_OK); | 2873 function_token_position, function_type, language_mode(), CHECK_OK); |
2704 } else if (peek() == Token::SUPER) { | 2874 } else if (peek() == Token::SUPER) { |
2705 const bool is_new = false; | 2875 const bool is_new = false; |
2706 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2876 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2707 } else { | 2877 } else { |
2708 result = ParsePrimaryExpression(classifier, CHECK_OK); | 2878 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); |
2709 } | 2879 } |
2710 | 2880 |
2711 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2881 result = |
2882 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); | |
2712 return result; | 2883 return result; |
2713 } | 2884 } |
2714 | 2885 |
2715 | 2886 |
2716 template <class Traits> | 2887 template <class Traits> |
2717 typename ParserBase<Traits>::ExpressionT | 2888 typename ParserBase<Traits>::ExpressionT |
2718 ParserBase<Traits>::ParseSuperExpression(bool is_new, | 2889 ParserBase<Traits>::ParseSuperExpression(bool is_new, |
2719 ExpressionClassifier* classifier, | 2890 ExpressionClassifier* classifier, |
2720 bool* ok) { | 2891 bool* ok) { |
2721 Expect(Token::SUPER, CHECK_OK); | 2892 Expect(Token::SUPER, CHECK_OK); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2768 if (!scope_->ReceiverScope()->is_function_scope()) { | 2939 if (!scope_->ReceiverScope()->is_function_scope()) { |
2769 ReportMessageAt(scanner()->location(), | 2940 ReportMessageAt(scanner()->location(), |
2770 MessageTemplate::kUnexpectedNewTarget); | 2941 MessageTemplate::kUnexpectedNewTarget); |
2771 *ok = false; | 2942 *ok = false; |
2772 return this->EmptyExpression(); | 2943 return this->EmptyExpression(); |
2773 } | 2944 } |
2774 | 2945 |
2775 return this->NewTargetExpression(scope_, factory(), pos); | 2946 return this->NewTargetExpression(scope_, factory(), pos); |
2776 } | 2947 } |
2777 | 2948 |
2778 | |
Dan Ehrenberg
2016/05/06 00:08:56
Add back irrelevant blank line removals.
| |
2779 template <class Traits> | 2949 template <class Traits> |
2780 typename ParserBase<Traits>::ExpressionT | 2950 typename ParserBase<Traits>::ExpressionT |
2781 ParserBase<Traits>::ParseMemberExpressionContinuation( | 2951 ParserBase<Traits>::ParseMemberExpressionContinuation( |
2782 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) { | 2952 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
2953 bool* ok) { | |
2783 // Parses this part of MemberExpression: | 2954 // Parses this part of MemberExpression: |
2784 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2955 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
2785 while (true) { | 2956 while (true) { |
2786 switch (peek()) { | 2957 switch (peek()) { |
2787 case Token::LBRACK: { | 2958 case Token::LBRACK: { |
2959 *is_async = false; | |
2788 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2960 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2789 BindingPatternUnexpectedToken(classifier); | 2961 BindingPatternUnexpectedToken(classifier); |
2790 ArrowFormalParametersUnexpectedToken(classifier); | 2962 ArrowFormalParametersUnexpectedToken(classifier); |
2791 | 2963 |
2792 Consume(Token::LBRACK); | 2964 Consume(Token::LBRACK); |
2793 int pos = position(); | 2965 int pos = position(); |
2794 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2966 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2795 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2967 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2796 expression = factory()->NewProperty(expression, index, pos); | 2968 expression = factory()->NewProperty(expression, index, pos); |
2797 if (fni_ != NULL) { | 2969 if (fni_ != NULL) { |
2798 this->PushPropertyName(fni_, index); | 2970 this->PushPropertyName(fni_, index); |
2799 } | 2971 } |
2800 Expect(Token::RBRACK, CHECK_OK); | 2972 Expect(Token::RBRACK, CHECK_OK); |
2801 break; | 2973 break; |
2802 } | 2974 } |
2803 case Token::PERIOD: { | 2975 case Token::PERIOD: { |
2976 *is_async = false; | |
2804 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2977 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2805 BindingPatternUnexpectedToken(classifier); | 2978 BindingPatternUnexpectedToken(classifier); |
2806 ArrowFormalParametersUnexpectedToken(classifier); | 2979 ArrowFormalParametersUnexpectedToken(classifier); |
2807 | 2980 |
2808 Consume(Token::PERIOD); | 2981 Consume(Token::PERIOD); |
2809 int pos = position(); | 2982 int pos = position(); |
2810 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2983 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2811 expression = factory()->NewProperty( | 2984 expression = factory()->NewProperty( |
2812 expression, factory()->NewStringLiteral(name, pos), pos); | 2985 expression, factory()->NewStringLiteral(name, pos), pos); |
2813 if (fni_ != NULL) { | 2986 if (fni_ != NULL) { |
2814 this->PushLiteralName(fni_, name); | 2987 this->PushLiteralName(fni_, name); |
2815 } | 2988 } |
2816 break; | 2989 break; |
2817 } | 2990 } |
2818 case Token::TEMPLATE_SPAN: | 2991 case Token::TEMPLATE_SPAN: |
2819 case Token::TEMPLATE_TAIL: { | 2992 case Token::TEMPLATE_TAIL: { |
2993 *is_async = false; | |
2820 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2994 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2821 BindingPatternUnexpectedToken(classifier); | 2995 BindingPatternUnexpectedToken(classifier); |
2822 ArrowFormalParametersUnexpectedToken(classifier); | 2996 ArrowFormalParametersUnexpectedToken(classifier); |
2823 int pos; | 2997 int pos; |
2824 if (scanner()->current_token() == Token::IDENTIFIER) { | 2998 if (scanner()->current_token() == Token::IDENTIFIER) { |
2825 pos = position(); | 2999 pos = position(); |
2826 } else { | 3000 } else { |
2827 pos = peek_position(); | 3001 pos = peek_position(); |
2828 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 3002 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2829 // If the tag function looks like an IIFE, set_parenthesized() to | 3003 // If the tag function looks like an IIFE, set_parenthesized() to |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2978 case Token::STATIC: | 3152 case Token::STATIC: |
2979 case Token::LET: // Yes, you can do let let = ... in sloppy mode | 3153 case Token::LET: // Yes, you can do let let = ... in sloppy mode |
2980 case Token::YIELD: | 3154 case Token::YIELD: |
2981 case Token::AWAIT: | 3155 case Token::AWAIT: |
2982 return true; | 3156 return true; |
2983 default: | 3157 default: |
2984 return false; | 3158 return false; |
2985 } | 3159 } |
2986 } | 3160 } |
2987 | 3161 |
2988 | |
2989 template <class Traits> | 3162 template <class Traits> |
2990 typename ParserBase<Traits>::ExpressionT | 3163 typename ParserBase<Traits>::ExpressionT |
2991 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3164 ParserBase<Traits>::ParseArrowFunctionLiteral( |
2992 bool accept_IN, const FormalParametersT& formal_parameters, | 3165 bool accept_IN, const FormalParametersT& formal_parameters, bool is_async, |
2993 const ExpressionClassifier& formals_classifier, bool* ok) { | 3166 const ExpressionClassifier& formals_classifier, bool* ok) { |
2994 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3167 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
2995 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3168 // ASI inserts `;` after arrow parameters if a line terminator is found. |
2996 // `=> ...` is never a valid expression, so report as syntax error. | 3169 // `=> ...` is never a valid expression, so report as syntax error. |
2997 // If next token is not `=>`, it's a syntax error anyways. | 3170 // If next token is not `=>`, it's a syntax error anyways. |
2998 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3171 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
2999 *ok = false; | 3172 *ok = false; |
3000 return this->EmptyExpression(); | 3173 return this->EmptyExpression(); |
3001 } | 3174 } |
3002 | 3175 |
3003 typename Traits::Type::StatementList body; | 3176 typename Traits::Type::StatementList body; |
3004 int num_parameters = formal_parameters.scope->num_parameters(); | 3177 int num_parameters = formal_parameters.scope->num_parameters(); |
3005 int materialized_literal_count = -1; | 3178 int materialized_literal_count = -1; |
3006 int expected_property_count = -1; | 3179 int expected_property_count = -1; |
3007 Scanner::Location super_loc; | 3180 Scanner::Location super_loc; |
3008 | 3181 |
3009 { | 3182 { |
3010 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3183 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3011 FunctionState function_state(&function_state_, &scope_, | 3184 FunctionState function_state( |
3012 formal_parameters.scope, kArrowFunction, | 3185 &function_state_, &scope_, formal_parameters.scope, |
3013 &function_factory); | 3186 is_async ? kAsyncArrowFunction : kArrowFunction, &function_factory); |
3014 | 3187 |
3015 function_state.SkipMaterializedLiterals( | 3188 function_state.SkipMaterializedLiterals( |
3016 formal_parameters.materialized_literals_count); | 3189 formal_parameters.materialized_literals_count); |
3017 | 3190 |
3018 this->ReindexLiterals(formal_parameters); | 3191 this->ReindexLiterals(formal_parameters); |
3019 | 3192 |
3020 Expect(Token::ARROW, CHECK_OK); | 3193 Expect(Token::ARROW, CHECK_OK); |
3021 | 3194 |
3022 if (peek() == Token::LBRACE) { | 3195 if (peek() == Token::LBRACE) { |
3023 // Multiple statement body | 3196 // Multiple statement body |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3311 has_seen_constructor_ = true; | 3484 has_seen_constructor_ = true; |
3312 return; | 3485 return; |
3313 } | 3486 } |
3314 } | 3487 } |
3315 | 3488 |
3316 | 3489 |
3317 } // namespace internal | 3490 } // namespace internal |
3318 } // namespace v8 | 3491 } // namespace v8 |
3319 | 3492 |
3320 #endif // V8_PARSING_PARSER_BASE_H | 3493 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |