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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 | 683 |
684 struct ClassInfo { | 684 struct ClassInfo { |
685 public: | 685 public: |
686 explicit ClassInfo(ParserBase* parser) | 686 explicit ClassInfo(ParserBase* parser) |
687 : proxy(nullptr), | 687 : proxy(nullptr), |
688 extends(parser->impl()->EmptyExpression()), | 688 extends(parser->impl()->EmptyExpression()), |
689 properties(parser->impl()->NewClassPropertyList(4)), | 689 properties(parser->impl()->NewClassPropertyList(4)), |
690 instance_field_initializers(parser->impl()->NewExpressionList(0)), | 690 instance_field_initializers(parser->impl()->NewExpressionList(0)), |
691 constructor(parser->impl()->EmptyFunctionLiteral()), | 691 constructor(parser->impl()->EmptyFunctionLiteral()), |
692 has_seen_constructor(false), | 692 has_seen_constructor(false), |
693 static_initializer_var(nullptr) {} | 693 static_initializer_var(nullptr), |
694 has_name_static_property(false), | |
695 has_static_computed_names(false) {} | |
694 VariableProxy* proxy; | 696 VariableProxy* proxy; |
695 ExpressionT extends; | 697 ExpressionT extends; |
696 typename Types::ClassPropertyList properties; | 698 typename Types::ClassPropertyList properties; |
697 ExpressionListT instance_field_initializers; | 699 ExpressionListT instance_field_initializers; |
698 FunctionLiteralT constructor; | 700 FunctionLiteralT constructor; |
699 bool has_seen_constructor; | 701 bool has_seen_constructor; |
700 Variable* static_initializer_var; | 702 Variable* static_initializer_var; |
703 bool has_name_static_property; | |
704 bool has_static_computed_names; | |
701 }; | 705 }; |
702 | 706 |
703 DeclarationScope* NewScriptScope() const { | 707 DeclarationScope* NewScriptScope() const { |
704 return new (zone()) DeclarationScope(zone(), ast_value_factory()); | 708 return new (zone()) DeclarationScope(zone(), ast_value_factory()); |
705 } | 709 } |
706 | 710 |
707 DeclarationScope* NewVarblockScope() const { | 711 DeclarationScope* NewVarblockScope() const { |
708 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); | 712 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); |
709 } | 713 } |
710 | 714 |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 }; | 1173 }; |
1170 | 1174 |
1171 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1175 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
1172 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1176 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
1173 bool* is_generator, bool* is_get, bool* is_set, | 1177 bool* is_generator, bool* is_get, bool* is_set, |
1174 bool* is_async, bool* is_computed_name, | 1178 bool* is_async, bool* is_computed_name, |
1175 bool* ok); | 1179 bool* ok); |
1176 ExpressionT ParseObjectLiteral(bool* ok); | 1180 ExpressionT ParseObjectLiteral(bool* ok); |
1177 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1181 ClassLiteralPropertyT ParseClassPropertyDefinition( |
1178 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 1182 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
1179 bool* has_seen_constructor, bool* ok); | 1183 bool* has_seen_constructor, bool* has_name_static_property, |
1184 bool* has_static_computed_names, bool* ok); | |
1180 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, | 1185 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, |
1181 bool* ok); | 1186 bool* ok); |
1182 ObjectLiteralPropertyT ParseObjectPropertyDefinition( | 1187 ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
1183 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); | 1188 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); |
1184 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1189 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1185 bool maybe_arrow, bool* ok); | 1190 bool maybe_arrow, bool* ok); |
1186 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1191 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1187 bool* ok) { | 1192 bool* ok) { |
1188 return ParseArguments(first_spread_pos, false, ok); | 1193 return ParseArguments(first_spread_pos, false, ok); |
1189 } | 1194 } |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2132 impl()->PushLiteralName(*name); | 2137 impl()->PushLiteralName(*name); |
2133 | 2138 |
2134 uint32_t index; | 2139 uint32_t index; |
2135 return impl()->IsArrayIndex(*name, &index) | 2140 return impl()->IsArrayIndex(*name, &index) |
2136 ? factory()->NewNumberLiteral(index, pos) | 2141 ? factory()->NewNumberLiteral(index, pos) |
2137 : factory()->NewStringLiteral(*name, pos); | 2142 : factory()->NewStringLiteral(*name, pos); |
2138 } | 2143 } |
2139 | 2144 |
2140 template <typename Impl> | 2145 template <typename Impl> |
2141 typename ParserBase<Impl>::ClassLiteralPropertyT | 2146 typename ParserBase<Impl>::ClassLiteralPropertyT |
2142 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, | 2147 ParserBase<Impl>::ParseClassPropertyDefinition( |
2143 bool has_extends, | 2148 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
2144 bool* is_computed_name, | 2149 bool* has_seen_constructor, bool* has_name_static_property, |
2145 bool* has_seen_constructor, | 2150 bool* has_static_computed_names, bool* ok) { |
2146 bool* ok) { | 2151 DCHECK_NOT_NULL(has_seen_constructor); |
Henrique Ferreiro
2016/11/29 11:01:26
Is it ok to fix this in this CL?
Toon Verwaest
2016/11/29 12:27:47
Sure, drive-by fixes like this are entirely fine i
| |
2147 DCHECK(has_seen_constructor != nullptr); | 2152 DCHECK_NOT_NULL(has_name_static_property); |
2153 DCHECK_NOT_NULL(has_static_computed_names); | |
2148 bool is_get = false; | 2154 bool is_get = false; |
2149 bool is_set = false; | 2155 bool is_set = false; |
2150 bool is_generator = false; | 2156 bool is_generator = false; |
2151 bool is_async = false; | 2157 bool is_async = false; |
2152 bool is_static = false; | 2158 bool is_static = false; |
2153 PropertyKind kind = PropertyKind::kNotSet; | 2159 PropertyKind kind = PropertyKind::kNotSet; |
2154 | 2160 |
2155 Token::Value name_token = peek(); | 2161 Token::Value name_token = peek(); |
2156 | 2162 |
2157 IdentifierT name = impl()->EmptyIdentifier(); | 2163 IdentifierT name = impl()->EmptyIdentifier(); |
(...skipping 13 matching lines...) Expand all Loading... | |
2171 name_expression = ParsePropertyName( | 2177 name_expression = ParsePropertyName( |
2172 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2178 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2173 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2179 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2174 } | 2180 } |
2175 } else { | 2181 } else { |
2176 name_expression = ParsePropertyName( | 2182 name_expression = ParsePropertyName( |
2177 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2183 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2178 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2184 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2179 } | 2185 } |
2180 | 2186 |
2187 if (!*has_name_static_property && is_static && impl()->IsName(name)) { | |
2188 *has_name_static_property = true; | |
2189 } | |
2190 | |
2191 if (!*has_static_computed_names && is_static && *is_computed_name) { | |
2192 *has_static_computed_names = true; | |
2193 } | |
2194 | |
2181 switch (kind) { | 2195 switch (kind) { |
2182 case PropertyKind::kClassField: | 2196 case PropertyKind::kClassField: |
2183 case PropertyKind::kNotSet: // This case is a name followed by a name or | 2197 case PropertyKind::kNotSet: // This case is a name followed by a name or |
2184 // other property. Here we have to assume | 2198 // other property. Here we have to assume |
2185 // that's an uninitialized field followed by a | 2199 // that's an uninitialized field followed by a |
2186 // linebreak followed by a property, with ASI | 2200 // linebreak followed by a property, with ASI |
2187 // adding the semicolon. If not, there will be | 2201 // adding the semicolon. If not, there will be |
2188 // a syntax error after parsing the first name | 2202 // a syntax error after parsing the first name |
2189 // as an uninitialized field. | 2203 // as an uninitialized field. |
2190 case PropertyKind::kShorthandProperty: | 2204 case PropertyKind::kShorthandProperty: |
(...skipping 1910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4101 | 4115 |
4102 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); | 4116 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); |
4103 while (peek() != Token::RBRACE) { | 4117 while (peek() != Token::RBRACE) { |
4104 if (Check(Token::SEMICOLON)) continue; | 4118 if (Check(Token::SEMICOLON)) continue; |
4105 FuncNameInferrer::State fni_state(fni_); | 4119 FuncNameInferrer::State fni_state(fni_); |
4106 bool is_computed_name = false; // Classes do not care about computed | 4120 bool is_computed_name = false; // Classes do not care about computed |
4107 // property names here. | 4121 // property names here. |
4108 ExpressionClassifier property_classifier(this); | 4122 ExpressionClassifier property_classifier(this); |
4109 ClassLiteralPropertyT property = ParseClassPropertyDefinition( | 4123 ClassLiteralPropertyT property = ParseClassPropertyDefinition( |
4110 &checker, has_extends, &is_computed_name, | 4124 &checker, has_extends, &is_computed_name, |
4111 &class_info.has_seen_constructor, CHECK_OK); | 4125 &class_info.has_seen_constructor, &class_info.has_name_static_property, |
4126 &class_info.has_static_computed_names, CHECK_OK); | |
4112 impl()->RewriteNonPattern(CHECK_OK); | 4127 impl()->RewriteNonPattern(CHECK_OK); |
4113 impl()->AccumulateFormalParameterContainmentErrors(); | 4128 impl()->AccumulateFormalParameterContainmentErrors(); |
4114 | 4129 |
4115 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); | 4130 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); |
4116 impl()->InferFunctionName(); | 4131 impl()->InferFunctionName(); |
4117 } | 4132 } |
4118 | 4133 |
4119 Expect(Token::RBRACE, CHECK_OK); | 4134 Expect(Token::RBRACE, CHECK_OK); |
4120 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); | 4135 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); |
4121 } | 4136 } |
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5463 has_seen_constructor_ = true; | 5478 has_seen_constructor_ = true; |
5464 return; | 5479 return; |
5465 } | 5480 } |
5466 } | 5481 } |
5467 | 5482 |
5468 | 5483 |
5469 } // namespace internal | 5484 } // namespace internal |
5470 } // namespace v8 | 5485 } // namespace v8 |
5471 | 5486 |
5472 #endif // V8_PARSING_PARSER_BASE_H | 5487 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |