Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: src/preparser.h

Issue 1328083002: [es6] support `get` and `set` in shorthand properties (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: A more fundamental refactoring to make things clearer Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
caitp (gmail) 2015/09/07 03:16:17 I reorganized ParsePropertyDefinition because it w
2615 // PropertyDefinition : PropertyName ':' AssignmentExpression 2615 // ObjectLiteral-exclusive productions
2616 if (!*is_computed_name) { 2616 switch (peek()) {
2617 checker->CheckProperty(name_token, kValueProperty, is_static, 2617 case Token::COLON: {
2618 is_generator, 2618 // PropertyDefinition :
2619 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2619 // PropertyName : AssignmentExpression
2620 // PropertyName : BindingPattern
2621 if (!*is_computed_name) {
2622 checker->CheckProperty(name_token, kValueProperty, is_static,
2623 is_generator,
2624 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2625 }
2626 Consume(Token::COLON);
2627 value = this->ParseAssignmentExpression(
2628 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2629 return factory()->NewObjectLiteralProperty(name_expression, value,
2630 false, *is_computed_name);
2631 }
2632 case Token::ASSIGN:
2633 // CoverInitializedName
2634 // BindingIdentifier = AssignmentPattern
2635 this->ExpressionUnexpectedToken(classifier);
2636 case Token::COMMA:
2637 case Token::RBRACE: {
2638 // BindingIdentifier
2639 if (!Token::IsIdentifier(name_token, language_mode(),
2640 this->is_generator()))
2641 break;
adamk 2015/09/08 23:17:17 This break makes this whole approach not much easi
caitp (gmail) 2015/09/08 23:35:13 It can work the other way, just makes the inventio
2642
2643 if (classifier->duplicate_finder() != nullptr &&
2644 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
2645 classifier->RecordDuplicateFormalParameterError(
2646 scanner()->location());
2647 }
2648
2649 ExpressionT lhs = this->ExpressionFromIdentifier(
2650 name, next_beg_pos, next_end_pos, scope_, factory());
2651
2652 if (Check(Token::ASSIGN)) {
2653 // CoverInitializedName
2654 // BindingIdentifier = AssignmentPattern
2655 ExpressionClassifier rhs_classifier;
2656 ExpressionT rhs = this->ParseAssignmentExpression(
2657 true, &rhs_classifier,
2658 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2659 classifier->Accumulate(rhs_classifier,
2660 ExpressionClassifier::ExpressionProductions);
2661 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
2662 RelocInfo::kNoPosition);
2663 } else {
2664 // BindingIdentifier
2665 value = lhs;
2666 }
2667
2668 return factory()->NewObjectLiteralProperty(
2669 name_expression, value, ObjectLiteralProperty::COMPUTED, false,
2670 false);
2671 }
2672 default:
2673 break;
2620 } 2674 }
2621 Consume(Token::COLON); 2675 }
2622 value = this->ParseAssignmentExpression(
2623 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2624 2676
2625 } else if (is_generator || peek() == Token::LPAREN) { 2677 if (is_generator || peek() == Token::LPAREN) {
2626 // Concise Method 2678 // MethodDefinition :
2679 // PropertyName ( StrictFormalParameters ) { FunctionBody }
2680 // * PropertyName ( StrictFormalParameters ) { FunctionBody }
2627 if (!*is_computed_name) { 2681 if (!*is_computed_name) {
2628 checker->CheckProperty(name_token, kMethodProperty, is_static, 2682 checker->CheckProperty(name_token, kMethodProperty, is_static,
2629 is_generator, 2683 is_generator,
2630 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2684 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2631 } 2685 }
2632 2686
2633 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod 2687 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod
2634 : FunctionKind::kConciseMethod; 2688 : FunctionKind::kConciseMethod;
2635 2689
2636 if (in_class && !is_static && this->IsConstructor(name)) { 2690 if (in_class && !is_static && this->IsConstructor(name)) {
2637 *has_seen_constructor = true; 2691 *has_seen_constructor = true;
2638 kind = has_extends ? FunctionKind::kSubclassConstructor 2692 kind = has_extends ? FunctionKind::kSubclassConstructor
2639 : FunctionKind::kBaseConstructor; 2693 : FunctionKind::kBaseConstructor;
2640 } 2694 }
2641 2695
2642 if (!in_class) kind = WithObjectLiteralBit(kind); 2696 if (!in_class) kind = WithObjectLiteralBit(kind);
2643 2697
2644 value = this->ParseFunctionLiteral( 2698 value = this->ParseFunctionLiteral(
2645 name, scanner()->location(), kSkipFunctionNameCheck, kind, 2699 name, scanner()->location(), kSkipFunctionNameCheck, kind,
2646 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, 2700 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION,
2647 FunctionLiteral::NORMAL_ARITY, language_mode(), 2701 FunctionLiteral::NORMAL_ARITY, language_mode(),
2648 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2702 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2649 2703
2650 return factory()->NewObjectLiteralProperty(name_expression, value, 2704 return factory()->NewObjectLiteralProperty(name_expression, value,
2651 ObjectLiteralProperty::COMPUTED, 2705 ObjectLiteralProperty::COMPUTED,
2652 is_static, *is_computed_name); 2706 is_static, *is_computed_name);
2653
2654 } else if (in_class && name_is_static && !is_static) { 2707 } else if (in_class && name_is_static && !is_static) {
2655 // static MethodDefinition 2708 // static MethodDefinition
2656 return ParsePropertyDefinition(checker, true, has_extends, true, 2709 return ParsePropertyDefinition(checker, true, has_extends, true,
2657 is_computed_name, nullptr, classifier, ok); 2710 is_computed_name, nullptr, classifier, ok);
2658 } else if (is_get || is_set) { 2711 } else if (is_get || is_set) {
2659 // Accessor 2712 // MethodDefinition (Accessors) :
2713 // get PropertyName ( ) { FunctionBody }
2714 // set PropertyName ( PropertySetParameterList ) { FunctionBody }
2660 name = this->EmptyIdentifier(); 2715 name = this->EmptyIdentifier();
2661 bool dont_care = false; 2716 bool dont_care = false;
2662 name_token = peek(); 2717 name_token = peek();
2663 2718
2664 name_expression = ParsePropertyName( 2719 name_expression = ParsePropertyName(
2665 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, 2720 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier,
2666 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2721 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2667 2722
2668 if (!*is_computed_name) { 2723 if (!*is_computed_name) {
2669 checker->CheckProperty(name_token, kAccessorProperty, is_static, 2724 checker->CheckProperty(name_token, kAccessorProperty, is_static,
(...skipping 14 matching lines...) Expand all
2684 // statically we can skip the extra runtime check. 2739 // statically we can skip the extra runtime check.
2685 if (!*is_computed_name) { 2740 if (!*is_computed_name) {
2686 name_expression = 2741 name_expression =
2687 factory()->NewStringLiteral(name, name_expression->position()); 2742 factory()->NewStringLiteral(name, name_expression->position());
2688 } 2743 }
2689 2744
2690 return factory()->NewObjectLiteralProperty( 2745 return factory()->NewObjectLiteralProperty(
2691 name_expression, value, 2746 name_expression, value,
2692 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, 2747 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER,
2693 is_static, *is_computed_name); 2748 is_static, *is_computed_name);
2694
2695 } else if (!in_class && Token::IsIdentifier(name_token, language_mode(),
2696 this->is_generator())) {
2697 DCHECK(!*is_computed_name);
2698 DCHECK(!is_static);
2699
2700 if (classifier->duplicate_finder() != nullptr &&
2701 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
2702 classifier->RecordDuplicateFormalParameterError(scanner()->location());
2703 }
2704
2705 ExpressionT lhs = this->ExpressionFromIdentifier(
2706 name, next_beg_pos, next_end_pos, scope_, factory());
2707 if (peek() == Token::ASSIGN) {
2708 this->ExpressionUnexpectedToken(classifier);
2709 Consume(Token::ASSIGN);
2710 ExpressionClassifier rhs_classifier;
2711 ExpressionT rhs = this->ParseAssignmentExpression(
2712 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2713 classifier->Accumulate(rhs_classifier,
2714 ExpressionClassifier::ExpressionProductions);
2715 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
2716 RelocInfo::kNoPosition);
2717 } else {
2718 value = lhs;
2719 }
2720 return factory()->NewObjectLiteralProperty(
2721 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false);
2722
2723 } else { 2749 } else {
2724 Token::Value next = Next(); 2750 Token::Value next = Next();
2725 ReportUnexpectedToken(next); 2751 ReportUnexpectedToken(next);
2726 *ok = false; 2752 *ok = false;
2727 return this->EmptyObjectLiteralProperty(); 2753 return this->EmptyObjectLiteralProperty();
2728 } 2754 }
2729
2730 return factory()->NewObjectLiteralProperty(name_expression, value, is_static,
2731 *is_computed_name);
2732 } 2755 }
2733 2756
2734 2757
2735 template <class Traits> 2758 template <class Traits>
2736 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( 2759 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
2737 ExpressionClassifier* classifier, bool* ok) { 2760 ExpressionClassifier* classifier, bool* ok) {
2738 // ObjectLiteral :: 2761 // ObjectLiteral ::
2739 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2762 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2740 2763
2741 int pos = peek_position(); 2764 int pos = peek_position();
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 *ok = false; 4180 *ok = false;
4158 return; 4181 return;
4159 } 4182 }
4160 has_seen_constructor_ = true; 4183 has_seen_constructor_ = true;
4161 return; 4184 return;
4162 } 4185 }
4163 } 4186 }
4164 } } // v8::internal 4187 } } // v8::internal
4165 4188
4166 #endif // V8_PREPARSER_H 4189 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698