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/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 | 670 |
671 struct ClassInfo { | 671 struct ClassInfo { |
672 public: | 672 public: |
673 explicit ClassInfo(ParserBase* parser) | 673 explicit ClassInfo(ParserBase* parser) |
674 : proxy(nullptr), | 674 : proxy(nullptr), |
675 extends(parser->impl()->EmptyExpression()), | 675 extends(parser->impl()->EmptyExpression()), |
676 properties(parser->impl()->NewClassPropertyList(4)), | 676 properties(parser->impl()->NewClassPropertyList(4)), |
677 instance_field_initializers(parser->impl()->NewExpressionList(0)), | 677 instance_field_initializers(parser->impl()->NewExpressionList(0)), |
678 constructor(parser->impl()->EmptyFunctionLiteral()), | 678 constructor(parser->impl()->EmptyFunctionLiteral()), |
679 has_seen_constructor(false), | 679 has_seen_constructor(false), |
680 static_initializer_var(nullptr) {} | 680 static_initializer_var(nullptr), |
681 has_name_static_property(false), | |
682 has_static_computed_names(false) {} | |
681 VariableProxy* proxy; | 683 VariableProxy* proxy; |
682 ExpressionT extends; | 684 ExpressionT extends; |
683 typename Types::ClassPropertyList properties; | 685 typename Types::ClassPropertyList properties; |
684 ExpressionListT instance_field_initializers; | 686 ExpressionListT instance_field_initializers; |
685 FunctionLiteralT constructor; | 687 FunctionLiteralT constructor; |
686 bool has_seen_constructor; | 688 bool has_seen_constructor; |
687 Variable* static_initializer_var; | 689 Variable* static_initializer_var; |
690 bool has_name_static_property; | |
691 bool has_static_computed_names; | |
688 }; | 692 }; |
689 | 693 |
690 DeclarationScope* NewScriptScope() const { | 694 DeclarationScope* NewScriptScope() const { |
691 return new (zone()) DeclarationScope(zone(), ast_value_factory()); | 695 return new (zone()) DeclarationScope(zone(), ast_value_factory()); |
692 } | 696 } |
693 | 697 |
694 DeclarationScope* NewVarblockScope() const { | 698 DeclarationScope* NewVarblockScope() const { |
695 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); | 699 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); |
696 } | 700 } |
697 | 701 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 | 1165 |
1162 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1166 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
1163 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1167 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
1164 bool* is_generator, bool* is_get, bool* is_set, | 1168 bool* is_generator, bool* is_get, bool* is_set, |
1165 bool* is_async, bool* is_computed_name, | 1169 bool* is_async, bool* is_computed_name, |
1166 bool* ok); | 1170 bool* ok); |
1167 ExpressionT ParseObjectLiteral(bool* ok); | 1171 ExpressionT ParseObjectLiteral(bool* ok); |
1168 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1172 ClassLiteralPropertyT ParseClassPropertyDefinition( |
1169 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 1173 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
1170 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, | 1174 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
1171 bool* is_static, bool* ok); | 1175 bool* is_static, bool* has_name_static_property, bool* ok); |
1172 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, | 1176 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, |
1173 bool* ok); | 1177 bool* ok); |
1174 ObjectLiteralPropertyT ParseObjectPropertyDefinition( | 1178 ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
1175 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); | 1179 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); |
1176 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1180 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1177 bool maybe_arrow, bool* ok); | 1181 bool maybe_arrow, bool* ok); |
1178 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1182 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1179 bool* ok) { | 1183 bool* ok) { |
1180 return ParseArguments(first_spread_pos, false, ok); | 1184 return ParseArguments(first_spread_pos, false, ok); |
1181 } | 1185 } |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2134 return impl()->IsArrayIndex(*name, &index) | 2138 return impl()->IsArrayIndex(*name, &index) |
2135 ? factory()->NewNumberLiteral(index, pos) | 2139 ? factory()->NewNumberLiteral(index, pos) |
2136 : factory()->NewStringLiteral(*name, pos); | 2140 : factory()->NewStringLiteral(*name, pos); |
2137 } | 2141 } |
2138 | 2142 |
2139 template <typename Impl> | 2143 template <typename Impl> |
2140 typename ParserBase<Impl>::ClassLiteralPropertyT | 2144 typename ParserBase<Impl>::ClassLiteralPropertyT |
2141 ParserBase<Impl>::ParseClassPropertyDefinition( | 2145 ParserBase<Impl>::ParseClassPropertyDefinition( |
2142 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 2146 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
2143 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, | 2147 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
2144 bool* is_static, bool* ok) { | 2148 bool* is_static, bool* has_name_static_property, bool* ok) { |
2145 DCHECK(has_seen_constructor != nullptr); | 2149 DCHECK_NOT_NULL(has_seen_constructor); |
2150 DCHECK_NOT_NULL(has_name_static_property); | |
2146 bool is_get = false; | 2151 bool is_get = false; |
2147 bool is_set = false; | 2152 bool is_set = false; |
2148 bool is_generator = false; | 2153 bool is_generator = false; |
2149 bool is_async = false; | 2154 bool is_async = false; |
2150 *is_static = false; | 2155 *is_static = false; |
2151 *property_kind = ClassLiteralProperty::METHOD; | 2156 *property_kind = ClassLiteralProperty::METHOD; |
2152 PropertyKind kind = PropertyKind::kNotSet; | 2157 PropertyKind kind = PropertyKind::kNotSet; |
2153 | 2158 |
2154 Token::Value name_token = peek(); | 2159 Token::Value name_token = peek(); |
2155 | 2160 |
(...skipping 14 matching lines...) Expand all Loading... | |
2170 name_expression = ParsePropertyName( | 2175 name_expression = ParsePropertyName( |
2171 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2176 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2172 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2177 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2173 } | 2178 } |
2174 } else { | 2179 } else { |
2175 name_expression = ParsePropertyName( | 2180 name_expression = ParsePropertyName( |
2176 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2181 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2177 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2182 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2178 } | 2183 } |
2179 | 2184 |
2185 if (!*has_name_static_property && is_static && impl()->IsName(name)) { | |
2186 *has_name_static_property = true; | |
2187 } | |
2188 | |
2180 switch (kind) { | 2189 switch (kind) { |
2181 case PropertyKind::kClassField: | 2190 case PropertyKind::kClassField: |
2182 case PropertyKind::kNotSet: // This case is a name followed by a name or | 2191 case PropertyKind::kNotSet: // This case is a name followed by a name or |
2183 // other property. Here we have to assume | 2192 // other property. Here we have to assume |
2184 // that's an uninitialized field followed by a | 2193 // that's an uninitialized field followed by a |
2185 // linebreak followed by a property, with ASI | 2194 // linebreak followed by a property, with ASI |
2186 // adding the semicolon. If not, there will be | 2195 // adding the semicolon. If not, there will be |
2187 // a syntax error after parsing the first name | 2196 // a syntax error after parsing the first name |
2188 // as an uninitialized field. | 2197 // as an uninitialized field. |
2189 case PropertyKind::kShorthandProperty: | 2198 case PropertyKind::kShorthandProperty: |
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4137 bool is_computed_name = false; // Classes do not care about computed | 4146 bool is_computed_name = false; // Classes do not care about computed |
4138 // property names here. | 4147 // property names here. |
4139 bool is_static; | 4148 bool is_static; |
4140 ClassLiteralProperty::Kind property_kind; | 4149 ClassLiteralProperty::Kind property_kind; |
4141 ExpressionClassifier property_classifier(this); | 4150 ExpressionClassifier property_classifier(this); |
4142 // If we haven't seen the constructor yet, it potentially is the next | 4151 // If we haven't seen the constructor yet, it potentially is the next |
4143 // property. | 4152 // property. |
4144 bool is_constructor = !class_info.has_seen_constructor; | 4153 bool is_constructor = !class_info.has_seen_constructor; |
4145 ClassLiteralPropertyT property = ParseClassPropertyDefinition( | 4154 ClassLiteralPropertyT property = ParseClassPropertyDefinition( |
4146 &checker, has_extends, &is_computed_name, | 4155 &checker, has_extends, &is_computed_name, |
4147 &class_info.has_seen_constructor, &property_kind, &is_static, CHECK_OK); | 4156 &class_info.has_seen_constructor, &property_kind, &is_static, |
4157 &class_info.has_name_static_property, CHECK_OK); | |
4158 if (!class_info.has_static_computed_names && is_static && | |
Henrique Ferreiro
2016/12/02 13:02:32
I moved this out of ParseClassPropertyDefinition g
| |
4159 is_computed_name) { | |
4160 class_info.has_static_computed_names = true; | |
4161 } | |
4148 is_constructor &= class_info.has_seen_constructor; | 4162 is_constructor &= class_info.has_seen_constructor; |
4149 impl()->RewriteNonPattern(CHECK_OK); | 4163 impl()->RewriteNonPattern(CHECK_OK); |
4150 impl()->AccumulateFormalParameterContainmentErrors(); | 4164 impl()->AccumulateFormalParameterContainmentErrors(); |
4151 | 4165 |
4152 impl()->DeclareClassProperty(name, property, property_kind, is_static, | 4166 impl()->DeclareClassProperty(name, property, property_kind, is_static, |
4153 is_constructor, &class_info, CHECK_OK); | 4167 is_constructor, &class_info, CHECK_OK); |
4154 impl()->InferFunctionName(); | 4168 impl()->InferFunctionName(); |
4155 } | 4169 } |
4156 | 4170 |
4157 Expect(Token::RBRACE, CHECK_OK); | 4171 Expect(Token::RBRACE, CHECK_OK); |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5495 has_seen_constructor_ = true; | 5509 has_seen_constructor_ = true; |
5496 return; | 5510 return; |
5497 } | 5511 } |
5498 } | 5512 } |
5499 | 5513 |
5500 | 5514 |
5501 } // namespace internal | 5515 } // namespace internal |
5502 } // namespace v8 | 5516 } // namespace v8 |
5503 | 5517 |
5504 #endif // V8_PARSING_PARSER_BASE_H | 5518 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |