| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 354 |
| 355 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); | 355 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); |
| 356 | 356 |
| 357 for (ObjectLiteralProperty* property : *pattern->properties()) { | 357 for (ObjectLiteralProperty* property : *pattern->properties()) { |
| 358 PatternContext context = SetInitializerContextIfNeeded(property->value()); | 358 PatternContext context = SetInitializerContextIfNeeded(property->value()); |
| 359 Expression* value; | 359 Expression* value; |
| 360 | 360 |
| 361 if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) { | 361 if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) { |
| 362 // var { y, [x++]: a, ...c } = temp | 362 // var { y, [x++]: a, ...c } = temp |
| 363 // becomes | 363 // becomes |
| 364 // var temp1 = %ToName('y'); | 364 // var y = temp.y; |
| 365 // var y = temp[temp1] | 365 // var temp1 = %ToName(x++); |
| 366 // var temp2 = %ToName(x++); | 366 // var a = temp[temp1]; |
| 367 // var a = temp[temp2]; | |
| 368 // var c; | 367 // var c; |
| 369 // c = %CopyDataPropertiesWithExcludedProperties(temp, temp1, temp2); | 368 // c = %CopyDataPropertiesWithExcludedProperties(temp, "y", temp1); |
| 370 value = factory()->NewCallRuntime( | 369 value = factory()->NewCallRuntime( |
| 371 Runtime::kCopyDataPropertiesWithExcludedProperties, | 370 Runtime::kCopyDataPropertiesWithExcludedProperties, |
| 372 rest_runtime_callargs, kNoSourcePosition); | 371 rest_runtime_callargs, kNoSourcePosition); |
| 373 } else { | 372 } else { |
| 374 Expression* key = property->key(); | 373 Expression* key = property->key(); |
| 375 | 374 |
| 376 if (!key->IsLiteral()) { | 375 if (!key->IsLiteral()) { |
| 377 // Computed property names contain expressions which might require | 376 // Computed property names contain expressions which might require |
| 378 // scope rewriting. | 377 // scope rewriting. |
| 379 RewriteParameterScopes(key); | 378 RewriteParameterScopes(key); |
| 380 } | 379 } |
| 381 | 380 |
| 382 // TODO(gsathya): Skip %ToName runtime call for literals. | |
| 383 if (pattern->has_rest_property()) { | 381 if (pattern->has_rest_property()) { |
| 384 auto args = new (zone()) ZoneList<Expression*>(1, zone()); | 382 Expression* excluded_property = key; |
| 385 args->Add(key, zone()); | 383 |
| 386 auto to_name_key = CreateTempVar(factory()->NewCallRuntime( | 384 if (property->is_computed_name()) { |
| 387 Runtime::kToName, args, kNoSourcePosition)); | 385 DCHECK(!key->IsPropertyName() || !key->IsNumberLiteral()); |
| 388 key = factory()->NewVariableProxy(to_name_key); | 386 auto args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 387 args->Add(key, zone()); |
| 388 auto to_name_key = CreateTempVar(factory()->NewCallRuntime( |
| 389 Runtime::kToName, args, kNoSourcePosition)); |
| 390 key = factory()->NewVariableProxy(to_name_key); |
| 391 excluded_property = factory()->NewVariableProxy(to_name_key); |
| 392 } else { |
| 393 DCHECK(key->IsPropertyName() || key->IsNumberLiteral()); |
| 394 } |
| 389 | 395 |
| 390 DCHECK(rest_runtime_callargs != nullptr); | 396 DCHECK(rest_runtime_callargs != nullptr); |
| 391 rest_runtime_callargs->Add(factory()->NewVariableProxy(to_name_key), | 397 rest_runtime_callargs->Add(excluded_property, zone()); |
| 392 zone()); | |
| 393 } | 398 } |
| 394 | 399 |
| 395 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, | 400 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, |
| 396 kNoSourcePosition); | 401 kNoSourcePosition); |
| 397 } | 402 } |
| 398 | 403 |
| 399 RecurseIntoSubpattern(property->value(), value); | 404 RecurseIntoSubpattern(property->value(), value); |
| 400 set_context(context); | 405 set_context(context); |
| 401 } | 406 } |
| 402 } | 407 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 NOT_A_PATTERN(TryFinallyStatement) | 749 NOT_A_PATTERN(TryFinallyStatement) |
| 745 NOT_A_PATTERN(UnaryOperation) | 750 NOT_A_PATTERN(UnaryOperation) |
| 746 NOT_A_PATTERN(VariableDeclaration) | 751 NOT_A_PATTERN(VariableDeclaration) |
| 747 NOT_A_PATTERN(WhileStatement) | 752 NOT_A_PATTERN(WhileStatement) |
| 748 NOT_A_PATTERN(WithStatement) | 753 NOT_A_PATTERN(WithStatement) |
| 749 NOT_A_PATTERN(Yield) | 754 NOT_A_PATTERN(Yield) |
| 750 | 755 |
| 751 #undef NOT_A_PATTERN | 756 #undef NOT_A_PATTERN |
| 752 } // namespace internal | 757 } // namespace internal |
| 753 } // namespace v8 | 758 } // namespace v8 |
| OLD | NEW |