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