| 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 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 if (in_class && !is_static && this->IsConstructor(*name)) { | 1751 if (in_class && !is_static && this->IsConstructor(*name)) { |
| 1752 *has_seen_constructor = true; | 1752 *has_seen_constructor = true; |
| 1753 kind = has_extends ? FunctionKind::kSubclassConstructor | 1753 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 1754 : FunctionKind::kBaseConstructor; | 1754 : FunctionKind::kBaseConstructor; |
| 1755 } | 1755 } |
| 1756 | 1756 |
| 1757 if (!in_class) kind = WithObjectLiteralBit(kind); | 1757 if (!in_class) kind = WithObjectLiteralBit(kind); |
| 1758 | 1758 |
| 1759 value = this->ParseFunctionLiteral( | 1759 value = this->ParseFunctionLiteral( |
| 1760 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 1760 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 1761 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 1761 RelocInfo::kNoPosition, FunctionLiteral::kAnonymousExpression, |
| 1762 FunctionLiteral::NORMAL_ARITY, language_mode(), | 1762 FunctionLiteral::kNormalArity, language_mode(), |
| 1763 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1763 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1764 | 1764 |
| 1765 return factory()->NewObjectLiteralProperty(name_expression, value, | 1765 return factory()->NewObjectLiteralProperty(name_expression, value, |
| 1766 ObjectLiteralProperty::COMPUTED, | 1766 ObjectLiteralProperty::COMPUTED, |
| 1767 is_static, *is_computed_name); | 1767 is_static, *is_computed_name); |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 if (in_class && name_is_static && !is_static) { | 1770 if (in_class && name_is_static && !is_static) { |
| 1771 // ClassElement (static) | 1771 // ClassElement (static) |
| 1772 // 'static' MethodDefinition | 1772 // 'static' MethodDefinition |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1791 if (!*is_computed_name) { | 1791 if (!*is_computed_name) { |
| 1792 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 1792 checker->CheckProperty(name_token, kAccessorProperty, is_static, |
| 1793 is_generator, | 1793 is_generator, |
| 1794 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1794 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1795 } | 1795 } |
| 1796 | 1796 |
| 1797 FunctionKind kind = FunctionKind::kAccessorFunction; | 1797 FunctionKind kind = FunctionKind::kAccessorFunction; |
| 1798 if (!in_class) kind = WithObjectLiteralBit(kind); | 1798 if (!in_class) kind = WithObjectLiteralBit(kind); |
| 1799 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 1799 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
| 1800 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 1800 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 1801 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 1801 RelocInfo::kNoPosition, FunctionLiteral::kAnonymousExpression, |
| 1802 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, | 1802 is_get ? FunctionLiteral::kGetterArity : FunctionLiteral::kSetterArity, |
| 1803 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1803 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1804 | 1804 |
| 1805 // Make sure the name expression is a string since we need a Name for | 1805 // Make sure the name expression is a string since we need a Name for |
| 1806 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this | 1806 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this |
| 1807 // statically we can skip the extra runtime check. | 1807 // statically we can skip the extra runtime check. |
| 1808 if (!*is_computed_name) { | 1808 if (!*is_computed_name) { |
| 1809 name_expression = | 1809 name_expression = |
| 1810 factory()->NewStringLiteral(*name, name_expression->position()); | 1810 factory()->NewStringLiteral(*name, name_expression->position()); |
| 1811 } | 1811 } |
| 1812 | 1812 |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2557 BindingPatternUnexpectedToken(classifier); | 2557 BindingPatternUnexpectedToken(classifier); |
| 2558 ArrowFormalParametersUnexpectedToken(classifier); | 2558 ArrowFormalParametersUnexpectedToken(classifier); |
| 2559 | 2559 |
| 2560 Consume(Token::FUNCTION); | 2560 Consume(Token::FUNCTION); |
| 2561 int function_token_position = position(); | 2561 int function_token_position = position(); |
| 2562 bool is_generator = Check(Token::MUL); | 2562 bool is_generator = Check(Token::MUL); |
| 2563 IdentifierT name = this->EmptyIdentifier(); | 2563 IdentifierT name = this->EmptyIdentifier(); |
| 2564 bool is_strict_reserved_name = false; | 2564 bool is_strict_reserved_name = false; |
| 2565 Scanner::Location function_name_location = Scanner::Location::invalid(); | 2565 Scanner::Location function_name_location = Scanner::Location::invalid(); |
| 2566 FunctionLiteral::FunctionType function_type = | 2566 FunctionLiteral::FunctionType function_type = |
| 2567 FunctionLiteral::ANONYMOUS_EXPRESSION; | 2567 FunctionLiteral::kAnonymousExpression; |
| 2568 if (peek_any_identifier()) { | 2568 if (peek_any_identifier()) { |
| 2569 name = ParseIdentifierOrStrictReservedWord( | 2569 name = ParseIdentifierOrStrictReservedWord( |
| 2570 is_generator, &is_strict_reserved_name, CHECK_OK); | 2570 is_generator, &is_strict_reserved_name, CHECK_OK); |
| 2571 function_name_location = scanner()->location(); | 2571 function_name_location = scanner()->location(); |
| 2572 function_type = FunctionLiteral::NAMED_EXPRESSION; | 2572 function_type = FunctionLiteral::kNamedExpression; |
| 2573 } | 2573 } |
| 2574 result = this->ParseFunctionLiteral( | 2574 result = this->ParseFunctionLiteral( |
| 2575 name, function_name_location, | 2575 name, function_name_location, |
| 2576 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 2576 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
| 2577 : kFunctionNameValidityUnknown, | 2577 : kFunctionNameValidityUnknown, |
| 2578 is_generator ? FunctionKind::kGeneratorFunction | 2578 is_generator ? FunctionKind::kGeneratorFunction |
| 2579 : FunctionKind::kNormalFunction, | 2579 : FunctionKind::kNormalFunction, |
| 2580 function_token_position, function_type, FunctionLiteral::NORMAL_ARITY, | 2580 function_token_position, function_type, FunctionLiteral::kNormalArity, |
| 2581 language_mode(), CHECK_OK); | 2581 language_mode(), CHECK_OK); |
| 2582 } else if (peek() == Token::SUPER) { | 2582 } else if (peek() == Token::SUPER) { |
| 2583 const bool is_new = false; | 2583 const bool is_new = false; |
| 2584 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2584 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
| 2585 } else { | 2585 } else { |
| 2586 result = ParsePrimaryExpression(classifier, CHECK_OK); | 2586 result = ParsePrimaryExpression(classifier, CHECK_OK); |
| 2587 } | 2587 } |
| 2588 | 2588 |
| 2589 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); | 2589 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); |
| 2590 return result; | 2590 return result; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2943 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); | 2943 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
| 2944 } | 2944 } |
| 2945 } | 2945 } |
| 2946 | 2946 |
| 2947 | 2947 |
| 2948 template <class Traits> | 2948 template <class Traits> |
| 2949 void ParserBase<Traits>::CheckArityRestrictions( | 2949 void ParserBase<Traits>::CheckArityRestrictions( |
| 2950 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 2950 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 2951 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { | 2951 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { |
| 2952 switch (arity_restriction) { | 2952 switch (arity_restriction) { |
| 2953 case FunctionLiteral::GETTER_ARITY: | 2953 case FunctionLiteral::kGetterArity: |
| 2954 if (param_count != 0) { | 2954 if (param_count != 0) { |
| 2955 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2955 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
| 2956 MessageTemplate::kBadGetterArity); | 2956 MessageTemplate::kBadGetterArity); |
| 2957 *ok = false; | 2957 *ok = false; |
| 2958 } | 2958 } |
| 2959 break; | 2959 break; |
| 2960 case FunctionLiteral::SETTER_ARITY: | 2960 case FunctionLiteral::kSetterArity: |
| 2961 if (param_count != 1) { | 2961 if (param_count != 1) { |
| 2962 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2962 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
| 2963 MessageTemplate::kBadSetterArity); | 2963 MessageTemplate::kBadSetterArity); |
| 2964 *ok = false; | 2964 *ok = false; |
| 2965 } | 2965 } |
| 2966 if (has_rest) { | 2966 if (has_rest) { |
| 2967 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 2967 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
| 2968 MessageTemplate::kBadSetterRestParameter); | 2968 MessageTemplate::kBadSetterRestParameter); |
| 2969 *ok = false; | 2969 *ok = false; |
| 2970 } | 2970 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3038 body = this->NewStatementList(0, zone()); | 3038 body = this->NewStatementList(0, zone()); |
| 3039 this->SkipLazyFunctionBody(&materialized_literal_count, | 3039 this->SkipLazyFunctionBody(&materialized_literal_count, |
| 3040 &expected_property_count, CHECK_OK); | 3040 &expected_property_count, CHECK_OK); |
| 3041 if (formal_parameters.materialized_literals_count > 0) { | 3041 if (formal_parameters.materialized_literals_count > 0) { |
| 3042 materialized_literal_count += | 3042 materialized_literal_count += |
| 3043 formal_parameters.materialized_literals_count; | 3043 formal_parameters.materialized_literals_count; |
| 3044 } | 3044 } |
| 3045 } else { | 3045 } else { |
| 3046 body = this->ParseEagerFunctionBody( | 3046 body = this->ParseEagerFunctionBody( |
| 3047 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, | 3047 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
| 3048 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); | 3048 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK); |
| 3049 materialized_literal_count = | 3049 materialized_literal_count = |
| 3050 function_state.materialized_literal_count(); | 3050 function_state.materialized_literal_count(); |
| 3051 expected_property_count = function_state.expected_property_count(); | 3051 expected_property_count = function_state.expected_property_count(); |
| 3052 } | 3052 } |
| 3053 } else { | 3053 } else { |
| 3054 // Single-expression body | 3054 // Single-expression body |
| 3055 int pos = position(); | 3055 int pos = position(); |
| 3056 parenthesized_function_ = false; | 3056 parenthesized_function_ = false; |
| 3057 ExpressionClassifier classifier; | 3057 ExpressionClassifier classifier; |
| 3058 ExpressionT expression = | 3058 ExpressionT expression = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3082 scanner()->location().end_pos, CHECK_OK); | 3082 scanner()->location().end_pos, CHECK_OK); |
| 3083 } | 3083 } |
| 3084 if (is_strict(language_mode()) || allow_harmony_sloppy()) { | 3084 if (is_strict(language_mode()) || allow_harmony_sloppy()) { |
| 3085 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); | 3085 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); |
| 3086 } | 3086 } |
| 3087 | 3087 |
| 3088 Traits::RewriteDestructuringAssignments(); | 3088 Traits::RewriteDestructuringAssignments(); |
| 3089 } | 3089 } |
| 3090 | 3090 |
| 3091 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 3091 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
| 3092 this->EmptyIdentifierString(), ast_value_factory(), | 3092 this->EmptyIdentifierString(), formal_parameters.scope, body, |
| 3093 formal_parameters.scope, body, materialized_literal_count, | 3093 materialized_literal_count, expected_property_count, num_parameters, |
| 3094 expected_property_count, num_parameters, | |
| 3095 FunctionLiteral::kNoDuplicateParameters, | 3094 FunctionLiteral::kNoDuplicateParameters, |
| 3096 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 3095 FunctionLiteral::kAnonymousExpression, |
| 3097 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, | 3096 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, |
| 3098 formal_parameters.scope->start_position()); | 3097 formal_parameters.scope->start_position()); |
| 3099 | 3098 |
| 3100 function_literal->set_function_token_position( | 3099 function_literal->set_function_token_position( |
| 3101 formal_parameters.scope->start_position()); | 3100 formal_parameters.scope->start_position()); |
| 3102 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); | 3101 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); |
| 3103 | 3102 |
| 3104 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3103 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
| 3105 | 3104 |
| 3106 return function_literal; | 3105 return function_literal; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3339 return; | 3338 return; |
| 3340 } | 3339 } |
| 3341 has_seen_constructor_ = true; | 3340 has_seen_constructor_ = true; |
| 3342 return; | 3341 return; |
| 3343 } | 3342 } |
| 3344 } | 3343 } |
| 3345 } // namespace internal | 3344 } // namespace internal |
| 3346 } // namespace v8 | 3345 } // namespace v8 |
| 3347 | 3346 |
| 3348 #endif // V8_PARSING_PARSER_BASE_H | 3347 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |