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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 public: | 81 public: |
82 // Shorten type names defined by Traits. | 82 // Shorten type names defined by Traits. |
83 typedef typename Traits::Type::Expression ExpressionT; | 83 typedef typename Traits::Type::Expression ExpressionT; |
84 typedef typename Traits::Type::Identifier IdentifierT; | 84 typedef typename Traits::Type::Identifier IdentifierT; |
85 typedef typename Traits::Type::FormalParameter FormalParameterT; | 85 typedef typename Traits::Type::FormalParameter FormalParameterT; |
86 typedef typename Traits::Type::FormalParameters FormalParametersT; | 86 typedef typename Traits::Type::FormalParameters FormalParametersT; |
87 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 87 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
88 typedef typename Traits::Type::Literal LiteralT; | 88 typedef typename Traits::Type::Literal LiteralT; |
89 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 89 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
90 | 90 |
| 91 enum ExpressionFlavor { |
| 92 VanillaExpression, |
| 93 ElementExpression |
| 94 }; |
| 95 |
91 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 96 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
92 v8::Extension* extension, AstValueFactory* ast_value_factory, | 97 v8::Extension* extension, AstValueFactory* ast_value_factory, |
93 ParserRecorder* log, typename Traits::Type::Parser this_object) | 98 ParserRecorder* log, typename Traits::Type::Parser this_object) |
94 : Traits(this_object), | 99 : Traits(this_object), |
95 parenthesized_function_(false), | 100 parenthesized_function_(false), |
| 101 has_seen_assignment_pattern_(false), |
96 scope_(NULL), | 102 scope_(NULL), |
97 function_state_(NULL), | 103 function_state_(NULL), |
98 extension_(extension), | 104 extension_(extension), |
99 fni_(NULL), | 105 fni_(NULL), |
100 ast_value_factory_(ast_value_factory), | 106 ast_value_factory_(ast_value_factory), |
101 log_(log), | 107 log_(log), |
102 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 108 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
103 stack_limit_(stack_limit), | 109 stack_limit_(stack_limit), |
104 zone_(zone), | 110 zone_(zone), |
105 scanner_(scanner), | 111 scanner_(scanner), |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 MessageTemplate::Template message, bool* ok) { | 449 MessageTemplate::Template message, bool* ok) { |
444 Scanner::Location octal = scanner()->octal_position(); | 450 Scanner::Location octal = scanner()->octal_position(); |
445 if (octal.IsValid() && beg_pos <= octal.beg_pos && | 451 if (octal.IsValid() && beg_pos <= octal.beg_pos && |
446 octal.end_pos <= end_pos) { | 452 octal.end_pos <= end_pos) { |
447 ReportMessageAt(octal, message); | 453 ReportMessageAt(octal, message); |
448 scanner()->clear_octal_position(); | 454 scanner()->clear_octal_position(); |
449 *ok = false; | 455 *ok = false; |
450 } | 456 } |
451 } | 457 } |
452 | 458 |
| 459 bool CheckAssignmentPattern(ExpressionT value, |
| 460 ExpressionClassifier* classifier, bool* ok) { |
| 461 if (value->IsPatternOrLiteral()) { |
| 462 if (!classifier->is_valid_assignment_pattern()) { |
| 463 ReportClassifierError(classifier->assignment_pattern_error()); |
| 464 *ok = false; |
| 465 } |
| 466 return true; |
| 467 } |
| 468 return false; |
| 469 } |
| 470 |
453 inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 471 inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
454 CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kStrictOctalLiteral, | 472 CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kStrictOctalLiteral, |
455 ok); | 473 ok); |
456 } | 474 } |
457 | 475 |
458 inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 476 inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
459 CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kTemplateOctalLiteral, | 477 CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kTemplateOctalLiteral, |
460 ok); | 478 ok); |
461 } | 479 } |
462 | 480 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 682 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
665 ObjectLiteralPropertyT ParsePropertyDefinition( | 683 ObjectLiteralPropertyT ParsePropertyDefinition( |
666 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 684 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
667 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 685 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
668 ExpressionClassifier* classifier, bool* ok); | 686 ExpressionClassifier* classifier, bool* ok); |
669 typename Traits::Type::ExpressionList ParseArguments( | 687 typename Traits::Type::ExpressionList ParseArguments( |
670 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 688 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
671 bool* ok); | 689 bool* ok); |
672 ExpressionT ParseAssignmentExpression(bool accept_IN, | 690 ExpressionT ParseAssignmentExpression(bool accept_IN, |
673 ExpressionClassifier* classifier, | 691 ExpressionClassifier* classifier, |
674 bool* ok); | 692 ExpressionFlavor flavor, bool* ok); |
| 693 ExpressionT ParseAssignmentExpression(bool accept_IN, |
| 694 ExpressionClassifier* classifier, |
| 695 bool* ok) { |
| 696 return ParseAssignmentExpression(accept_IN, classifier, VanillaExpression, |
| 697 ok); |
| 698 } |
| 699 ExpressionT ParseNestedAssignmentExpression(bool accept_IN, |
| 700 ExpressionClassifier* classifier, |
| 701 bool* ok) { |
| 702 bool saved = has_seen_assignment_pattern_; |
| 703 has_seen_assignment_pattern_ = false; |
| 704 ExpressionT result = ParseAssignmentExpression( |
| 705 accept_IN, classifier, ok); |
| 706 if (!*ok) return this->EmptyExpression(); |
| 707 has_seen_assignment_pattern_ = saved; |
| 708 return result; |
| 709 } |
675 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 710 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); |
676 ExpressionT ParseConditionalExpression(bool accept_IN, | 711 ExpressionT ParseConditionalExpression(bool accept_IN, |
677 ExpressionClassifier* classifier, | 712 ExpressionClassifier* classifier, |
678 bool* ok); | 713 bool* ok); |
679 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 714 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
680 ExpressionClassifier* classifier, bool* ok); | 715 ExpressionClassifier* classifier, bool* ok); |
681 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 716 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
682 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 717 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
683 bool* ok); | 718 bool* ok); |
684 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 719 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
(...skipping 28 matching lines...) Expand all Loading... |
713 // Checks if the expression is a valid reference expression (e.g., on the | 748 // Checks if the expression is a valid reference expression (e.g., on the |
714 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 749 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
715 // we allow calls for web compatibility and rewrite them to a runtime throw. | 750 // we allow calls for web compatibility and rewrite them to a runtime throw. |
716 ExpressionT CheckAndRewriteReferenceExpression( | 751 ExpressionT CheckAndRewriteReferenceExpression( |
717 ExpressionT expression, int beg_pos, int end_pos, | 752 ExpressionT expression, int beg_pos, int end_pos, |
718 MessageTemplate::Template message, bool* ok); | 753 MessageTemplate::Template message, bool* ok); |
719 ExpressionT CheckAndRewriteReferenceExpression( | 754 ExpressionT CheckAndRewriteReferenceExpression( |
720 ExpressionT expression, int beg_pos, int end_pos, | 755 ExpressionT expression, int beg_pos, int end_pos, |
721 MessageTemplate::Template message, ParseErrorType type, bool* ok); | 756 MessageTemplate::Template message, ParseErrorType type, bool* ok); |
722 | 757 |
| 758 void CheckPatternElement( |
| 759 ExpressionT expression, int beg_pos, int end_pos, |
| 760 ExpressionClassifier* classifier); |
| 761 |
723 // Used to validate property names in object literals and class literals | 762 // Used to validate property names in object literals and class literals |
724 enum PropertyKind { | 763 enum PropertyKind { |
725 kAccessorProperty, | 764 kAccessorProperty, |
726 kValueProperty, | 765 kValueProperty, |
727 kMethodProperty | 766 kMethodProperty |
728 }; | 767 }; |
729 | 768 |
730 class ObjectLiteralCheckerBase { | 769 class ObjectLiteralCheckerBase { |
731 public: | 770 public: |
732 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} | 771 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 } | 816 } |
778 | 817 |
779 bool has_seen_constructor_; | 818 bool has_seen_constructor_; |
780 }; | 819 }; |
781 | 820 |
782 // If true, the next (and immediately following) function literal is | 821 // If true, the next (and immediately following) function literal is |
783 // preceded by a parenthesis. | 822 // preceded by a parenthesis. |
784 // Heuristically that means that the function will be called immediately, | 823 // Heuristically that means that the function will be called immediately, |
785 // so never lazily compile it. | 824 // so never lazily compile it. |
786 bool parenthesized_function_; | 825 bool parenthesized_function_; |
| 826 bool has_seen_assignment_pattern_; |
787 | 827 |
788 Scope* scope_; // Scope stack. | 828 Scope* scope_; // Scope stack. |
789 FunctionState* function_state_; // Function state stack. | 829 FunctionState* function_state_; // Function state stack. |
790 v8::Extension* extension_; | 830 v8::Extension* extension_; |
791 FuncNameInferrer* fni_; | 831 FuncNameInferrer* fni_; |
792 AstValueFactory* ast_value_factory_; // Not owned. | 832 AstValueFactory* ast_value_factory_; // Not owned. |
793 ParserRecorder* log_; | 833 ParserRecorder* log_; |
794 Mode mode_; | 834 Mode mode_; |
795 uintptr_t stack_limit_; | 835 uintptr_t stack_limit_; |
796 | 836 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 friend class PreParserExpression; | 938 friend class PreParserExpression; |
899 }; | 939 }; |
900 | 940 |
901 | 941 |
902 class PreParserExpression { | 942 class PreParserExpression { |
903 public: | 943 public: |
904 static PreParserExpression Default() { | 944 static PreParserExpression Default() { |
905 return PreParserExpression(TypeField::encode(kExpression)); | 945 return PreParserExpression(TypeField::encode(kExpression)); |
906 } | 946 } |
907 | 947 |
| 948 static PreParserExpression Assignment(PreParserExpression lhs, |
| 949 Token::Value op) { |
| 950 uint32_t code = TypeField::encode(kAssignment); |
| 951 if (op == Token::ASSIGN && |
| 952 (lhs->IsObjectLiteral() || lhs->IsArrayLiteral())) { |
| 953 code |= ExpressionTypeField::encode(kDestructuringAssignment); |
| 954 } |
| 955 return PreParserExpression(code); |
| 956 } |
| 957 |
908 static PreParserExpression Spread(PreParserExpression expression) { | 958 static PreParserExpression Spread(PreParserExpression expression) { |
909 return PreParserExpression(TypeField::encode(kSpreadExpression)); | 959 return PreParserExpression(TypeField::encode(kSpreadExpression)); |
910 } | 960 } |
911 | 961 |
912 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 962 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
913 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 963 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
914 IdentifierTypeField::encode(id.type_)); | 964 IdentifierTypeField::encode(id.type_)); |
915 } | 965 } |
916 | 966 |
917 static PreParserExpression BinaryOperation(PreParserExpression left, | 967 static PreParserExpression BinaryOperation(PreParserExpression left, |
918 Token::Value op, | 968 Token::Value op, |
919 PreParserExpression right) { | 969 PreParserExpression right) { |
920 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); | 970 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); |
921 } | 971 } |
922 | 972 |
923 static PreParserExpression StringLiteral() { | 973 static PreParserExpression StringLiteral() { |
924 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 974 return PreParserExpression(TypeField::encode(kStringLiteral)); |
925 } | 975 } |
926 | 976 |
927 static PreParserExpression UseStrictStringLiteral() { | 977 static PreParserExpression UseStrictStringLiteral() { |
928 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 978 return PreParserExpression(TypeField::encode(kStringLiteral) | |
929 IsUseStrictField::encode(true)); | 979 IsUseStrictField::encode(true)); |
930 } | 980 } |
931 | 981 |
932 static PreParserExpression UseStrongStringLiteral() { | 982 static PreParserExpression UseStrongStringLiteral() { |
933 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 983 return PreParserExpression(TypeField::encode(kStringLiteral) | |
934 IsUseStrongField::encode(true)); | 984 IsUseStrongField::encode(true)); |
935 } | 985 } |
936 | 986 |
| 987 static PreParserExpression NumberLiteral() { |
| 988 return PreParserExpression(TypeField::encode(kNumberLiteral)); |
| 989 } |
| 990 |
| 991 static PreParserExpression ArrayLiteral() { |
| 992 return PreParserExpression(TypeField::encode(kArrayLiteral)); |
| 993 } |
| 994 |
| 995 static PreParserExpression ObjectLiteral() { |
| 996 return PreParserExpression(TypeField::encode(kObjectLiteral)); |
| 997 } |
| 998 |
937 static PreParserExpression This() { | 999 static PreParserExpression This() { |
938 return PreParserExpression(TypeField::encode(kExpression) | | 1000 return PreParserExpression(TypeField::encode(kExpression) | |
939 ExpressionTypeField::encode(kThisExpression)); | 1001 ExpressionTypeField::encode(kThisExpression)); |
940 } | 1002 } |
941 | 1003 |
942 static PreParserExpression ThisProperty() { | 1004 static PreParserExpression ThisProperty() { |
943 return PreParserExpression( | 1005 return PreParserExpression( |
944 TypeField::encode(kExpression) | | 1006 TypeField::encode(kExpression) | |
945 ExpressionTypeField::encode(kThisPropertyExpression)); | 1007 ExpressionTypeField::encode(kThisPropertyExpression)); |
946 } | 1008 } |
(...skipping 24 matching lines...) Expand all Loading... |
971 bool IsIdentifier() const { | 1033 bool IsIdentifier() const { |
972 return TypeField::decode(code_) == kIdentifierExpression; | 1034 return TypeField::decode(code_) == kIdentifierExpression; |
973 } | 1035 } |
974 | 1036 |
975 PreParserIdentifier AsIdentifier() const { | 1037 PreParserIdentifier AsIdentifier() const { |
976 DCHECK(IsIdentifier()); | 1038 DCHECK(IsIdentifier()); |
977 return PreParserIdentifier(IdentifierTypeField::decode(code_)); | 1039 return PreParserIdentifier(IdentifierTypeField::decode(code_)); |
978 } | 1040 } |
979 | 1041 |
980 bool IsStringLiteral() const { | 1042 bool IsStringLiteral() const { |
981 return TypeField::decode(code_) == kStringLiteralExpression; | 1043 return TypeField::decode(code_) == kStringLiteral; |
982 } | 1044 } |
983 | 1045 |
984 bool IsUseStrictLiteral() const { | 1046 bool IsUseStrictLiteral() const { |
985 return TypeField::decode(code_) == kStringLiteralExpression && | 1047 return TypeField::decode(code_) == kStringLiteral && |
986 IsUseStrictField::decode(code_); | 1048 IsUseStrictField::decode(code_); |
987 } | 1049 } |
988 | 1050 |
989 bool IsUseStrongLiteral() const { | 1051 bool IsUseStrongLiteral() const { |
990 return TypeField::decode(code_) == kStringLiteralExpression && | 1052 return TypeField::decode(code_) == kStringLiteral && |
991 IsUseStrongField::decode(code_); | 1053 IsUseStrongField::decode(code_); |
992 } | 1054 } |
993 | 1055 |
| 1056 bool IsNumberLiteral() const { |
| 1057 return TypeField::decode(code_) == kNumberLiteral; |
| 1058 } |
| 1059 |
| 1060 bool IsArrayLiteral() const { |
| 1061 return TypeField::decode(code_) == kArrayLiteral; |
| 1062 } |
| 1063 |
| 1064 bool IsObjectLiteral() const { |
| 1065 return TypeField::decode(code_) == kObjectLiteral; |
| 1066 } |
| 1067 |
| 1068 inline bool IsPatternOrLiteral() const { |
| 1069 return IsObjectLiteral() || IsArrayLiteral(); |
| 1070 } |
| 1071 |
994 bool IsThis() const { | 1072 bool IsThis() const { |
995 return TypeField::decode(code_) == kExpression && | 1073 return TypeField::decode(code_) == kExpression && |
996 ExpressionTypeField::decode(code_) == kThisExpression; | 1074 ExpressionTypeField::decode(code_) == kThisExpression; |
997 } | 1075 } |
998 | 1076 |
999 bool IsThisProperty() const { | 1077 bool IsThisProperty() const { |
1000 return TypeField::decode(code_) == kExpression && | 1078 return TypeField::decode(code_) == kExpression && |
1001 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 1079 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
1002 } | 1080 } |
1003 | 1081 |
(...skipping 19 matching lines...) Expand all Loading... |
1023 | 1101 |
1024 // At the moment PreParser doesn't track these expression types. | 1102 // At the moment PreParser doesn't track these expression types. |
1025 bool IsFunctionLiteral() const { return false; } | 1103 bool IsFunctionLiteral() const { return false; } |
1026 bool IsCallNew() const { return false; } | 1104 bool IsCallNew() const { return false; } |
1027 | 1105 |
1028 bool IsNoTemplateTag() const { | 1106 bool IsNoTemplateTag() const { |
1029 return TypeField::decode(code_) == kExpression && | 1107 return TypeField::decode(code_) == kExpression && |
1030 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; | 1108 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; |
1031 } | 1109 } |
1032 | 1110 |
| 1111 bool IsAssignment() const { |
| 1112 return TypeField::decode(code_) == kAssignment; |
| 1113 } |
| 1114 |
| 1115 PreParserExpression AsAssignment() const { return *this; } |
| 1116 |
| 1117 bool IsDestructuring() const { |
| 1118 return TypeField::decode(code_) == kAssignment && |
| 1119 ExpressionTypeField::decode(code_) == kDestructuringAssignment; |
| 1120 } |
| 1121 |
1033 bool IsSpreadExpression() const { | 1122 bool IsSpreadExpression() const { |
1034 return TypeField::decode(code_) == kSpreadExpression; | 1123 return TypeField::decode(code_) == kSpreadExpression; |
1035 } | 1124 } |
1036 | 1125 |
1037 PreParserExpression AsFunctionLiteral() { return *this; } | 1126 PreParserExpression AsFunctionLiteral() { return *this; } |
1038 | 1127 |
1039 bool IsBinaryOperation() const { | 1128 bool IsBinaryOperation() const { |
1040 return TypeField::decode(code_) == kBinaryOperationExpression; | 1129 return TypeField::decode(code_) == kBinaryOperationExpression; |
1041 } | 1130 } |
1042 | 1131 |
1043 // Dummy implementation for making expression->somefunc() work in both Parser | 1132 // Dummy implementation for making expression->somefunc() work in both Parser |
1044 // and PreParser. | 1133 // and PreParser. |
1045 PreParserExpression* operator->() { return this; } | 1134 PreParserExpression* operator->() { return this; } |
1046 | 1135 |
1047 // More dummy implementations of things PreParser doesn't need to track: | 1136 // More dummy implementations of things PreParser doesn't need to track: |
1048 void set_index(int index) {} // For YieldExpressions | 1137 void set_index(int index) {} // For YieldExpressions |
1049 void set_should_eager_compile() {} | 1138 void set_should_eager_compile() {} |
1050 | 1139 |
1051 int position() const { return RelocInfo::kNoPosition; } | 1140 int position() const { return RelocInfo::kNoPosition; } |
1052 void set_function_token_position(int position) {} | 1141 void set_function_token_position(int position) {} |
1053 | 1142 |
1054 private: | 1143 private: |
1055 enum Type { | 1144 enum Type { |
1056 kExpression, | 1145 kExpression, |
1057 kIdentifierExpression, | 1146 kIdentifierExpression, |
1058 kStringLiteralExpression, | 1147 kStringLiteral, |
| 1148 kNumberLiteral, |
| 1149 kArrayLiteral, |
| 1150 kObjectLiteral, |
1059 kBinaryOperationExpression, | 1151 kBinaryOperationExpression, |
1060 kSpreadExpression | 1152 kSpreadExpression, |
| 1153 kAssignment |
1061 }; | 1154 }; |
1062 | 1155 |
1063 enum ExpressionType { | 1156 enum ExpressionType { |
1064 kThisExpression, | 1157 kThisExpression, |
1065 kThisPropertyExpression, | 1158 kThisPropertyExpression, |
1066 kPropertyExpression, | 1159 kPropertyExpression, |
1067 kCallExpression, | 1160 kCallExpression, |
1068 kSuperCallReference, | 1161 kSuperCallReference, |
1069 kNoTemplateTagExpression | 1162 kNoTemplateTagExpression, |
| 1163 kDestructuringAssignment |
1070 }; | 1164 }; |
1071 | 1165 |
1072 explicit PreParserExpression(uint32_t expression_code) | 1166 explicit PreParserExpression(uint32_t expression_code) |
1073 : code_(expression_code) {} | 1167 : code_(expression_code) {} |
1074 | 1168 |
1075 // The first three bits are for the Type. | 1169 // The first three bits are for the Type. |
1076 typedef BitField<Type, 0, 3> TypeField; | 1170 typedef BitField<Type, 0, 4> TypeField; |
1077 | 1171 |
1078 // The rest of the bits are interpreted depending on the value | 1172 // The rest of the bits are interpreted depending on the value |
1079 // of the Type field, so they can share the storage. | 1173 // of the Type field, so they can share the storage. |
1080 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 1174 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
1081 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 1175 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
1082 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 1176 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
1083 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 1177 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
1084 IdentifierTypeField; | 1178 IdentifierTypeField; |
1085 | 1179 |
1086 uint32_t code_; | 1180 uint32_t code_; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 | 1264 |
1171 | 1265 |
1172 typedef PreParserList<PreParserStatement> PreParserStatementList; | 1266 typedef PreParserList<PreParserStatement> PreParserStatementList; |
1173 | 1267 |
1174 | 1268 |
1175 class PreParserFactory { | 1269 class PreParserFactory { |
1176 public: | 1270 public: |
1177 explicit PreParserFactory(void* unused_value_factory) {} | 1271 explicit PreParserFactory(void* unused_value_factory) {} |
1178 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 1272 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
1179 int pos) { | 1273 int pos) { |
1180 return PreParserExpression::Default(); | 1274 return PreParserExpression::StringLiteral(); |
1181 } | 1275 } |
1182 PreParserExpression NewNumberLiteral(double number, | 1276 PreParserExpression NewNumberLiteral(double number, |
1183 int pos) { | 1277 int pos) { |
1184 return PreParserExpression::Default(); | 1278 return PreParserExpression::NumberLiteral(); |
1185 } | 1279 } |
1186 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 1280 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
1187 PreParserIdentifier js_flags, | 1281 PreParserIdentifier js_flags, |
1188 int literal_index, | 1282 int literal_index, |
1189 bool is_strong, | 1283 bool is_strong, |
1190 int pos) { | 1284 int pos) { |
1191 return PreParserExpression::Default(); | 1285 return PreParserExpression::Default(); |
1192 } | 1286 } |
1193 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1287 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
1194 int literal_index, | 1288 int literal_index, |
1195 bool is_strong, | 1289 bool is_strong, |
1196 int pos) { | 1290 int pos) { |
1197 return PreParserExpression::Default(); | 1291 return PreParserExpression::ArrayLiteral(); |
1198 } | 1292 } |
1199 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1293 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
1200 int first_spread_index, int literal_index, | 1294 int first_spread_index, int literal_index, |
1201 bool is_strong, int pos) { | 1295 bool is_strong, int pos) { |
1202 return PreParserExpression::Default(); | 1296 return PreParserExpression::ArrayLiteral(); |
1203 } | 1297 } |
1204 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1298 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
1205 PreParserExpression value, | 1299 PreParserExpression value, |
1206 ObjectLiteralProperty::Kind kind, | 1300 ObjectLiteralProperty::Kind kind, |
1207 bool is_static, | 1301 bool is_static, |
1208 bool is_computed_name) { | 1302 bool is_computed_name) { |
1209 return PreParserExpression::Default(); | 1303 return PreParserExpression::Default(); |
1210 } | 1304 } |
1211 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1305 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
1212 PreParserExpression value, | 1306 PreParserExpression value, |
1213 bool is_static, | 1307 bool is_static, |
1214 bool is_computed_name) { | 1308 bool is_computed_name) { |
1215 return PreParserExpression::Default(); | 1309 return PreParserExpression::Default(); |
1216 } | 1310 } |
1217 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1311 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
1218 int literal_index, | 1312 int literal_index, |
1219 int boilerplate_properties, | 1313 int boilerplate_properties, |
1220 bool has_function, | 1314 bool has_function, |
1221 bool is_strong, | 1315 bool is_strong, |
1222 int pos) { | 1316 int pos) { |
1223 return PreParserExpression::Default(); | 1317 return PreParserExpression::ObjectLiteral(); |
1224 } | 1318 } |
1225 PreParserExpression NewVariableProxy(void* variable) { | 1319 PreParserExpression NewVariableProxy(void* variable) { |
1226 return PreParserExpression::Default(); | 1320 return PreParserExpression::Default(); |
1227 } | 1321 } |
1228 PreParserExpression NewProperty(PreParserExpression obj, | 1322 PreParserExpression NewProperty(PreParserExpression obj, |
1229 PreParserExpression key, | 1323 PreParserExpression key, |
1230 int pos) { | 1324 int pos) { |
1231 if (obj.IsThis()) { | 1325 if (obj.IsThis()) { |
1232 return PreParserExpression::ThisProperty(); | 1326 return PreParserExpression::ThisProperty(); |
1233 } | 1327 } |
(...skipping 11 matching lines...) Expand all Loading... |
1245 } | 1339 } |
1246 PreParserExpression NewCompareOperation(Token::Value op, | 1340 PreParserExpression NewCompareOperation(Token::Value op, |
1247 PreParserExpression left, | 1341 PreParserExpression left, |
1248 PreParserExpression right, int pos) { | 1342 PreParserExpression right, int pos) { |
1249 return PreParserExpression::Default(); | 1343 return PreParserExpression::Default(); |
1250 } | 1344 } |
1251 PreParserExpression NewAssignment(Token::Value op, | 1345 PreParserExpression NewAssignment(Token::Value op, |
1252 PreParserExpression left, | 1346 PreParserExpression left, |
1253 PreParserExpression right, | 1347 PreParserExpression right, |
1254 int pos) { | 1348 int pos) { |
1255 return PreParserExpression::Default(); | 1349 return PreParserExpression::Assignment(left, op); |
1256 } | 1350 } |
1257 PreParserExpression NewYield(PreParserExpression generator_object, | 1351 PreParserExpression NewYield(PreParserExpression generator_object, |
1258 PreParserExpression expression, | 1352 PreParserExpression expression, |
1259 Yield::Kind yield_kind, | 1353 Yield::Kind yield_kind, |
1260 int pos) { | 1354 int pos) { |
1261 return PreParserExpression::Default(); | 1355 return PreParserExpression::Default(); |
1262 } | 1356 } |
1263 PreParserExpression NewConditional(PreParserExpression condition, | 1357 PreParserExpression NewConditional(PreParserExpression condition, |
1264 PreParserExpression then_expression, | 1358 PreParserExpression then_expression, |
1265 PreParserExpression else_expression, | 1359 PreParserExpression else_expression, |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 1699 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
1606 PreParserIdentifier function_name, int pos, | 1700 PreParserIdentifier function_name, int pos, |
1607 const PreParserFormalParameters& parameters, FunctionKind kind, | 1701 const PreParserFormalParameters& parameters, FunctionKind kind, |
1608 FunctionLiteral::FunctionType function_type, bool* ok); | 1702 FunctionLiteral::FunctionType function_type, bool* ok); |
1609 | 1703 |
1610 V8_INLINE void ParseArrowFunctionFormalParameterList( | 1704 V8_INLINE void ParseArrowFunctionFormalParameterList( |
1611 PreParserFormalParameters* parameters, | 1705 PreParserFormalParameters* parameters, |
1612 PreParserExpression expression, const Scanner::Location& params_loc, | 1706 PreParserExpression expression, const Scanner::Location& params_loc, |
1613 Scanner::Location* duplicate_loc, bool* ok); | 1707 Scanner::Location* duplicate_loc, bool* ok); |
1614 | 1708 |
| 1709 PreParserExpression RewriteDestructuringAssignment( |
| 1710 PreParserExpression expression) { |
| 1711 return expression; |
| 1712 } |
| 1713 |
1615 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} | 1714 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} |
1616 | 1715 |
1617 struct TemplateLiteralState {}; | 1716 struct TemplateLiteralState {}; |
1618 | 1717 |
1619 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1718 TemplateLiteralState OpenTemplateLiteral(int pos) { |
1620 return TemplateLiteralState(); | 1719 return TemplateLiteralState(); |
1621 } | 1720 } |
1622 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1721 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
1623 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1722 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
1624 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 1723 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2439 return this->EmptyExpression(); | 2538 return this->EmptyExpression(); |
2440 } | 2539 } |
2441 elem = this->GetLiteralTheHole(peek_position(), factory()); | 2540 elem = this->GetLiteralTheHole(peek_position(), factory()); |
2442 } else if (peek() == Token::ELLIPSIS) { | 2541 } else if (peek() == Token::ELLIPSIS) { |
2443 if (!allow_harmony_spread_arrays()) { | 2542 if (!allow_harmony_spread_arrays()) { |
2444 ExpressionUnexpectedToken(classifier); | 2543 ExpressionUnexpectedToken(classifier); |
2445 } | 2544 } |
2446 int start_pos = peek_position(); | 2545 int start_pos = peek_position(); |
2447 Consume(Token::ELLIPSIS); | 2546 Consume(Token::ELLIPSIS); |
2448 ExpressionT argument = | 2547 ExpressionT argument = |
2449 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2548 this->ParseAssignmentExpression(true, classifier, ElementExpression, |
| 2549 CHECK_OK); |
2450 elem = factory()->NewSpread(argument, start_pos); | 2550 elem = factory()->NewSpread(argument, start_pos); |
2451 seen_spread = true; | 2551 seen_spread = true; |
2452 if (first_spread_index < 0) { | 2552 if (first_spread_index < 0) { |
2453 first_spread_index = values->length(); | 2553 first_spread_index = values->length(); |
2454 } | 2554 } |
2455 } else { | 2555 } else { |
2456 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2556 elem = this->ParseAssignmentExpression(true, classifier, |
| 2557 ElementExpression, CHECK_OK); |
2457 } | 2558 } |
2458 values->Add(elem, zone_); | 2559 values->Add(elem, zone_); |
2459 if (peek() != Token::RBRACK) { | 2560 if (peek() != Token::RBRACK) { |
2460 if (seen_spread) { | 2561 if (seen_spread) { |
2461 BindingPatternUnexpectedToken(classifier); | 2562 BindingPatternUnexpectedToken(classifier); |
2462 } | 2563 } |
2463 Expect(Token::COMMA, CHECK_OK); | 2564 Expect(Token::COMMA, CHECK_OK); |
2464 } | 2565 } |
2465 } | 2566 } |
2466 Expect(Token::RBRACK, CHECK_OK); | 2567 Expect(Token::RBRACK, CHECK_OK); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 | 2661 |
2561 if (!in_class && !is_generator && peek() == Token::COLON) { | 2662 if (!in_class && !is_generator && peek() == Token::COLON) { |
2562 // PropertyDefinition : PropertyName ':' AssignmentExpression | 2663 // PropertyDefinition : PropertyName ':' AssignmentExpression |
2563 if (!*is_computed_name) { | 2664 if (!*is_computed_name) { |
2564 checker->CheckProperty(name_token, kValueProperty, is_static, | 2665 checker->CheckProperty(name_token, kValueProperty, is_static, |
2565 is_generator, | 2666 is_generator, |
2566 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2667 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2567 } | 2668 } |
2568 Consume(Token::COLON); | 2669 Consume(Token::COLON); |
2569 value = this->ParseAssignmentExpression( | 2670 value = this->ParseAssignmentExpression( |
2570 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2671 true, classifier, ElementExpression, |
| 2672 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2571 | 2673 |
2572 } else if (is_generator || peek() == Token::LPAREN) { | 2674 } else if (is_generator || peek() == Token::LPAREN) { |
2573 // Concise Method | 2675 // Concise Method |
| 2676 if (!in_class) { |
| 2677 classifier->RecordPatternError( |
| 2678 Scanner::Location(next_beg_pos, next_end_pos), |
| 2679 MessageTemplate::kInvalidDestructuringTarget); |
| 2680 } |
2574 if (!*is_computed_name) { | 2681 if (!*is_computed_name) { |
2575 checker->CheckProperty(name_token, kMethodProperty, is_static, | 2682 checker->CheckProperty(name_token, kMethodProperty, is_static, |
2576 is_generator, | 2683 is_generator, |
2577 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2684 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2578 } | 2685 } |
2579 | 2686 |
2580 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 2687 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
2581 : FunctionKind::kConciseMethod; | 2688 : FunctionKind::kConciseMethod; |
2582 | 2689 |
2583 if (in_class && !is_static && this->IsConstructor(name)) { | 2690 if (in_class && !is_static && this->IsConstructor(name)) { |
(...skipping 13 matching lines...) Expand all Loading... |
2597 return factory()->NewObjectLiteralProperty(name_expression, value, | 2704 return factory()->NewObjectLiteralProperty(name_expression, value, |
2598 ObjectLiteralProperty::COMPUTED, | 2705 ObjectLiteralProperty::COMPUTED, |
2599 is_static, *is_computed_name); | 2706 is_static, *is_computed_name); |
2600 | 2707 |
2601 } else if (in_class && name_is_static && !is_static) { | 2708 } else if (in_class && name_is_static && !is_static) { |
2602 // static MethodDefinition | 2709 // static MethodDefinition |
2603 return ParsePropertyDefinition(checker, true, has_extends, true, | 2710 return ParsePropertyDefinition(checker, true, has_extends, true, |
2604 is_computed_name, nullptr, classifier, ok); | 2711 is_computed_name, nullptr, classifier, ok); |
2605 } else if (is_get || is_set) { | 2712 } else if (is_get || is_set) { |
2606 // Accessor | 2713 // Accessor |
| 2714 if (!in_class) { |
| 2715 classifier->RecordPatternError( |
| 2716 Scanner::Location(next_beg_pos, next_end_pos), |
| 2717 MessageTemplate::kInvalidDestructuringTarget); |
| 2718 } |
2607 name = this->EmptyIdentifier(); | 2719 name = this->EmptyIdentifier(); |
2608 bool dont_care = false; | 2720 bool dont_care = false; |
2609 name_token = peek(); | 2721 name_token = peek(); |
2610 | 2722 |
2611 name_expression = ParsePropertyName( | 2723 name_expression = ParsePropertyName( |
2612 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, | 2724 &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
2613 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2725 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2614 | 2726 |
2615 if (!*is_computed_name) { | 2727 if (!*is_computed_name) { |
2616 checker->CheckProperty(name_token, kAccessorProperty, is_static, | 2728 checker->CheckProperty(name_token, kAccessorProperty, is_static, |
(...skipping 17 matching lines...) Expand all Loading... |
2634 factory()->NewStringLiteral(name, name_expression->position()); | 2746 factory()->NewStringLiteral(name, name_expression->position()); |
2635 } | 2747 } |
2636 | 2748 |
2637 return factory()->NewObjectLiteralProperty( | 2749 return factory()->NewObjectLiteralProperty( |
2638 name_expression, value, | 2750 name_expression, value, |
2639 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 2751 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
2640 is_static, *is_computed_name); | 2752 is_static, *is_computed_name); |
2641 | 2753 |
2642 } else if (!in_class && Token::IsIdentifier(name_token, language_mode(), | 2754 } else if (!in_class && Token::IsIdentifier(name_token, language_mode(), |
2643 this->is_generator())) { | 2755 this->is_generator())) { |
| 2756 // IdentifierReference | CoverInitializedName |
2644 DCHECK(!*is_computed_name); | 2757 DCHECK(!*is_computed_name); |
2645 DCHECK(!is_static); | 2758 DCHECK(!is_static); |
2646 | 2759 |
2647 if (classifier->duplicate_finder() != nullptr && | 2760 if (classifier->duplicate_finder() != nullptr && |
2648 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 2761 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
2649 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 2762 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
2650 } | 2763 } |
2651 | 2764 |
2652 ExpressionT lhs = this->ExpressionFromIdentifier( | 2765 ExpressionT lhs = this->ExpressionFromIdentifier( |
2653 name, next_beg_pos, next_end_pos, scope_, factory()); | 2766 name, next_beg_pos, next_end_pos, scope_, factory()); |
2654 if (peek() == Token::ASSIGN) { | 2767 if (peek() == Token::ASSIGN) { |
| 2768 // TODO(caitp): don't report SyntaxError for CoverInitializedName when |
| 2769 // parsing Pattern. |
2655 this->ExpressionUnexpectedToken(classifier); | 2770 this->ExpressionUnexpectedToken(classifier); |
2656 Consume(Token::ASSIGN); | 2771 Consume(Token::ASSIGN); |
2657 ExpressionClassifier rhs_classifier; | 2772 ExpressionClassifier rhs_classifier; |
2658 ExpressionT rhs = this->ParseAssignmentExpression( | 2773 |
| 2774 ExpressionT rhs = this->ParseNestedAssignmentExpression( |
2659 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2775 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2776 |
2660 classifier->Accumulate(rhs_classifier, | 2777 classifier->Accumulate(rhs_classifier, |
2661 ExpressionClassifier::ExpressionProduction); | 2778 ExpressionClassifier::ExpressionProduction); |
2662 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 2779 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
2663 RelocInfo::kNoPosition); | 2780 RelocInfo::kNoPosition); |
2664 } else { | 2781 } else { |
2665 value = lhs; | 2782 value = lhs; |
2666 } | 2783 } |
| 2784 |
2667 return factory()->NewObjectLiteralProperty( | 2785 return factory()->NewObjectLiteralProperty( |
2668 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); | 2786 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); |
2669 | 2787 |
2670 } else { | 2788 } else { |
2671 Token::Value next = Next(); | 2789 Token::Value next = Next(); |
2672 ReportUnexpectedToken(next); | 2790 ReportUnexpectedToken(next); |
2673 *ok = false; | 2791 *ok = false; |
2674 return this->EmptyObjectLiteralProperty(); | 2792 return this->EmptyObjectLiteralProperty(); |
2675 } | 2793 } |
2676 | 2794 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2754 // '(' (AssignmentExpression)*[','] ')' | 2872 // '(' (AssignmentExpression)*[','] ')' |
2755 | 2873 |
2756 Scanner::Location spread_arg = Scanner::Location::invalid(); | 2874 Scanner::Location spread_arg = Scanner::Location::invalid(); |
2757 typename Traits::Type::ExpressionList result = | 2875 typename Traits::Type::ExpressionList result = |
2758 this->NewExpressionList(4, zone_); | 2876 this->NewExpressionList(4, zone_); |
2759 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2877 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
2760 bool done = (peek() == Token::RPAREN); | 2878 bool done = (peek() == Token::RPAREN); |
2761 bool was_unspread = false; | 2879 bool was_unspread = false; |
2762 int unspread_sequences_count = 0; | 2880 int unspread_sequences_count = 0; |
2763 while (!done) { | 2881 while (!done) { |
| 2882 DCHECK_EQ(has_seen_assignment_pattern_, false); |
2764 bool is_spread = allow_harmony_spreadcalls() && (peek() == Token::ELLIPSIS); | 2883 bool is_spread = allow_harmony_spreadcalls() && (peek() == Token::ELLIPSIS); |
2765 int start_pos = peek_position(); | 2884 int start_pos = peek_position(); |
2766 if (is_spread) Consume(Token::ELLIPSIS); | 2885 if (is_spread) Consume(Token::ELLIPSIS); |
2767 | 2886 ExpressionT argument = this->ParseNestedAssignmentExpression( |
2768 ExpressionT argument = this->ParseAssignmentExpression( | |
2769 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); | 2887 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
2770 if (is_spread) { | 2888 if (is_spread) { |
2771 if (!spread_arg.IsValid()) { | 2889 if (!spread_arg.IsValid()) { |
2772 spread_arg.beg_pos = start_pos; | 2890 spread_arg.beg_pos = start_pos; |
2773 spread_arg.end_pos = peek_position(); | 2891 spread_arg.end_pos = peek_position(); |
2774 } | 2892 } |
2775 argument = factory()->NewSpread(argument, start_pos); | 2893 argument = factory()->NewSpread(argument, start_pos); |
2776 } | 2894 } |
2777 result->Add(argument, zone_); | 2895 result->Add(argument, zone_); |
2778 | 2896 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2811 } | 2929 } |
2812 | 2930 |
2813 return result; | 2931 return result; |
2814 } | 2932 } |
2815 | 2933 |
2816 // Precedence = 2 | 2934 // Precedence = 2 |
2817 template <class Traits> | 2935 template <class Traits> |
2818 typename ParserBase<Traits>::ExpressionT | 2936 typename ParserBase<Traits>::ExpressionT |
2819 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, | 2937 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
2820 ExpressionClassifier* classifier, | 2938 ExpressionClassifier* classifier, |
| 2939 ExpressionFlavor flavor, |
2821 bool* ok) { | 2940 bool* ok) { |
2822 // AssignmentExpression :: | 2941 // AssignmentExpression :: |
2823 // ConditionalExpression | 2942 // ConditionalExpression |
2824 // ArrowFunction | 2943 // ArrowFunction |
2825 // YieldExpression | 2944 // YieldExpression |
2826 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2945 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2827 | 2946 |
2828 int lhs_beg_pos = peek_position(); | 2947 int lhs_beg_pos = peek_position(); |
2829 | 2948 |
2830 if (peek() == Token::YIELD && is_generator()) { | 2949 if (peek() == Token::YIELD && is_generator()) { |
(...skipping 23 matching lines...) Expand all Loading... |
2854 scope->set_start_position(lhs_beg_pos); | 2973 scope->set_start_position(lhs_beg_pos); |
2855 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2974 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2856 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2975 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
2857 &duplicate_loc, CHECK_OK); | 2976 &duplicate_loc, CHECK_OK); |
2858 if (duplicate_loc.IsValid()) { | 2977 if (duplicate_loc.IsValid()) { |
2859 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2978 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2860 duplicate_loc); | 2979 duplicate_loc); |
2861 } | 2980 } |
2862 expression = this->ParseArrowFunctionLiteral( | 2981 expression = this->ParseArrowFunctionLiteral( |
2863 parameters, arrow_formals_classifier, CHECK_OK); | 2982 parameters, arrow_formals_classifier, CHECK_OK); |
| 2983 classifier->RecordPatternError( |
| 2984 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
| 2985 MessageTemplate::kInvalidDestructuringTarget); |
2864 return expression; | 2986 return expression; |
2865 } | 2987 } |
2866 | 2988 |
2867 // "expression" was not itself an arrow function parameter list, but it might | 2989 // "expression" was not itself an arrow function parameter list, but it might |
2868 // form part of one. Propagate speculative formal parameter error locations. | 2990 // form part of one. Propagate speculative formal parameter error locations. |
2869 classifier->Accumulate(arrow_formals_classifier, | 2991 classifier->Accumulate(arrow_formals_classifier, |
2870 ExpressionClassifier::StandardProductions | | 2992 ExpressionClassifier::StandardProductions | |
2871 ExpressionClassifier::FormalParametersProductions); | 2993 ExpressionClassifier::FormalParametersProductions); |
2872 | 2994 |
| 2995 int lhs_end_pos = scanner()->location().end_pos; |
2873 if (!Token::IsAssignmentOp(peek())) { | 2996 if (!Token::IsAssignmentOp(peek())) { |
| 2997 if (flavor == ElementExpression) { |
| 2998 CheckPatternElement(expression, lhs_beg_pos, lhs_end_pos, classifier); |
| 2999 } |
| 3000 ValidateExpression(classifier, CHECK_OK); |
| 3001 |
2874 if (fni_ != NULL) fni_->Leave(); | 3002 if (fni_ != NULL) fni_->Leave(); |
2875 // Parsed conditional expression only (no assignment). | 3003 // Parsed conditional expression only (no assignment). |
2876 return expression; | 3004 return expression; |
2877 } | 3005 } |
2878 | 3006 |
2879 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { | 3007 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { |
2880 BindingPatternUnexpectedToken(classifier); | 3008 BindingPatternUnexpectedToken(classifier); |
2881 } | 3009 } |
2882 | 3010 |
2883 expression = this->CheckAndRewriteReferenceExpression( | 3011 // Check that the LHS is a valid AssignmentPattern, or does not appear to be |
2884 expression, lhs_beg_pos, scanner()->location().end_pos, | 3012 // an ObjectLiteral or ArrayLiteral. |
2885 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 3013 bool has_seen_assignment_pattern = has_seen_assignment_pattern_; |
2886 expression = this->MarkExpressionAsAssigned(expression); | |
2887 | 3014 |
2888 Token::Value op = Next(); // Get assignment operator. | 3015 Token::Value op = Next(); // Get assignment operator. |
| 3016 |
2889 if (op != Token::ASSIGN) { | 3017 if (op != Token::ASSIGN) { |
2890 classifier->RecordBindingPatternError(scanner()->location(), | 3018 classifier->RecordPatternError(scanner()->location(), |
2891 MessageTemplate::kUnexpectedToken, | 3019 MessageTemplate::kUnexpectedToken, |
2892 Token::String(op)); | 3020 Token::String(op)); |
2893 } | 3021 } |
| 3022 bool was_pattern = CheckAssignmentPattern(expression, classifier, CHECK_OK); |
| 3023 has_seen_assignment_pattern_ |= was_pattern; |
| 3024 if (!was_pattern) { |
| 3025 expression = this->CheckAndRewriteReferenceExpression( |
| 3026 expression, lhs_beg_pos, lhs_end_pos, |
| 3027 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
| 3028 expression = this->MarkExpressionAsAssigned(expression); |
| 3029 } |
| 3030 |
2894 int pos = position(); | 3031 int pos = position(); |
2895 | 3032 |
2896 ExpressionClassifier rhs_classifier; | 3033 ExpressionClassifier rhs_classifier; |
2897 ExpressionT right = | 3034 ExpressionT right = |
2898 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); | 3035 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
2899 classifier->Accumulate(rhs_classifier, | 3036 classifier->Accumulate(rhs_classifier, |
2900 ExpressionClassifier::ExpressionProduction); | 3037 ExpressionClassifier::ExpressionProduction); |
2901 | 3038 |
2902 // TODO(1231235): We try to estimate the set of properties set by | 3039 // TODO(1231235): We try to estimate the set of properties set by |
2903 // constructors. We define a new property whenever there is an | 3040 // constructors. We define a new property whenever there is an |
(...skipping 14 matching lines...) Expand all Loading... |
2918 || op == Token::INIT_CONST_LEGACY | 3055 || op == Token::INIT_CONST_LEGACY |
2919 || op == Token::ASSIGN) | 3056 || op == Token::ASSIGN) |
2920 && (!right->IsCall() && !right->IsCallNew())) { | 3057 && (!right->IsCall() && !right->IsCallNew())) { |
2921 fni_->Infer(); | 3058 fni_->Infer(); |
2922 } else { | 3059 } else { |
2923 fni_->RemoveLastFunction(); | 3060 fni_->RemoveLastFunction(); |
2924 } | 3061 } |
2925 fni_->Leave(); | 3062 fni_->Leave(); |
2926 } | 3063 } |
2927 | 3064 |
2928 return factory()->NewAssignment(op, expression, right, pos); | 3065 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
| 3066 |
| 3067 if (has_seen_assignment_pattern_ && !has_seen_assignment_pattern) { |
| 3068 // Reset flag when assignment assignment chain has ended, and rewrite the |
| 3069 // entire chain. |
| 3070 has_seen_assignment_pattern_ = false; |
| 3071 return Traits::RewriteDestructuringAssignment(result); |
| 3072 } |
| 3073 |
| 3074 return result; |
2929 } | 3075 } |
2930 | 3076 |
2931 template <class Traits> | 3077 template <class Traits> |
2932 typename ParserBase<Traits>::ExpressionT | 3078 typename ParserBase<Traits>::ExpressionT |
2933 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, | 3079 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, |
2934 bool* ok) { | 3080 bool* ok) { |
2935 // YieldExpression :: | 3081 // YieldExpression :: |
2936 // 'yield' ([no line terminator] '*'? AssignmentExpression)? | 3082 // 'yield' ([no line terminator] '*'? AssignmentExpression)? |
2937 int pos = peek_position(); | 3083 int pos = peek_position(); |
2938 Expect(Token::YIELD, CHECK_OK); | 3084 Expect(Token::YIELD, CHECK_OK); |
(...skipping 13 matching lines...) Expand all Loading... |
2952 case Token::COMMA: | 3098 case Token::COMMA: |
2953 // The above set of tokens is the complete set of tokens that can appear | 3099 // The above set of tokens is the complete set of tokens that can appear |
2954 // after an AssignmentExpression, and none of them can start an | 3100 // after an AssignmentExpression, and none of them can start an |
2955 // AssignmentExpression. This allows us to avoid looking for an RHS for | 3101 // AssignmentExpression. This allows us to avoid looking for an RHS for |
2956 // a Yield::kSuspend operation, given only one look-ahead token. | 3102 // a Yield::kSuspend operation, given only one look-ahead token. |
2957 if (kind == Yield::kSuspend) | 3103 if (kind == Yield::kSuspend) |
2958 break; | 3104 break; |
2959 DCHECK_EQ(Yield::kDelegating, kind); | 3105 DCHECK_EQ(Yield::kDelegating, kind); |
2960 // Delegating yields require an RHS; fall through. | 3106 // Delegating yields require an RHS; fall through. |
2961 default: | 3107 default: |
2962 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 3108 expression = ParseNestedAssignmentExpression(false, classifier, |
| 3109 CHECK_OK); |
2963 break; | 3110 break; |
2964 } | 3111 } |
2965 } | 3112 } |
2966 if (kind == Yield::kDelegating) { | 3113 if (kind == Yield::kDelegating) { |
2967 // var iterator = subject[Symbol.iterator](); | 3114 // var iterator = subject[Symbol.iterator](); |
2968 expression = this->GetIterator(expression, factory()); | 3115 expression = this->GetIterator(expression, factory()); |
2969 } | 3116 } |
2970 typename Traits::Type::YieldExpression yield = | 3117 typename Traits::Type::YieldExpression yield = |
2971 factory()->NewYield(generator_object, expression, kind, pos); | 3118 factory()->NewYield(generator_object, expression, kind, pos); |
2972 return yield; | 3119 return yield; |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3986 ExpressionT error = this->NewThrowReferenceError(message, pos); | 4133 ExpressionT error = this->NewThrowReferenceError(message, pos); |
3987 return factory()->NewProperty(expression, error, pos); | 4134 return factory()->NewProperty(expression, error, pos); |
3988 } else { | 4135 } else { |
3989 this->ReportMessageAt(location, message, type); | 4136 this->ReportMessageAt(location, message, type); |
3990 *ok = false; | 4137 *ok = false; |
3991 return this->EmptyExpression(); | 4138 return this->EmptyExpression(); |
3992 } | 4139 } |
3993 } | 4140 } |
3994 | 4141 |
3995 | 4142 |
| 4143 template <typename Traits> |
| 4144 void ParserBase<Traits>::CheckPatternElement( |
| 4145 ExpressionT expression, int beg_pos, int end_pos, |
| 4146 ExpressionClassifier* classifier) { |
| 4147 if (expression->IsPatternOrLiteral() && |
| 4148 (classifier->is_valid_assignment_pattern() || |
| 4149 classifier->is_valid_binding_pattern())) { |
| 4150 return; |
| 4151 } |
| 4152 if (!expression->IsValidReferenceExpression()) { |
| 4153 classifier->RecordPatternError( |
| 4154 Scanner::Location(beg_pos, end_pos), |
| 4155 MessageTemplate::kInvalidDestructuringTarget); |
| 4156 } |
| 4157 } |
| 4158 |
| 4159 |
3996 #undef CHECK_OK | 4160 #undef CHECK_OK |
3997 #undef CHECK_OK_CUSTOM | 4161 #undef CHECK_OK_CUSTOM |
3998 | 4162 |
3999 | 4163 |
4000 template <typename Traits> | 4164 template <typename Traits> |
4001 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 4165 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
4002 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 4166 Token::Value property, PropertyKind type, bool is_static, bool is_generator, |
4003 bool* ok) { | 4167 bool* ok) { |
4004 DCHECK(!is_static); | 4168 DCHECK(!is_static); |
4005 DCHECK(!is_generator || type == kMethodProperty); | 4169 DCHECK(!is_generator || type == kMethodProperty); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4046 *ok = false; | 4210 *ok = false; |
4047 return; | 4211 return; |
4048 } | 4212 } |
4049 has_seen_constructor_ = true; | 4213 has_seen_constructor_ = true; |
4050 return; | 4214 return; |
4051 } | 4215 } |
4052 } | 4216 } |
4053 } } // v8::internal | 4217 } } // v8::internal |
4054 | 4218 |
4055 #endif // V8_PREPARSER_H | 4219 #endif // V8_PREPARSER_H |
OLD | NEW |