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

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

Issue 2481163002: Assign unique IDs to FunctionLiterals (Closed)
Patch Set: updates 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
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparse-data.h » ('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_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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ast_node_factory_(ast_value_factory), 202 ast_node_factory_(ast_value_factory),
203 runtime_call_stats_(runtime_call_stats), 203 runtime_call_stats_(runtime_call_stats),
204 parsing_on_main_thread_(parsing_on_main_thread), 204 parsing_on_main_thread_(parsing_on_main_thread),
205 parsing_module_(false), 205 parsing_module_(false),
206 stack_limit_(stack_limit), 206 stack_limit_(stack_limit),
207 zone_(zone), 207 zone_(zone),
208 classifier_(nullptr), 208 classifier_(nullptr),
209 scanner_(scanner), 209 scanner_(scanner),
210 stack_overflow_(false), 210 stack_overflow_(false),
211 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), 211 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile),
212 function_literal_id_(0),
212 allow_natives_(false), 213 allow_natives_(false),
213 allow_tailcalls_(false), 214 allow_tailcalls_(false),
214 allow_harmony_do_expressions_(false), 215 allow_harmony_do_expressions_(false),
215 allow_harmony_function_sent_(false), 216 allow_harmony_function_sent_(false),
216 allow_harmony_async_await_(false), 217 allow_harmony_async_await_(false),
217 allow_harmony_restrictive_generators_(false), 218 allow_harmony_restrictive_generators_(false),
218 allow_harmony_trailing_commas_(false), 219 allow_harmony_trailing_commas_(false),
219 allow_harmony_class_fields_(false) {} 220 allow_harmony_class_fields_(false) {}
220 221
221 #define ALLOW_ACCESSORS(name) \ 222 #define ALLOW_ACCESSORS(name) \
(...skipping 17 matching lines...) Expand all
239 240
240 void set_default_eager_compile_hint( 241 void set_default_eager_compile_hint(
241 FunctionLiteral::EagerCompileHint eager_compile_hint) { 242 FunctionLiteral::EagerCompileHint eager_compile_hint) {
242 default_eager_compile_hint_ = eager_compile_hint; 243 default_eager_compile_hint_ = eager_compile_hint;
243 } 244 }
244 245
245 FunctionLiteral::EagerCompileHint default_eager_compile_hint() const { 246 FunctionLiteral::EagerCompileHint default_eager_compile_hint() const {
246 return default_eager_compile_hint_; 247 return default_eager_compile_hint_;
247 } 248 }
248 249
250 int GetNextFunctionLiteralId() { return ++function_literal_id_; }
251 int GetLastFunctionLiteralId() const { return function_literal_id_; }
252
253 void SkipFunctionLiterals(int delta) { function_literal_id_ += delta; }
254
255 void ResetFunctionLiteralId() { function_literal_id_ = 0; }
256
249 Zone* zone() const { return zone_; } 257 Zone* zone() const { return zone_; }
250 258
251 protected: 259 protected:
252 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>; 260 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>;
253 261
254 enum AllowRestrictedIdentifiers { 262 enum AllowRestrictedIdentifiers {
255 kAllowRestrictedIdentifiers, 263 kAllowRestrictedIdentifiers,
256 kDontAllowRestrictedIdentifiers 264 kDontAllowRestrictedIdentifiers
257 }; 265 };
258 266
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 }; 1160 };
1153 1161
1154 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); 1162 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind);
1155 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, 1163 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind,
1156 bool* is_generator, bool* is_get, bool* is_set, 1164 bool* is_generator, bool* is_get, bool* is_set,
1157 bool* is_async, bool* is_computed_name, 1165 bool* is_async, bool* is_computed_name,
1158 bool* ok); 1166 bool* ok);
1159 ExpressionT ParseObjectLiteral(bool* ok); 1167 ExpressionT ParseObjectLiteral(bool* ok);
1160 ClassLiteralPropertyT ParseClassPropertyDefinition( 1168 ClassLiteralPropertyT ParseClassPropertyDefinition(
1161 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, 1169 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
1162 bool* has_seen_constructor, bool* ok); 1170 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind,
1171 bool* is_static, bool* ok);
1163 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, 1172 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer,
1164 bool* ok); 1173 bool* ok);
1165 ObjectLiteralPropertyT ParseObjectPropertyDefinition( 1174 ObjectLiteralPropertyT ParseObjectPropertyDefinition(
1166 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); 1175 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok);
1167 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, 1176 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
1168 bool maybe_arrow, bool* ok); 1177 bool maybe_arrow, bool* ok);
1169 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, 1178 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
1170 bool* ok) { 1179 bool* ok) {
1171 return ParseArguments(first_spread_pos, false, ok); 1180 return ParseArguments(first_spread_pos, false, ok);
1172 } 1181 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 1445
1437 private: 1446 private:
1438 Zone* zone_; 1447 Zone* zone_;
1439 ExpressionClassifier* classifier_; 1448 ExpressionClassifier* classifier_;
1440 1449
1441 Scanner* scanner_; 1450 Scanner* scanner_;
1442 bool stack_overflow_; 1451 bool stack_overflow_;
1443 1452
1444 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; 1453 FunctionLiteral::EagerCompileHint default_eager_compile_hint_;
1445 1454
1455 int function_literal_id_;
1456
1446 bool allow_natives_; 1457 bool allow_natives_;
1447 bool allow_tailcalls_; 1458 bool allow_tailcalls_;
1448 bool allow_harmony_do_expressions_; 1459 bool allow_harmony_do_expressions_;
1449 bool allow_harmony_function_sent_; 1460 bool allow_harmony_function_sent_;
1450 bool allow_harmony_async_await_; 1461 bool allow_harmony_async_await_;
1451 bool allow_harmony_restrictive_generators_; 1462 bool allow_harmony_restrictive_generators_;
1452 bool allow_harmony_trailing_commas_; 1463 bool allow_harmony_trailing_commas_;
1453 bool allow_harmony_class_fields_; 1464 bool allow_harmony_class_fields_;
1454 1465
1455 friend class DiscardableZoneScope; 1466 friend class DiscardableZoneScope;
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 impl()->PushLiteralName(*name); 2131 impl()->PushLiteralName(*name);
2121 2132
2122 uint32_t index; 2133 uint32_t index;
2123 return impl()->IsArrayIndex(*name, &index) 2134 return impl()->IsArrayIndex(*name, &index)
2124 ? factory()->NewNumberLiteral(index, pos) 2135 ? factory()->NewNumberLiteral(index, pos)
2125 : factory()->NewStringLiteral(*name, pos); 2136 : factory()->NewStringLiteral(*name, pos);
2126 } 2137 }
2127 2138
2128 template <typename Impl> 2139 template <typename Impl>
2129 typename ParserBase<Impl>::ClassLiteralPropertyT 2140 typename ParserBase<Impl>::ClassLiteralPropertyT
2130 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, 2141 ParserBase<Impl>::ParseClassPropertyDefinition(
2131 bool has_extends, 2142 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
2132 bool* is_computed_name, 2143 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind,
2133 bool* has_seen_constructor, 2144 bool* is_static, bool* ok) {
2134 bool* ok) {
2135 DCHECK(has_seen_constructor != nullptr); 2145 DCHECK(has_seen_constructor != nullptr);
2136 bool is_get = false; 2146 bool is_get = false;
2137 bool is_set = false; 2147 bool is_set = false;
2138 bool is_generator = false; 2148 bool is_generator = false;
2139 bool is_async = false; 2149 bool is_async = false;
2140 bool is_static = false; 2150 *is_static = false;
2151 *property_kind = ClassLiteralProperty::METHOD;
2141 PropertyKind kind = PropertyKind::kNotSet; 2152 PropertyKind kind = PropertyKind::kNotSet;
2142 2153
2143 Token::Value name_token = peek(); 2154 Token::Value name_token = peek();
2144 2155
2145 IdentifierT name = impl()->EmptyIdentifier(); 2156 IdentifierT name = impl()->EmptyIdentifier();
2146 ExpressionT name_expression; 2157 ExpressionT name_expression;
2147 if (name_token == Token::STATIC) { 2158 if (name_token == Token::STATIC) {
2148 Consume(Token::STATIC); 2159 Consume(Token::STATIC);
2149 if (peek() == Token::LPAREN) { 2160 if (peek() == Token::LPAREN) {
2150 kind = PropertyKind::kMethodProperty; 2161 kind = PropertyKind::kMethodProperty;
2151 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' 2162 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static'
2152 name_expression = factory()->NewStringLiteral(name, position()); 2163 name_expression = factory()->NewStringLiteral(name, position());
2153 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || 2164 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON ||
2154 peek() == Token::RBRACE) { 2165 peek() == Token::RBRACE) {
2155 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' 2166 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static'
2156 name_expression = factory()->NewStringLiteral(name, position()); 2167 name_expression = factory()->NewStringLiteral(name, position());
2157 } else { 2168 } else {
2158 is_static = true; 2169 *is_static = true;
2159 name_expression = ParsePropertyName( 2170 name_expression = ParsePropertyName(
2160 &name, &kind, &is_generator, &is_get, &is_set, &is_async, 2171 &name, &kind, &is_generator, &is_get, &is_set, &is_async,
2161 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2172 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2162 } 2173 }
2163 } else { 2174 } else {
2164 name_expression = ParsePropertyName( 2175 name_expression = ParsePropertyName(
2165 &name, &kind, &is_generator, &is_get, &is_set, &is_async, 2176 &name, &kind, &is_generator, &is_get, &is_set, &is_async,
2166 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2177 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2167 } 2178 }
2168 2179
2169 switch (kind) { 2180 switch (kind) {
2170 case PropertyKind::kClassField: 2181 case PropertyKind::kClassField:
2171 case PropertyKind::kNotSet: // This case is a name followed by a name or 2182 case PropertyKind::kNotSet: // This case is a name followed by a name or
2172 // other property. Here we have to assume 2183 // other property. Here we have to assume
2173 // that's an uninitialized field followed by a 2184 // that's an uninitialized field followed by a
2174 // linebreak followed by a property, with ASI 2185 // linebreak followed by a property, with ASI
2175 // adding the semicolon. If not, there will be 2186 // adding the semicolon. If not, there will be
2176 // a syntax error after parsing the first name 2187 // a syntax error after parsing the first name
2177 // as an uninitialized field. 2188 // as an uninitialized field.
2178 case PropertyKind::kShorthandProperty: 2189 case PropertyKind::kShorthandProperty:
2179 case PropertyKind::kValueProperty: 2190 case PropertyKind::kValueProperty:
2180 if (allow_harmony_class_fields()) { 2191 if (allow_harmony_class_fields()) {
2181 bool has_initializer = Check(Token::ASSIGN); 2192 bool has_initializer = Check(Token::ASSIGN);
2182 ExpressionT function_literal = ParseClassFieldForInitializer( 2193 ExpressionT function_literal = ParseClassFieldForInitializer(
2183 has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2194 has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2184 ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2195 ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2196 *property_kind = ClassLiteralProperty::FIELD;
2185 return factory()->NewClassLiteralProperty( 2197 return factory()->NewClassLiteralProperty(
2186 name_expression, function_literal, ClassLiteralProperty::FIELD, 2198 name_expression, function_literal, *property_kind, *is_static,
2187 is_static, *is_computed_name); 2199 *is_computed_name);
2188 } else { 2200 } else {
2189 ReportUnexpectedToken(Next()); 2201 ReportUnexpectedToken(Next());
2190 *ok = false; 2202 *ok = false;
2191 return impl()->EmptyClassLiteralProperty(); 2203 return impl()->EmptyClassLiteralProperty();
2192 } 2204 }
2193 2205
2194 case PropertyKind::kMethodProperty: { 2206 case PropertyKind::kMethodProperty: {
2195 DCHECK(!is_get && !is_set); 2207 DCHECK(!is_get && !is_set);
2196 2208
2197 // MethodDefinition 2209 // MethodDefinition
2198 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' 2210 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
2199 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' 2211 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
2200 2212
2201 if (!*is_computed_name) { 2213 if (!*is_computed_name) {
2202 checker->CheckClassMethodName( 2214 checker->CheckClassMethodName(
2203 name_token, PropertyKind::kMethodProperty, is_generator, is_async, 2215 name_token, PropertyKind::kMethodProperty, is_generator, is_async,
2204 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2216 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2205 } 2217 }
2206 2218
2207 FunctionKind kind = is_generator 2219 FunctionKind kind = is_generator
2208 ? FunctionKind::kConciseGeneratorMethod 2220 ? FunctionKind::kConciseGeneratorMethod
2209 : is_async ? FunctionKind::kAsyncConciseMethod 2221 : is_async ? FunctionKind::kAsyncConciseMethod
2210 : FunctionKind::kConciseMethod; 2222 : FunctionKind::kConciseMethod;
2211 2223
2212 if (!is_static && impl()->IsConstructor(name)) { 2224 if (!*is_static && impl()->IsConstructor(name)) {
2213 *has_seen_constructor = true; 2225 *has_seen_constructor = true;
2214 kind = has_extends ? FunctionKind::kSubclassConstructor 2226 kind = has_extends ? FunctionKind::kSubclassConstructor
2215 : FunctionKind::kBaseConstructor; 2227 : FunctionKind::kBaseConstructor;
2216 } 2228 }
2217 2229
2218 ExpressionT value = impl()->ParseFunctionLiteral( 2230 ExpressionT value = impl()->ParseFunctionLiteral(
2219 name, scanner()->location(), kSkipFunctionNameCheck, kind, 2231 name, scanner()->location(), kSkipFunctionNameCheck, kind,
2220 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, 2232 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod,
2221 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2233 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2222 2234
2235 *property_kind = ClassLiteralProperty::METHOD;
2223 return factory()->NewClassLiteralProperty(name_expression, value, 2236 return factory()->NewClassLiteralProperty(name_expression, value,
2224 ClassLiteralProperty::METHOD, 2237 *property_kind, *is_static,
2225 is_static, *is_computed_name); 2238 *is_computed_name);
2226 } 2239 }
2227 2240
2228 case PropertyKind::kAccessorProperty: { 2241 case PropertyKind::kAccessorProperty: {
2229 DCHECK((is_get || is_set) && !is_generator && !is_async); 2242 DCHECK((is_get || is_set) && !is_generator && !is_async);
2230 2243
2231 if (!*is_computed_name) { 2244 if (!*is_computed_name) {
2232 checker->CheckClassMethodName( 2245 checker->CheckClassMethodName(
2233 name_token, PropertyKind::kAccessorProperty, false, false, 2246 name_token, PropertyKind::kAccessorProperty, false, false,
2234 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2247 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2235 // Make sure the name expression is a string since we need a Name for 2248 // Make sure the name expression is a string since we need a Name for
2236 // Runtime_DefineAccessorPropertyUnchecked and since we can determine 2249 // Runtime_DefineAccessorPropertyUnchecked and since we can determine
2237 // this statically we can skip the extra runtime check. 2250 // this statically we can skip the extra runtime check.
2238 name_expression = 2251 name_expression =
2239 factory()->NewStringLiteral(name, name_expression->position()); 2252 factory()->NewStringLiteral(name, name_expression->position());
2240 } 2253 }
2241 2254
2242 FunctionKind kind = is_get ? FunctionKind::kGetterFunction 2255 FunctionKind kind = is_get ? FunctionKind::kGetterFunction
2243 : FunctionKind::kSetterFunction; 2256 : FunctionKind::kSetterFunction;
2244 2257
2245 FunctionLiteralT value = impl()->ParseFunctionLiteral( 2258 FunctionLiteralT value = impl()->ParseFunctionLiteral(
2246 name, scanner()->location(), kSkipFunctionNameCheck, kind, 2259 name, scanner()->location(), kSkipFunctionNameCheck, kind,
2247 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, 2260 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod,
2248 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); 2261 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
2249 2262
2250 if (!*is_computed_name) { 2263 if (!*is_computed_name) {
2251 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); 2264 impl()->AddAccessorPrefixToFunctionName(is_get, value, name);
2252 } 2265 }
2253 2266
2254 return factory()->NewClassLiteralProperty( 2267 *property_kind =
2255 name_expression, value, 2268 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER;
2256 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, 2269 return factory()->NewClassLiteralProperty(name_expression, value,
2257 is_static, *is_computed_name); 2270 *property_kind, *is_static,
2271 *is_computed_name);
2258 } 2272 }
2259 } 2273 }
2260 UNREACHABLE(); 2274 UNREACHABLE();
2261 return impl()->EmptyClassLiteralProperty(); 2275 return impl()->EmptyClassLiteralProperty();
2262 } 2276 }
2263 2277
2264 template <typename Impl> 2278 template <typename Impl>
2265 typename ParserBase<Impl>::FunctionLiteralT 2279 typename ParserBase<Impl>::FunctionLiteralT
2266 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, 2280 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
2267 bool* ok) { 2281 bool* ok) {
(...skipping 17 matching lines...) Expand all
2285 } 2299 }
2286 initializer_scope->set_end_position(scanner()->location().end_pos); 2300 initializer_scope->set_end_position(scanner()->location().end_pos);
2287 typename Types::StatementList body = impl()->NewStatementList(1); 2301 typename Types::StatementList body = impl()->NewStatementList(1);
2288 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); 2302 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone());
2289 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 2303 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
2290 impl()->EmptyIdentifierString(), initializer_scope, body, 2304 impl()->EmptyIdentifierString(), initializer_scope, body,
2291 initializer_state.materialized_literal_count(), 2305 initializer_state.materialized_literal_count(),
2292 initializer_state.expected_property_count(), 0, 0, 2306 initializer_state.expected_property_count(), 0, 0,
2293 FunctionLiteral::kNoDuplicateParameters, 2307 FunctionLiteral::kNoDuplicateParameters,
2294 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_, 2308 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_,
2295 initializer_scope->start_position(), true); 2309 initializer_scope->start_position(), true, GetNextFunctionLiteralId());
2296 function_literal->set_is_class_field_initializer(true); 2310 function_literal->set_is_class_field_initializer(true);
2297 return function_literal; 2311 return function_literal;
2298 } 2312 }
2299 2313
2300 template <typename Impl> 2314 template <typename Impl>
2301 typename ParserBase<Impl>::ObjectLiteralPropertyT 2315 typename ParserBase<Impl>::ObjectLiteralPropertyT
2302 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, 2316 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
2303 bool* is_computed_name, 2317 bool* is_computed_name,
2304 bool* ok) { 2318 bool* ok) {
2305 bool is_get = false; 2319 bool is_get = false;
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 // `=> ...` is never a valid expression, so report as syntax error. 3937 // `=> ...` is never a valid expression, so report as syntax error.
3924 // If next token is not `=>`, it's a syntax error anyways. 3938 // If next token is not `=>`, it's a syntax error anyways.
3925 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); 3939 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
3926 *ok = false; 3940 *ok = false;
3927 return impl()->EmptyExpression(); 3941 return impl()->EmptyExpression();
3928 } 3942 }
3929 3943
3930 StatementListT body = impl()->NullStatementList(); 3944 StatementListT body = impl()->NullStatementList();
3931 int materialized_literal_count = -1; 3945 int materialized_literal_count = -1;
3932 int expected_property_count = -1; 3946 int expected_property_count = -1;
3947 int function_literal_id = GetNextFunctionLiteralId();
3933 3948
3934 FunctionKind kind = formal_parameters.scope->function_kind(); 3949 FunctionKind kind = formal_parameters.scope->function_kind();
3935 FunctionLiteral::EagerCompileHint eager_compile_hint = 3950 FunctionLiteral::EagerCompileHint eager_compile_hint =
3936 default_eager_compile_hint_; 3951 default_eager_compile_hint_;
3937 bool can_preparse = impl()->parse_lazily() && 3952 bool can_preparse = impl()->parse_lazily() &&
3938 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; 3953 eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
3939 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this 3954 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
3940 // handling in Scope::ResolveVariable needs to change. 3955 // handling in Scope::ResolveVariable needs to change.
3941 bool is_lazy_top_level_function = 3956 bool is_lazy_top_level_function =
3942 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); 3957 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4060 PrintF(" [%s]: %i-%i (arrow function)\n", 4075 PrintF(" [%s]: %i-%i (arrow function)\n",
4061 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse", 4076 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse",
4062 scope->start_position(), scope->end_position()); 4077 scope->start_position(), scope->end_position());
4063 } 4078 }
4064 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 4079 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
4065 impl()->EmptyIdentifierString(), formal_parameters.scope, body, 4080 impl()->EmptyIdentifierString(), formal_parameters.scope, body,
4066 materialized_literal_count, expected_property_count, 4081 materialized_literal_count, expected_property_count,
4067 formal_parameters.num_parameters(), formal_parameters.function_length, 4082 formal_parameters.num_parameters(), formal_parameters.function_length,
4068 FunctionLiteral::kNoDuplicateParameters, 4083 FunctionLiteral::kNoDuplicateParameters,
4069 FunctionLiteral::kAnonymousExpression, eager_compile_hint, 4084 FunctionLiteral::kAnonymousExpression, eager_compile_hint,
4070 formal_parameters.scope->start_position(), has_braces); 4085 formal_parameters.scope->start_position(), has_braces,
4086 function_literal_id);
4071 4087
4072 function_literal->set_function_token_position( 4088 function_literal->set_function_token_position(
4073 formal_parameters.scope->start_position()); 4089 formal_parameters.scope->start_position());
4074 if (should_be_used_once_hint) { 4090 if (should_be_used_once_hint) {
4075 function_literal->set_should_be_used_once_hint(); 4091 function_literal->set_should_be_used_once_hint();
4076 } 4092 }
4077 4093
4078 impl()->AddFunctionForNameInference(function_literal); 4094 impl()->AddFunctionForNameInference(function_literal);
4079 4095
4080 return function_literal; 4096 return function_literal;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4118 ClassLiteralChecker checker(this); 4134 ClassLiteralChecker checker(this);
4119 4135
4120 Expect(Token::LBRACE, CHECK_OK); 4136 Expect(Token::LBRACE, CHECK_OK);
4121 4137
4122 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); 4138 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends);
4123 while (peek() != Token::RBRACE) { 4139 while (peek() != Token::RBRACE) {
4124 if (Check(Token::SEMICOLON)) continue; 4140 if (Check(Token::SEMICOLON)) continue;
4125 FuncNameInferrer::State fni_state(fni_); 4141 FuncNameInferrer::State fni_state(fni_);
4126 bool is_computed_name = false; // Classes do not care about computed 4142 bool is_computed_name = false; // Classes do not care about computed
4127 // property names here. 4143 // property names here.
4144 bool is_static;
4145 ClassLiteralProperty::Kind property_kind;
4128 ExpressionClassifier property_classifier(this); 4146 ExpressionClassifier property_classifier(this);
4147 // If we haven't seen the constructor yet, it potentially is the next
4148 // property.
4149 bool is_constructor = !class_info.has_seen_constructor;
4129 ClassLiteralPropertyT property = ParseClassPropertyDefinition( 4150 ClassLiteralPropertyT property = ParseClassPropertyDefinition(
Toon Verwaest 2016/11/28 11:12:34 This is getting a little out of hand, but I guess
4130 &checker, has_extends, &is_computed_name, 4151 &checker, has_extends, &is_computed_name,
4131 &class_info.has_seen_constructor, CHECK_OK); 4152 &class_info.has_seen_constructor, &property_kind, &is_static, CHECK_OK);
4153 is_constructor &= class_info.has_seen_constructor;
4132 impl()->RewriteNonPattern(CHECK_OK); 4154 impl()->RewriteNonPattern(CHECK_OK);
4133 impl()->AccumulateFormalParameterContainmentErrors(); 4155 impl()->AccumulateFormalParameterContainmentErrors();
4134 4156
4135 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); 4157 impl()->DeclareClassProperty(name, property, property_kind, is_static,
4158 is_constructor, &class_info, CHECK_OK);
4136 impl()->InferFunctionName(); 4159 impl()->InferFunctionName();
4137 } 4160 }
4138 4161
4139 Expect(Token::RBRACE, CHECK_OK); 4162 Expect(Token::RBRACE, CHECK_OK);
4140 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); 4163 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok);
4141 } 4164 }
4142 4165
4143 template <typename Impl> 4166 template <typename Impl>
4144 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body, 4167 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
4145 FunctionKind kind, 4168 FunctionKind kind,
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
5477 has_seen_constructor_ = true; 5500 has_seen_constructor_ = true;
5478 return; 5501 return;
5479 } 5502 }
5480 } 5503 }
5481 5504
5482 5505
5483 } // namespace internal 5506 } // namespace internal
5484 } // namespace v8 5507 } // namespace v8
5485 5508
5486 #endif // V8_PARSING_PARSER_BASE_H 5509 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparse-data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698