OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/ast/ast.h" | 5 #include "src/ast/ast.h" |
6 #include "src/messages.h" | 6 #include "src/messages.h" |
7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.h" |
8 #include "src/parsing/parameter-initializer-rewriter.h" | 8 #include "src/parsing/parameter-initializer-rewriter.h" |
9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parser.h" |
10 | 10 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 DCHECK(scope()->outer_scope()->is_function_scope()); | 333 DCHECK(scope()->outer_scope()->is_function_scope()); |
334 DCHECK(scope()->calls_sloppy_eval()); | 334 DCHECK(scope()->calls_sloppy_eval()); |
335 | 335 |
336 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); | 336 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); |
337 } | 337 } |
338 | 338 |
339 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, | 339 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, |
340 Variable** temp_var) { | 340 Variable** temp_var) { |
341 auto temp = *temp_var = CreateTempVar(current_value_); | 341 auto temp = *temp_var = CreateTempVar(current_value_); |
342 | 342 |
| 343 ZoneList<Expression*>* rest_runtime_callargs = nullptr; |
| 344 if (pattern->has_rest_property()) { |
| 345 // non_rest_properties_count = pattern->properties()->length - 1; |
| 346 // args_length = 1 + non_rest_properties_count because we need to |
| 347 // pass temp as well to the runtime function. |
| 348 int args_length = pattern->properties()->length(); |
| 349 rest_runtime_callargs = |
| 350 new (zone()) ZoneList<Expression*>(args_length, zone()); |
| 351 rest_runtime_callargs->Add(factory()->NewVariableProxy(temp), zone()); |
| 352 } |
| 353 |
343 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); | 354 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); |
344 | 355 |
345 for (ObjectLiteralProperty* property : *pattern->properties()) { | 356 for (ObjectLiteralProperty* property : *pattern->properties()) { |
346 PatternContext context = SetInitializerContextIfNeeded(property->value()); | 357 PatternContext context = SetInitializerContextIfNeeded(property->value()); |
| 358 Expression* value; |
347 | 359 |
348 // Computed property names contain expressions which might require | 360 if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) { |
349 // scope rewriting. | 361 // var { y, [x++]: a, ...c } = temp |
350 if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key()); | 362 // becomes |
| 363 // var temp1 = %ToName('y'); |
| 364 // var y = temp[temp1] |
| 365 // var temp2 = %ToName(x++); |
| 366 // var a = temp[temp2]; |
| 367 // var c; |
| 368 // c = %CopyDataPropertiesWithExcludedProperties(temp, temp1, temp2); |
| 369 value = factory()->NewCallRuntime( |
| 370 Runtime::kCopyDataPropertiesWithExcludedProperties, |
| 371 rest_runtime_callargs, kNoSourcePosition); |
| 372 } else { |
| 373 Expression* key = property->key(); |
351 | 374 |
352 RecurseIntoSubpattern( | 375 if (!key->IsLiteral()) { |
353 property->value(), | 376 // Computed property names contain expressions which might require |
354 factory()->NewProperty(factory()->NewVariableProxy(temp), | 377 // scope rewriting. |
355 property->key(), kNoSourcePosition)); | 378 RewriteParameterScopes(key); |
| 379 } |
| 380 |
| 381 // TODO(gsathya): Skip %ToName runtime call for literals. |
| 382 if (pattern->has_rest_property()) { |
| 383 auto args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 384 args->Add(key, zone()); |
| 385 auto to_name_key = CreateTempVar(factory()->NewCallRuntime( |
| 386 Runtime::kToName, args, kNoSourcePosition)); |
| 387 key = factory()->NewVariableProxy(to_name_key); |
| 388 |
| 389 DCHECK(rest_runtime_callargs != nullptr); |
| 390 rest_runtime_callargs->Add(factory()->NewVariableProxy(to_name_key), |
| 391 zone()); |
| 392 } |
| 393 |
| 394 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, |
| 395 kNoSourcePosition); |
| 396 } |
| 397 |
| 398 RecurseIntoSubpattern(property->value(), value); |
356 set_context(context); | 399 set_context(context); |
357 } | 400 } |
358 } | 401 } |
359 | 402 |
360 | 403 |
361 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) { | 404 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) { |
362 Variable* temp_var = nullptr; | 405 Variable* temp_var = nullptr; |
363 VisitObjectLiteral(node, &temp_var); | 406 VisitObjectLiteral(node, &temp_var); |
364 } | 407 } |
365 | 408 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 NOT_A_PATTERN(TryFinallyStatement) | 743 NOT_A_PATTERN(TryFinallyStatement) |
701 NOT_A_PATTERN(UnaryOperation) | 744 NOT_A_PATTERN(UnaryOperation) |
702 NOT_A_PATTERN(VariableDeclaration) | 745 NOT_A_PATTERN(VariableDeclaration) |
703 NOT_A_PATTERN(WhileStatement) | 746 NOT_A_PATTERN(WhileStatement) |
704 NOT_A_PATTERN(WithStatement) | 747 NOT_A_PATTERN(WithStatement) |
705 NOT_A_PATTERN(Yield) | 748 NOT_A_PATTERN(Yield) |
706 | 749 |
707 #undef NOT_A_PATTERN | 750 #undef NOT_A_PATTERN |
708 } // namespace internal | 751 } // namespace internal |
709 } // namespace v8 | 752 } // namespace v8 |
OLD | NEW |