Chromium Code Reviews| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 DCHECK(scope()->outer_scope()->is_function_scope()); | 325 DCHECK(scope()->outer_scope()->is_function_scope()); |
| 326 DCHECK(scope()->calls_sloppy_eval()); | 326 DCHECK(scope()->calls_sloppy_eval()); |
| 327 | 327 |
| 328 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); | 328 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, | 331 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, |
| 332 Variable** temp_var) { | 332 Variable** temp_var) { |
| 333 auto temp = *temp_var = CreateTempVar(current_value_); | 333 auto temp = *temp_var = CreateTempVar(current_value_); |
| 334 | 334 |
| 335 ZoneList<Expression*>* rest_runtime_callargs = nullptr; | |
| 336 if (pattern->has_rest_property()) { | |
| 337 // non_rest_properties_count = pattern->properties()->length - 1; | |
| 338 // args_length = 1 + non_rest_properties_count because we need to | |
| 339 // pass temp as well to the runtime function. | |
| 340 int args_length = pattern->properties()->length(); | |
| 341 rest_runtime_callargs = | |
| 342 new (zone()) ZoneList<Expression*>(args_length, zone()); | |
| 343 rest_runtime_callargs->Add(factory()->NewVariableProxy(temp), zone()); | |
| 344 } | |
| 345 | |
| 335 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); | 346 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); |
| 336 | 347 |
| 337 for (ObjectLiteralProperty* property : *pattern->properties()) { | 348 for (ObjectLiteralProperty* property : *pattern->properties()) { |
| 338 PatternContext context = SetInitializerContextIfNeeded(property->value()); | 349 PatternContext context = SetInitializerContextIfNeeded(property->value()); |
| 350 Expression* value; | |
| 339 | 351 |
| 340 // Computed property names contain expressions which might require | 352 if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) { |
| 341 // scope rewriting. | 353 // var { a, b, ...c } = temp |
| 342 if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key()); | 354 // becomes |
| 355 // var c; | |
| 356 // c = %CopyDataPropertiesWithExcludedProperties(temp, a, b); | |
| 357 value = factory()->NewCallRuntime( | |
| 358 Runtime::kCopyDataPropertiesWithExcludedProperties, | |
| 359 rest_runtime_callargs, kNoSourcePosition); | |
| 360 } else { | |
| 361 Expression* key = property->key(); | |
| 343 | 362 |
| 344 RecurseIntoSubpattern( | 363 if (!key->IsLiteral()) { |
| 345 property->value(), | 364 // Computed property names contain expressions which might require |
| 346 factory()->NewProperty(factory()->NewVariableProxy(temp), | 365 // scope rewriting. |
| 347 property->key(), kNoSourcePosition)); | 366 RewriteParameterScopes(key); |
| 367 } | |
| 368 | |
| 369 if (pattern->has_rest_property()) { | |
| 370 Expression* excluded_property = property->key(); | |
| 371 | |
| 372 // We create a temporary variable for a computed property name | |
| 373 // so that we don't evaluate it twice when we include it in | |
|
adamk
2017/01/12 22:43:08
This isn't sufficient as it turns out: we need to
gsathya
2017/01/17 19:28:59
Done.
| |
| 374 // the excluded_properties list. | |
| 375 if (!key->IsLiteral()) { | |
| 376 auto temp_key = CreateTempVar(key); | |
| 377 key = factory()->NewVariableProxy(temp_key); | |
| 378 excluded_property = factory()->NewVariableProxy(temp_key); | |
| 379 } | |
| 380 | |
| 381 DCHECK(rest_runtime_callargs != nullptr); | |
| 382 rest_runtime_callargs->Add(excluded_property, zone()); | |
| 383 } | |
| 384 | |
| 385 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, | |
| 386 kNoSourcePosition); | |
| 387 } | |
| 388 | |
| 389 RecurseIntoSubpattern(property->value(), value); | |
| 348 set_context(context); | 390 set_context(context); |
| 349 } | 391 } |
| 350 } | 392 } |
| 351 | 393 |
| 352 | 394 |
| 353 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) { | 395 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) { |
| 354 Variable* temp_var = nullptr; | 396 Variable* temp_var = nullptr; |
| 355 VisitObjectLiteral(node, &temp_var); | 397 VisitObjectLiteral(node, &temp_var); |
| 356 } | 398 } |
| 357 | 399 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 NOT_A_PATTERN(TryFinallyStatement) | 734 NOT_A_PATTERN(TryFinallyStatement) |
| 693 NOT_A_PATTERN(UnaryOperation) | 735 NOT_A_PATTERN(UnaryOperation) |
| 694 NOT_A_PATTERN(VariableDeclaration) | 736 NOT_A_PATTERN(VariableDeclaration) |
| 695 NOT_A_PATTERN(WhileStatement) | 737 NOT_A_PATTERN(WhileStatement) |
| 696 NOT_A_PATTERN(WithStatement) | 738 NOT_A_PATTERN(WithStatement) |
| 697 NOT_A_PATTERN(Yield) | 739 NOT_A_PATTERN(Yield) |
| 698 | 740 |
| 699 #undef NOT_A_PATTERN | 741 #undef NOT_A_PATTERN |
| 700 } // namespace internal | 742 } // namespace internal |
| 701 } // namespace v8 | 743 } // namespace v8 |
| OLD | NEW |