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

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 2639333004: [pattern rewriter] Only desugar to call %ToName on computed properties (Closed)
Patch Set: Created 3 years, 11 months 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/objects.cc ('k') | src/runtime/runtime-object.cc » ('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 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
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];
adamk 2017/01/19 02:04:13 Isn't this temp.y?
gsathya 2017/01/21 00:27:33 Done.
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 (!key->IsLiteral()) {
387 Runtime::kToName, args, kNoSourcePosition)); 385 auto args = new (zone()) ZoneList<Expression*>(1, zone());
388 key = factory()->NewVariableProxy(to_name_key); 386 args->Add(key, zone());
387 auto to_name_key = CreateTempVar(factory()->NewCallRuntime(
388 Runtime::kToName, args, kNoSourcePosition));
389 key = factory()->NewVariableProxy(to_name_key);
390 excluded_property = factory()->NewVariableProxy(to_name_key);
391 }
adamk 2017/01/19 02:04:13 Can you add a DCHECK in the else branch about the
gsathya 2017/01/21 00:27:32 Done.
389 392
390 DCHECK(rest_runtime_callargs != nullptr); 393 DCHECK(rest_runtime_callargs != nullptr);
391 rest_runtime_callargs->Add(factory()->NewVariableProxy(to_name_key), 394 rest_runtime_callargs->Add(excluded_property, zone());
392 zone());
393 } 395 }
394 396
395 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, 397 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key,
396 kNoSourcePosition); 398 kNoSourcePosition);
397 } 399 }
398 400
399 RecurseIntoSubpattern(property->value(), value); 401 RecurseIntoSubpattern(property->value(), value);
400 set_context(context); 402 set_context(context);
401 } 403 }
402 } 404 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 NOT_A_PATTERN(TryFinallyStatement) 746 NOT_A_PATTERN(TryFinallyStatement)
745 NOT_A_PATTERN(UnaryOperation) 747 NOT_A_PATTERN(UnaryOperation)
746 NOT_A_PATTERN(VariableDeclaration) 748 NOT_A_PATTERN(VariableDeclaration)
747 NOT_A_PATTERN(WhileStatement) 749 NOT_A_PATTERN(WhileStatement)
748 NOT_A_PATTERN(WithStatement) 750 NOT_A_PATTERN(WithStatement)
749 NOT_A_PATTERN(Yield) 751 NOT_A_PATTERN(Yield)
750 752
751 #undef NOT_A_PATTERN 753 #undef NOT_A_PATTERN
752 } // namespace internal 754 } // namespace internal
753 } // namespace v8 755 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698