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

Side by Side Diff: src/parsing/parser-base.h

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: Check for 'name' properties at parse-time Created 4 years 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
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_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
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) {}
694 VariableProxy* proxy; 695 VariableProxy* proxy;
695 ExpressionT extends; 696 ExpressionT extends;
696 typename Types::ClassPropertyList properties; 697 typename Types::ClassPropertyList properties;
697 ExpressionListT instance_field_initializers; 698 ExpressionListT instance_field_initializers;
698 FunctionLiteralT constructor; 699 FunctionLiteralT constructor;
699 bool has_seen_constructor; 700 bool has_seen_constructor;
700 Variable* static_initializer_var; 701 Variable* static_initializer_var;
702 bool has_name_static_property;
701 }; 703 };
702 704
703 DeclarationScope* NewScriptScope() const { 705 DeclarationScope* NewScriptScope() const {
704 return new (zone()) DeclarationScope(zone(), ast_value_factory()); 706 return new (zone()) DeclarationScope(zone(), ast_value_factory());
705 } 707 }
706 708
707 DeclarationScope* NewVarblockScope() const { 709 DeclarationScope* NewVarblockScope() const {
708 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); 710 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
709 } 711 }
710 712
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 }; 1171 };
1170 1172
1171 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); 1173 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind);
1172 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, 1174 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind,
1173 bool* is_generator, bool* is_get, bool* is_set, 1175 bool* is_generator, bool* is_get, bool* is_set,
1174 bool* is_async, bool* is_computed_name, 1176 bool* is_async, bool* is_computed_name,
1175 bool* ok); 1177 bool* ok);
1176 ExpressionT ParseObjectLiteral(bool* ok); 1178 ExpressionT ParseObjectLiteral(bool* ok);
1177 ClassLiteralPropertyT ParseClassPropertyDefinition( 1179 ClassLiteralPropertyT ParseClassPropertyDefinition(
1178 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, 1180 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
1179 bool* has_seen_constructor, bool* ok); 1181 bool* has_seen_constructor, bool* has_name_static_property, bool* ok);
1180 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, 1182 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer,
1181 bool* ok); 1183 bool* ok);
1182 ObjectLiteralPropertyT ParseObjectPropertyDefinition( 1184 ObjectLiteralPropertyT ParseObjectPropertyDefinition(
1183 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); 1185 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok);
1184 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, 1186 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
1185 bool maybe_arrow, bool* ok); 1187 bool maybe_arrow, bool* ok);
1186 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, 1188 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
1187 bool* ok) { 1189 bool* ok) {
1188 return ParseArguments(first_spread_pos, false, ok); 1190 return ParseArguments(first_spread_pos, false, ok);
1189 } 1191 }
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 impl()->PushLiteralName(*name); 2134 impl()->PushLiteralName(*name);
2133 2135
2134 uint32_t index; 2136 uint32_t index;
2135 return impl()->IsArrayIndex(*name, &index) 2137 return impl()->IsArrayIndex(*name, &index)
2136 ? factory()->NewNumberLiteral(index, pos) 2138 ? factory()->NewNumberLiteral(index, pos)
2137 : factory()->NewStringLiteral(*name, pos); 2139 : factory()->NewStringLiteral(*name, pos);
2138 } 2140 }
2139 2141
2140 template <typename Impl> 2142 template <typename Impl>
2141 typename ParserBase<Impl>::ClassLiteralPropertyT 2143 typename ParserBase<Impl>::ClassLiteralPropertyT
2142 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, 2144 ParserBase<Impl>::ParseClassPropertyDefinition(
2143 bool has_extends, 2145 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
2144 bool* is_computed_name, 2146 bool* has_seen_constructor, bool* has_name_static_property, bool* ok) {
2145 bool* has_seen_constructor,
2146 bool* ok) {
2147 DCHECK(has_seen_constructor != nullptr); 2147 DCHECK(has_seen_constructor != nullptr);
2148 DCHECK(has_name_static_property != nullptr);
Toon Verwaest 2016/11/28 10:40:58 DCHECK_NOT_NULL
2148 bool is_get = false; 2149 bool is_get = false;
2149 bool is_set = false; 2150 bool is_set = false;
2150 bool is_generator = false; 2151 bool is_generator = false;
2151 bool is_async = false; 2152 bool is_async = false;
2152 bool is_static = false; 2153 bool is_static = false;
2153 PropertyKind kind = PropertyKind::kNotSet; 2154 PropertyKind kind = PropertyKind::kNotSet;
2154 2155
2155 Token::Value name_token = peek(); 2156 Token::Value name_token = peek();
2156 2157
2157 IdentifierT name = impl()->EmptyIdentifier(); 2158 IdentifierT name = impl()->EmptyIdentifier();
(...skipping 13 matching lines...) Expand all
2171 name_expression = ParsePropertyName( 2172 name_expression = ParsePropertyName(
2172 &name, &kind, &is_generator, &is_get, &is_set, &is_async, 2173 &name, &kind, &is_generator, &is_get, &is_set, &is_async,
2173 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2174 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2174 } 2175 }
2175 } else { 2176 } else {
2176 name_expression = ParsePropertyName( 2177 name_expression = ParsePropertyName(
2177 &name, &kind, &is_generator, &is_get, &is_set, &is_async, 2178 &name, &kind, &is_generator, &is_get, &is_set, &is_async,
2178 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2179 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2179 } 2180 }
2180 2181
2182 if (!*has_name_static_property && is_static && impl()->IsName(name)) {
2183 *has_name_static_property = true;
2184 }
2185
2181 switch (kind) { 2186 switch (kind) {
2182 case PropertyKind::kClassField: 2187 case PropertyKind::kClassField:
2183 case PropertyKind::kNotSet: // This case is a name followed by a name or 2188 case PropertyKind::kNotSet: // This case is a name followed by a name or
2184 // other property. Here we have to assume 2189 // other property. Here we have to assume
2185 // that's an uninitialized field followed by a 2190 // that's an uninitialized field followed by a
2186 // linebreak followed by a property, with ASI 2191 // linebreak followed by a property, with ASI
2187 // adding the semicolon. If not, there will be 2192 // adding the semicolon. If not, there will be
2188 // a syntax error after parsing the first name 2193 // a syntax error after parsing the first name
2189 // as an uninitialized field. 2194 // as an uninitialized field.
2190 case PropertyKind::kShorthandProperty: 2195 case PropertyKind::kShorthandProperty:
(...skipping 1910 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 4106
4102 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); 4107 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends);
4103 while (peek() != Token::RBRACE) { 4108 while (peek() != Token::RBRACE) {
4104 if (Check(Token::SEMICOLON)) continue; 4109 if (Check(Token::SEMICOLON)) continue;
4105 FuncNameInferrer::State fni_state(fni_); 4110 FuncNameInferrer::State fni_state(fni_);
4106 bool is_computed_name = false; // Classes do not care about computed 4111 bool is_computed_name = false; // Classes do not care about computed
4107 // property names here. 4112 // property names here.
4108 ExpressionClassifier property_classifier(this); 4113 ExpressionClassifier property_classifier(this);
4109 ClassLiteralPropertyT property = ParseClassPropertyDefinition( 4114 ClassLiteralPropertyT property = ParseClassPropertyDefinition(
4110 &checker, has_extends, &is_computed_name, 4115 &checker, has_extends, &is_computed_name,
4111 &class_info.has_seen_constructor, CHECK_OK); 4116 &class_info.has_seen_constructor, &class_info.has_name_static_property,
4117 CHECK_OK);
4112 impl()->RewriteNonPattern(CHECK_OK); 4118 impl()->RewriteNonPattern(CHECK_OK);
4113 impl()->AccumulateFormalParameterContainmentErrors(); 4119 impl()->AccumulateFormalParameterContainmentErrors();
4114 4120
4115 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); 4121 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK);
4116 impl()->InferFunctionName(); 4122 impl()->InferFunctionName();
4117 } 4123 }
4118 4124
4119 Expect(Token::RBRACE, CHECK_OK); 4125 Expect(Token::RBRACE, CHECK_OK);
4120 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); 4126 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok);
4121 } 4127 }
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
5463 has_seen_constructor_ = true; 5469 has_seen_constructor_ = true;
5464 return; 5470 return;
5465 } 5471 }
5466 } 5472 }
5467 5473
5468 5474
5469 } // namespace internal 5475 } // namespace internal
5470 } // namespace v8 5476 } // namespace v8
5471 5477
5472 #endif // V8_PARSING_PARSER_BASE_H 5478 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698