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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 stack_overflow_(false), | 211 stack_overflow_(false), |
212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), | 212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
213 function_literal_id_(0), | 213 function_literal_id_(0), |
214 allow_natives_(false), | 214 allow_natives_(false), |
215 allow_tailcalls_(false), | 215 allow_tailcalls_(false), |
216 allow_harmony_do_expressions_(false), | 216 allow_harmony_do_expressions_(false), |
217 allow_harmony_function_sent_(false), | 217 allow_harmony_function_sent_(false), |
218 allow_harmony_async_await_(false), | 218 allow_harmony_async_await_(false), |
219 allow_harmony_restrictive_generators_(false), | 219 allow_harmony_restrictive_generators_(false), |
220 allow_harmony_trailing_commas_(false), | 220 allow_harmony_trailing_commas_(false), |
221 allow_harmony_class_fields_(false) {} | 221 allow_harmony_class_fields_(false), |
| 222 allow_harmony_object_spread_(false) {} |
222 | 223 |
223 #define ALLOW_ACCESSORS(name) \ | 224 #define ALLOW_ACCESSORS(name) \ |
224 bool allow_##name() const { return allow_##name##_; } \ | 225 bool allow_##name() const { return allow_##name##_; } \ |
225 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 226 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
226 | 227 |
227 ALLOW_ACCESSORS(natives); | 228 ALLOW_ACCESSORS(natives); |
228 ALLOW_ACCESSORS(tailcalls); | 229 ALLOW_ACCESSORS(tailcalls); |
229 ALLOW_ACCESSORS(harmony_do_expressions); | 230 ALLOW_ACCESSORS(harmony_do_expressions); |
230 ALLOW_ACCESSORS(harmony_function_sent); | 231 ALLOW_ACCESSORS(harmony_function_sent); |
231 ALLOW_ACCESSORS(harmony_async_await); | 232 ALLOW_ACCESSORS(harmony_async_await); |
232 ALLOW_ACCESSORS(harmony_restrictive_generators); | 233 ALLOW_ACCESSORS(harmony_restrictive_generators); |
233 ALLOW_ACCESSORS(harmony_trailing_commas); | 234 ALLOW_ACCESSORS(harmony_trailing_commas); |
234 ALLOW_ACCESSORS(harmony_class_fields); | 235 ALLOW_ACCESSORS(harmony_class_fields); |
| 236 ALLOW_ACCESSORS(harmony_object_spread); |
235 | 237 |
236 #undef ALLOW_ACCESSORS | 238 #undef ALLOW_ACCESSORS |
237 | 239 |
238 uintptr_t stack_limit() const { return stack_limit_; } | 240 uintptr_t stack_limit() const { return stack_limit_; } |
239 | 241 |
240 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 242 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
241 | 243 |
242 void set_default_eager_compile_hint( | 244 void set_default_eager_compile_hint( |
243 FunctionLiteral::EagerCompileHint eager_compile_hint) { | 245 FunctionLiteral::EagerCompileHint eager_compile_hint) { |
244 default_eager_compile_hint_ = eager_compile_hint; | 246 default_eager_compile_hint_ = eager_compile_hint; |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 ExpressionT ParseExpressionCoverGrammar(bool accept_IN, bool* ok); | 1145 ExpressionT ParseExpressionCoverGrammar(bool accept_IN, bool* ok); |
1144 | 1146 |
1145 ExpressionT ParseArrayLiteral(bool* ok); | 1147 ExpressionT ParseArrayLiteral(bool* ok); |
1146 | 1148 |
1147 enum class PropertyKind { | 1149 enum class PropertyKind { |
1148 kAccessorProperty, | 1150 kAccessorProperty, |
1149 kValueProperty, | 1151 kValueProperty, |
1150 kShorthandProperty, | 1152 kShorthandProperty, |
1151 kMethodProperty, | 1153 kMethodProperty, |
1152 kClassField, | 1154 kClassField, |
| 1155 kSpreadProperty, |
1153 kNotSet | 1156 kNotSet |
1154 }; | 1157 }; |
1155 | 1158 |
1156 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1159 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
1157 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1160 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
1158 bool* is_generator, bool* is_get, bool* is_set, | 1161 bool* is_generator, bool* is_get, bool* is_set, |
1159 bool* is_async, bool* is_computed_name, | 1162 bool* is_async, bool* is_computed_name, |
1160 bool* ok); | 1163 bool* ok); |
1161 ExpressionT ParseObjectLiteral(bool* ok); | 1164 ExpressionT ParseObjectLiteral(bool* ok); |
1162 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1165 ClassLiteralPropertyT ParseClassPropertyDefinition( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 int function_literal_id_; | 1452 int function_literal_id_; |
1450 | 1453 |
1451 bool allow_natives_; | 1454 bool allow_natives_; |
1452 bool allow_tailcalls_; | 1455 bool allow_tailcalls_; |
1453 bool allow_harmony_do_expressions_; | 1456 bool allow_harmony_do_expressions_; |
1454 bool allow_harmony_function_sent_; | 1457 bool allow_harmony_function_sent_; |
1455 bool allow_harmony_async_await_; | 1458 bool allow_harmony_async_await_; |
1456 bool allow_harmony_restrictive_generators_; | 1459 bool allow_harmony_restrictive_generators_; |
1457 bool allow_harmony_trailing_commas_; | 1460 bool allow_harmony_trailing_commas_; |
1458 bool allow_harmony_class_fields_; | 1461 bool allow_harmony_class_fields_; |
| 1462 bool allow_harmony_object_spread_; |
1459 | 1463 |
1460 friend class DiscardableZoneScope; | 1464 friend class DiscardableZoneScope; |
1461 }; | 1465 }; |
1462 | 1466 |
1463 template <typename Impl> | 1467 template <typename Impl> |
1464 ParserBase<Impl>::FunctionState::FunctionState( | 1468 ParserBase<Impl>::FunctionState::FunctionState( |
1465 FunctionState** function_state_stack, ScopeState** scope_stack, | 1469 FunctionState** function_state_stack, ScopeState** scope_stack, |
1466 DeclarationScope* scope) | 1470 DeclarationScope* scope) |
1467 : ScopeState(scope_stack, scope), | 1471 : ScopeState(scope_stack, scope), |
1468 next_materialized_literal_index_(0), | 1472 next_materialized_literal_index_(0), |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2102 *is_computed_name = true; | 2106 *is_computed_name = true; |
2103 Consume(Token::LBRACK); | 2107 Consume(Token::LBRACK); |
2104 ExpressionClassifier computed_name_classifier(this); | 2108 ExpressionClassifier computed_name_classifier(this); |
2105 expression = ParseAssignmentExpression(true, CHECK_OK); | 2109 expression = ParseAssignmentExpression(true, CHECK_OK); |
2106 impl()->RewriteNonPattern(CHECK_OK); | 2110 impl()->RewriteNonPattern(CHECK_OK); |
2107 impl()->AccumulateFormalParameterContainmentErrors(); | 2111 impl()->AccumulateFormalParameterContainmentErrors(); |
2108 Expect(Token::RBRACK, CHECK_OK); | 2112 Expect(Token::RBRACK, CHECK_OK); |
2109 break; | 2113 break; |
2110 } | 2114 } |
2111 | 2115 |
| 2116 case Token::ELLIPSIS: |
| 2117 if (allow_harmony_object_spread()) { |
| 2118 // TODO(gsathya): Implement destructuring/rest |
| 2119 classifier()->RecordPatternError(scanner()->location(), |
| 2120 MessageTemplate::kUnexpectedToken); |
| 2121 |
| 2122 *name = impl()->EmptyIdentifier(); |
| 2123 Consume(Token::ELLIPSIS); |
| 2124 ExpressionClassifier spread_classifier(this); |
| 2125 expression = ParseAssignmentExpression(true, CHECK_OK); |
| 2126 impl()->RewriteNonPattern(CHECK_OK); |
| 2127 impl()->AccumulateFormalParameterContainmentErrors(); |
| 2128 *kind = PropertyKind::kSpreadProperty; |
| 2129 return expression; |
| 2130 } |
| 2131 |
2112 default: | 2132 default: |
2113 *name = ParseIdentifierName(CHECK_OK); | 2133 *name = ParseIdentifierName(CHECK_OK); |
2114 break; | 2134 break; |
2115 } | 2135 } |
2116 | 2136 |
2117 if (*kind == PropertyKind::kNotSet) { | 2137 if (*kind == PropertyKind::kNotSet) { |
2118 SetPropertyKindFromToken(peek(), kind); | 2138 SetPropertyKindFromToken(peek(), kind); |
2119 } | 2139 } |
2120 | 2140 |
2121 if (*is_computed_name) { | 2141 if (*is_computed_name) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 if (!*is_computed_name) { | 2282 if (!*is_computed_name) { |
2263 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); | 2283 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
2264 } | 2284 } |
2265 | 2285 |
2266 *property_kind = | 2286 *property_kind = |
2267 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; | 2287 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; |
2268 return factory()->NewClassLiteralProperty(name_expression, value, | 2288 return factory()->NewClassLiteralProperty(name_expression, value, |
2269 *property_kind, *is_static, | 2289 *property_kind, *is_static, |
2270 *is_computed_name); | 2290 *is_computed_name); |
2271 } | 2291 } |
| 2292 case PropertyKind::kSpreadProperty: |
| 2293 UNREACHABLE(); |
2272 } | 2294 } |
2273 UNREACHABLE(); | 2295 UNREACHABLE(); |
2274 return impl()->EmptyClassLiteralProperty(); | 2296 return impl()->EmptyClassLiteralProperty(); |
2275 } | 2297 } |
2276 | 2298 |
2277 template <typename Impl> | 2299 template <typename Impl> |
2278 typename ParserBase<Impl>::FunctionLiteralT | 2300 typename ParserBase<Impl>::FunctionLiteralT |
2279 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, | 2301 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, |
2280 bool* ok) { | 2302 bool* ok) { |
2281 // Makes a concise method which evaluates and returns the initialized value | 2303 // Makes a concise method which evaluates and returns the initialized value |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 IdentifierT name = impl()->EmptyIdentifier(); | 2345 IdentifierT name = impl()->EmptyIdentifier(); |
2324 Token::Value name_token = peek(); | 2346 Token::Value name_token = peek(); |
2325 int next_beg_pos = scanner()->peek_location().beg_pos; | 2347 int next_beg_pos = scanner()->peek_location().beg_pos; |
2326 int next_end_pos = scanner()->peek_location().end_pos; | 2348 int next_end_pos = scanner()->peek_location().end_pos; |
2327 | 2349 |
2328 ExpressionT name_expression = ParsePropertyName( | 2350 ExpressionT name_expression = ParsePropertyName( |
2329 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2351 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2330 is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2352 is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2331 | 2353 |
2332 switch (kind) { | 2354 switch (kind) { |
| 2355 case PropertyKind::kSpreadProperty: |
| 2356 DCHECK(allow_harmony_object_spread()); |
| 2357 DCHECK(!is_get && !is_set && !is_generator && !is_async && |
| 2358 !*is_computed_name); |
| 2359 DCHECK(name_token == Token::ELLIPSIS); |
| 2360 |
| 2361 *is_computed_name = true; |
| 2362 |
| 2363 return factory()->NewObjectLiteralProperty( |
| 2364 impl()->GetLiteralTheHole(kNoSourcePosition), name_expression, |
| 2365 ObjectLiteralProperty::SPREAD, true); |
| 2366 |
2333 case PropertyKind::kValueProperty: { | 2367 case PropertyKind::kValueProperty: { |
2334 DCHECK(!is_get && !is_set && !is_generator && !is_async); | 2368 DCHECK(!is_get && !is_set && !is_generator && !is_async); |
2335 | 2369 |
2336 if (!*is_computed_name) { | 2370 if (!*is_computed_name) { |
2337 checker->CheckDuplicateProto(name_token); | 2371 checker->CheckDuplicateProto(name_token); |
2338 } | 2372 } |
2339 Consume(Token::COLON); | 2373 Consume(Token::COLON); |
2340 int beg_pos = peek_position(); | 2374 int beg_pos = peek_position(); |
2341 ExpressionT value = ParseAssignmentExpression( | 2375 ExpressionT value = ParseAssignmentExpression( |
2342 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2376 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
(...skipping 3156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 has_seen_constructor_ = true; | 5533 has_seen_constructor_ = true; |
5500 return; | 5534 return; |
5501 } | 5535 } |
5502 } | 5536 } |
5503 | 5537 |
5504 | 5538 |
5505 } // namespace internal | 5539 } // namespace internal |
5506 } // namespace v8 | 5540 } // namespace v8 |
5507 | 5541 |
5508 #endif // V8_PARSING_PARSER_BASE_H | 5542 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |