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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 ExpressionT ParseNewTargetExpression(bool* ok); | 795 ExpressionT ParseNewTargetExpression(bool* ok); |
796 ExpressionT ParseStrongInitializationExpression( | 796 ExpressionT ParseStrongInitializationExpression( |
797 ExpressionClassifier* classifier, bool* ok); | 797 ExpressionClassifier* classifier, bool* ok); |
798 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 798 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
799 bool* ok); | 799 bool* ok); |
800 | 800 |
801 void ParseFormalParameter(FormalParametersT* parameters, | 801 void ParseFormalParameter(FormalParametersT* parameters, |
802 ExpressionClassifier* classifier, bool* ok); | 802 ExpressionClassifier* classifier, bool* ok); |
803 void ParseFormalParameterList(FormalParametersT* parameters, | 803 void ParseFormalParameterList(FormalParametersT* parameters, |
804 ExpressionClassifier* classifier, bool* ok); | 804 ExpressionClassifier* classifier, bool* ok); |
805 void CheckArityRestrictions( | 805 void CheckArityRestrictions(int param_count, |
806 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 806 FunctionLiteral::FunctionType function_type, |
807 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 807 bool has_rest, int formals_start_pos, |
| 808 int formals_end_pos, bool* ok); |
808 | 809 |
809 bool IsNextLetKeyword(); | 810 bool IsNextLetKeyword(); |
810 | 811 |
811 // Checks if the expression is a valid reference expression (e.g., on the | 812 // Checks if the expression is a valid reference expression (e.g., on the |
812 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 813 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
813 // we allow calls for web compatibility and rewrite them to a runtime throw. | 814 // we allow calls for web compatibility and rewrite them to a runtime throw. |
814 ExpressionT CheckAndRewriteReferenceExpression( | 815 ExpressionT CheckAndRewriteReferenceExpression( |
815 ExpressionT expression, int beg_pos, int end_pos, | 816 ExpressionT expression, int beg_pos, int end_pos, |
816 MessageTemplate::Template message, bool* ok); | 817 MessageTemplate::Template message, bool* ok); |
817 ExpressionT ClassifyAndRewriteReferenceExpression( | 818 ExpressionT ClassifyAndRewriteReferenceExpression( |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1730 : FunctionKind::kConciseMethod; | 1731 : FunctionKind::kConciseMethod; |
1731 | 1732 |
1732 if (in_class && !is_static && this->IsConstructor(*name)) { | 1733 if (in_class && !is_static && this->IsConstructor(*name)) { |
1733 *has_seen_constructor = true; | 1734 *has_seen_constructor = true; |
1734 kind = has_extends ? FunctionKind::kSubclassConstructor | 1735 kind = has_extends ? FunctionKind::kSubclassConstructor |
1735 : FunctionKind::kBaseConstructor; | 1736 : FunctionKind::kBaseConstructor; |
1736 } | 1737 } |
1737 | 1738 |
1738 value = this->ParseFunctionLiteral( | 1739 value = this->ParseFunctionLiteral( |
1739 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 1740 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
1740 RelocInfo::kNoPosition, FunctionLiteral::kAnonymousExpression, | 1741 RelocInfo::kNoPosition, FunctionLiteral::kMethod, language_mode(), |
1741 FunctionLiteral::kNormalArity, language_mode(), | |
1742 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1742 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1743 | 1743 |
1744 return factory()->NewObjectLiteralProperty(name_expression, value, | 1744 return factory()->NewObjectLiteralProperty(name_expression, value, |
1745 ObjectLiteralProperty::COMPUTED, | 1745 ObjectLiteralProperty::COMPUTED, |
1746 is_static, *is_computed_name); | 1746 is_static, *is_computed_name); |
1747 } | 1747 } |
1748 | 1748 |
1749 if (in_class && name_token == Token::STATIC && !is_static) { | 1749 if (in_class && name_token == Token::STATIC && !is_static) { |
1750 // ClassElement (static) | 1750 // ClassElement (static) |
1751 // 'static' MethodDefinition | 1751 // 'static' MethodDefinition |
(...skipping 20 matching lines...) Expand all Loading... |
1772 | 1772 |
1773 if (!*is_computed_name) { | 1773 if (!*is_computed_name) { |
1774 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 1774 checker->CheckProperty(name_token, kAccessorProperty, is_static, |
1775 is_generator, | 1775 is_generator, |
1776 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1776 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1777 } | 1777 } |
1778 | 1778 |
1779 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 1779 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
1780 *name, scanner()->location(), kSkipFunctionNameCheck, | 1780 *name, scanner()->location(), kSkipFunctionNameCheck, |
1781 FunctionKind::kAccessorFunction, RelocInfo::kNoPosition, | 1781 FunctionKind::kAccessorFunction, RelocInfo::kNoPosition, |
1782 FunctionLiteral::kAnonymousExpression, | 1782 is_get ? FunctionLiteral::kGetter : FunctionLiteral::kSetter, |
1783 is_get ? FunctionLiteral::kGetterArity : FunctionLiteral::kSetterArity, | |
1784 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1783 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1785 | 1784 |
1786 // Make sure the name expression is a string since we need a Name for | 1785 // Make sure the name expression is a string since we need a Name for |
1787 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this | 1786 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this |
1788 // statically we can skip the extra runtime check. | 1787 // statically we can skip the extra runtime check. |
1789 if (!*is_computed_name) { | 1788 if (!*is_computed_name) { |
1790 name_expression = | 1789 name_expression = |
1791 factory()->NewStringLiteral(*name, name_expression->position()); | 1790 factory()->NewStringLiteral(*name, name_expression->position()); |
1792 } | 1791 } |
1793 | 1792 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2570 is_generator, &is_strict_reserved_name, CHECK_OK); | 2569 is_generator, &is_strict_reserved_name, CHECK_OK); |
2571 function_name_location = scanner()->location(); | 2570 function_name_location = scanner()->location(); |
2572 function_type = FunctionLiteral::kNamedExpression; | 2571 function_type = FunctionLiteral::kNamedExpression; |
2573 } | 2572 } |
2574 result = this->ParseFunctionLiteral( | 2573 result = this->ParseFunctionLiteral( |
2575 name, function_name_location, | 2574 name, function_name_location, |
2576 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 2575 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
2577 : kFunctionNameValidityUnknown, | 2576 : kFunctionNameValidityUnknown, |
2578 is_generator ? FunctionKind::kGeneratorFunction | 2577 is_generator ? FunctionKind::kGeneratorFunction |
2579 : FunctionKind::kNormalFunction, | 2578 : FunctionKind::kNormalFunction, |
2580 function_token_position, function_type, FunctionLiteral::kNormalArity, | 2579 function_token_position, function_type, language_mode(), CHECK_OK); |
2581 language_mode(), CHECK_OK); | |
2582 } else if (peek() == Token::SUPER) { | 2580 } else if (peek() == Token::SUPER) { |
2583 const bool is_new = false; | 2581 const bool is_new = false; |
2584 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2582 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2585 } else { | 2583 } else { |
2586 result = ParsePrimaryExpression(classifier, CHECK_OK); | 2584 result = ParsePrimaryExpression(classifier, CHECK_OK); |
2587 } | 2585 } |
2588 | 2586 |
2589 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2587 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); |
2590 return result; | 2588 return result; |
2591 } | 2589 } |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2963 } | 2961 } |
2964 } | 2962 } |
2965 } | 2963 } |
2966 | 2964 |
2967 for (int i = 0; i < parameters->Arity(); ++i) { | 2965 for (int i = 0; i < parameters->Arity(); ++i) { |
2968 auto parameter = parameters->at(i); | 2966 auto parameter = parameters->at(i); |
2969 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); | 2967 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
2970 } | 2968 } |
2971 } | 2969 } |
2972 | 2970 |
2973 | |
2974 template <class Traits> | 2971 template <class Traits> |
2975 void ParserBase<Traits>::CheckArityRestrictions( | 2972 void ParserBase<Traits>::CheckArityRestrictions( |
2976 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 2973 int param_count, FunctionLiteral::FunctionType function_type, bool has_rest, |
2977 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { | 2974 int formals_start_pos, int formals_end_pos, bool* ok) { |
2978 switch (arity_restriction) { | 2975 switch (function_type) { |
2979 case FunctionLiteral::kGetterArity: | 2976 case FunctionLiteral::kGetter: |
2980 if (param_count != 0) { | 2977 if (param_count != 0) { |
2981 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2978 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
2982 MessageTemplate::kBadGetterArity); | 2979 MessageTemplate::kBadGetterArity); |
2983 *ok = false; | 2980 *ok = false; |
2984 } | 2981 } |
2985 break; | 2982 break; |
2986 case FunctionLiteral::kSetterArity: | 2983 case FunctionLiteral::kSetter: |
2987 if (param_count != 1) { | 2984 if (param_count != 1) { |
2988 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2985 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
2989 MessageTemplate::kBadSetterArity); | 2986 MessageTemplate::kBadSetterArity); |
2990 *ok = false; | 2987 *ok = false; |
2991 } | 2988 } |
2992 if (has_rest) { | 2989 if (has_rest) { |
2993 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2990 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
2994 MessageTemplate::kBadSetterRestParameter); | 2991 MessageTemplate::kBadSetterRestParameter); |
2995 *ok = false; | 2992 *ok = false; |
2996 } | 2993 } |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3360 return; | 3357 return; |
3361 } | 3358 } |
3362 has_seen_constructor_ = true; | 3359 has_seen_constructor_ = true; |
3363 return; | 3360 return; |
3364 } | 3361 } |
3365 } | 3362 } |
3366 } // namespace internal | 3363 } // namespace internal |
3367 } // namespace v8 | 3364 } // namespace v8 |
3368 | 3365 |
3369 #endif // V8_PARSING_PARSER_BASE_H | 3366 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |