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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2604 int next_beg_pos = scanner()->peek_location().beg_pos; | 2604 int next_beg_pos = scanner()->peek_location().beg_pos; |
2605 int next_end_pos = scanner()->peek_location().end_pos; | 2605 int next_end_pos = scanner()->peek_location().end_pos; |
2606 ExpressionT name_expression = ParsePropertyName( | 2606 ExpressionT name_expression = ParsePropertyName( |
2607 &name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, | 2607 &name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, |
2608 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2608 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2609 | 2609 |
2610 if (fni_ != nullptr && !*is_computed_name) { | 2610 if (fni_ != nullptr && !*is_computed_name) { |
2611 this->PushLiteralName(fni_, name); | 2611 this->PushLiteralName(fni_, name); |
2612 } | 2612 } |
2613 | 2613 |
2614 if (!in_class && !is_generator && peek() == Token::COLON) { | 2614 if (!in_class && !is_generator) { |
2615 // PropertyDefinition : PropertyName ':' AssignmentExpression | 2615 DCHECK(!is_static); |
2616 if (!*is_computed_name) { | 2616 |
2617 checker->CheckProperty(name_token, kValueProperty, is_static, | 2617 if (peek() == Token::COLON) { |
2618 is_generator, | 2618 // PropertyDefinition |
2619 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2619 // PropertyName ':' AssignmentExpression |
2620 if (!*is_computed_name) { | |
2621 checker->CheckProperty(name_token, kValueProperty, false, false, | |
2622 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
2623 } | |
2624 Consume(Token::COLON); | |
2625 value = this->ParseAssignmentExpression( | |
2626 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
2627 return factory()->NewObjectLiteralProperty(name_expression, value, false, | |
2628 *is_computed_name); | |
2620 } | 2629 } |
2621 Consume(Token::COLON); | |
2622 value = this->ParseAssignmentExpression( | |
2623 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
2624 | 2630 |
2625 } else if (is_generator || peek() == Token::LPAREN) { | 2631 if (Token::IsIdentifier(name_token, language_mode(), |
2626 // Concise Method | 2632 this->is_generator()) && |
2633 (peek() == Token::COMMA || peek() == Token::RBRACE || | |
2634 peek() == Token::ASSIGN)) { | |
2635 // PropertyDefinition | |
2636 // IdentifierReference | |
2637 // CoverInitializedName | |
2638 // | |
2639 // CoverInitializedName | |
2640 // IdentifierReference Initializer(opt) | |
2641 if (classifier->duplicate_finder() != nullptr && | |
2642 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | |
2643 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | |
2644 } | |
2645 | |
2646 ExpressionT lhs = this->ExpressionFromIdentifier( | |
2647 name, next_beg_pos, next_end_pos, scope_, factory()); | |
2648 | |
2649 if (peek() == Token::ASSIGN) { | |
2650 this->ExpressionUnexpectedToken(classifier); | |
2651 Consume(Token::ASSIGN); | |
2652 ExpressionClassifier rhs_classifier; | |
2653 ExpressionT rhs = this->ParseAssignmentExpression( | |
2654 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
2655 classifier->Accumulate(rhs_classifier, | |
2656 ExpressionClassifier::ExpressionProductions); | |
2657 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | |
2658 RelocInfo::kNoPosition); | |
2659 } else { | |
2660 value = lhs; | |
2661 } | |
2662 | |
2663 return factory()->NewObjectLiteralProperty( | |
2664 name_expression, value, ObjectLiteralProperty::COMPUTED, false, | |
2665 false); | |
2666 } | |
2667 } | |
2668 | |
2669 | |
2670 if (is_generator || peek() == Token::LPAREN) { | |
2671 // MethodDefinition | |
2672 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | |
2673 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | |
2627 if (!*is_computed_name) { | 2674 if (!*is_computed_name) { |
2628 checker->CheckProperty(name_token, kMethodProperty, is_static, | 2675 checker->CheckProperty(name_token, kMethodProperty, is_static, |
2629 is_generator, | 2676 is_generator, |
2630 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2677 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2631 } | 2678 } |
2632 | 2679 |
2633 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 2680 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
2634 : FunctionKind::kConciseMethod; | 2681 : FunctionKind::kConciseMethod; |
2635 | 2682 |
2636 if (in_class && !is_static && this->IsConstructor(name)) { | 2683 if (in_class && !is_static && this->IsConstructor(name)) { |
2637 *has_seen_constructor = true; | 2684 *has_seen_constructor = true; |
2638 kind = has_extends ? FunctionKind::kSubclassConstructor | 2685 kind = has_extends ? FunctionKind::kSubclassConstructor |
2639 : FunctionKind::kBaseConstructor; | 2686 : FunctionKind::kBaseConstructor; |
2640 } | 2687 } |
2641 | 2688 |
2642 if (!in_class) kind = WithObjectLiteralBit(kind); | 2689 if (!in_class) kind = WithObjectLiteralBit(kind); |
2643 | 2690 |
2644 value = this->ParseFunctionLiteral( | 2691 value = this->ParseFunctionLiteral( |
2645 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2692 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2646 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 2693 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
2647 FunctionLiteral::NORMAL_ARITY, language_mode(), | 2694 FunctionLiteral::NORMAL_ARITY, language_mode(), |
2648 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2695 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2649 | 2696 |
2650 return factory()->NewObjectLiteralProperty(name_expression, value, | 2697 return factory()->NewObjectLiteralProperty(name_expression, value, |
2651 ObjectLiteralProperty::COMPUTED, | 2698 ObjectLiteralProperty::COMPUTED, |
2652 is_static, *is_computed_name); | 2699 is_static, *is_computed_name); |
2700 } | |
2653 | 2701 |
2654 } else if (in_class && name_is_static && !is_static) { | 2702 if (in_class && name_is_static && !is_static) { |
2655 // static MethodDefinition | 2703 // ClassElement (static) |
2704 // static MethodDefinition | |
adamk
2015/09/16 20:58:00
'static' should be quoted.
caitp (gmail)
2015/09/16 21:01:09
Done.
| |
2656 return ParsePropertyDefinition(checker, true, has_extends, true, | 2705 return ParsePropertyDefinition(checker, true, has_extends, true, |
2657 is_computed_name, nullptr, classifier, ok); | 2706 is_computed_name, nullptr, classifier, ok); |
2658 } else if ((is_get || is_set) && | 2707 } |
2659 (in_class || (peek() != Token::RBRACE && peek() != Token::COMMA && | 2708 |
2660 peek() != Token::ASSIGN))) { | 2709 if (is_get || is_set) { |
2661 // Accessor | 2710 // MethodDefinition (Accessors) |
2711 // get PropertyName '(' ')' '{' FunctionBody '}' | |
2712 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | |
caitp (gmail)
2015/09/16 20:10:25
The get/set should probably be quoted, but there i
adamk
2015/09/16 20:58:00
Yuck, 80 char limit is unfortunate here. Probably
caitp (gmail)
2015/09/16 21:01:09
Acknowledged.
| |
2662 name = this->EmptyIdentifier(); | 2713 name = this->EmptyIdentifier(); |
2663 bool dont_care = false; | 2714 bool dont_care = false; |
2664 name_token = peek(); | 2715 name_token = peek(); |
2665 | 2716 |
2666 name_expression = ParsePropertyName( | 2717 name_expression = ParsePropertyName( |
2667 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, | 2718 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
2668 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2719 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2669 | 2720 |
2670 if (!*is_computed_name) { | 2721 if (!*is_computed_name) { |
2671 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 2722 checker->CheckProperty(name_token, kAccessorProperty, is_static, |
(...skipping 14 matching lines...) Expand all Loading... | |
2686 // statically we can skip the extra runtime check. | 2737 // statically we can skip the extra runtime check. |
2687 if (!*is_computed_name) { | 2738 if (!*is_computed_name) { |
2688 name_expression = | 2739 name_expression = |
2689 factory()->NewStringLiteral(name, name_expression->position()); | 2740 factory()->NewStringLiteral(name, name_expression->position()); |
2690 } | 2741 } |
2691 | 2742 |
2692 return factory()->NewObjectLiteralProperty( | 2743 return factory()->NewObjectLiteralProperty( |
2693 name_expression, value, | 2744 name_expression, value, |
2694 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 2745 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
2695 is_static, *is_computed_name); | 2746 is_static, *is_computed_name); |
2696 | |
2697 } else if (!in_class && Token::IsIdentifier(name_token, language_mode(), | |
2698 this->is_generator())) { | |
2699 DCHECK(!*is_computed_name); | |
2700 DCHECK(!is_static); | |
2701 | |
2702 if (classifier->duplicate_finder() != nullptr && | |
2703 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | |
2704 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | |
2705 } | |
2706 | |
2707 ExpressionT lhs = this->ExpressionFromIdentifier( | |
2708 name, next_beg_pos, next_end_pos, scope_, factory()); | |
2709 if (peek() == Token::ASSIGN) { | |
2710 this->ExpressionUnexpectedToken(classifier); | |
2711 Consume(Token::ASSIGN); | |
2712 ExpressionClassifier rhs_classifier; | |
2713 ExpressionT rhs = this->ParseAssignmentExpression( | |
2714 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
2715 classifier->Accumulate(rhs_classifier, | |
2716 ExpressionClassifier::ExpressionProductions); | |
2717 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | |
2718 RelocInfo::kNoPosition); | |
2719 } else { | |
2720 value = lhs; | |
2721 } | |
2722 return factory()->NewObjectLiteralProperty( | |
2723 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); | |
2724 | |
2725 } else { | |
2726 Token::Value next = Next(); | |
2727 ReportUnexpectedToken(next); | |
2728 *ok = false; | |
2729 return this->EmptyObjectLiteralProperty(); | |
2730 } | 2747 } |
2731 | 2748 |
2732 return factory()->NewObjectLiteralProperty(name_expression, value, is_static, | 2749 Token::Value next = Next(); |
2733 *is_computed_name); | 2750 ReportUnexpectedToken(next); |
2751 *ok = false; | |
2752 return this->EmptyObjectLiteralProperty(); | |
2734 } | 2753 } |
2735 | 2754 |
2736 | 2755 |
2737 template <class Traits> | 2756 template <class Traits> |
2738 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 2757 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
2739 ExpressionClassifier* classifier, bool* ok) { | 2758 ExpressionClassifier* classifier, bool* ok) { |
2740 // ObjectLiteral :: | 2759 // ObjectLiteral :: |
2741 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2760 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
2742 | 2761 |
2743 int pos = peek_position(); | 2762 int pos = peek_position(); |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4159 *ok = false; | 4178 *ok = false; |
4160 return; | 4179 return; |
4161 } | 4180 } |
4162 has_seen_constructor_ = true; | 4181 has_seen_constructor_ = true; |
4163 return; | 4182 return; |
4164 } | 4183 } |
4165 } | 4184 } |
4166 } } // v8::internal | 4185 } } // v8::internal |
4167 | 4186 |
4168 #endif // V8_PREPARSER_H | 4187 #endif // V8_PREPARSER_H |
OLD | NEW |