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

Unified Diff: src/parsing/pattern-rewriter.cc

Issue 2639333004: [pattern rewriter] Only desugar to call %ToName on computed properties (Closed)
Patch Set: add dcheck 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/pattern-rewriter.cc
diff --git a/src/parsing/pattern-rewriter.cc b/src/parsing/pattern-rewriter.cc
index ff2d66c00fcfc4fbd101a875f081504f3ea14ce8..78830297f4d979015b14a1f37c69a4c3577c0481 100644
--- a/src/parsing/pattern-rewriter.cc
+++ b/src/parsing/pattern-rewriter.cc
@@ -361,12 +361,11 @@ void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) {
// var { y, [x++]: a, ...c } = temp
// becomes
- // var temp1 = %ToName('y');
- // var y = temp[temp1]
- // var temp2 = %ToName(x++);
- // var a = temp[temp2];
+ // var y = temp.y;
+ // var temp1 = %ToName(x++);
+ // var a = temp[temp1];
// var c;
- // c = %CopyDataPropertiesWithExcludedProperties(temp, temp1, temp2);
+ // c = %CopyDataPropertiesWithExcludedProperties(temp, "y", temp1);
value = factory()->NewCallRuntime(
Runtime::kCopyDataPropertiesWithExcludedProperties,
rest_runtime_callargs, kNoSourcePosition);
@@ -379,17 +378,23 @@ void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
RewriteParameterScopes(key);
}
- // TODO(gsathya): Skip %ToName runtime call for literals.
if (pattern->has_rest_property()) {
- auto args = new (zone()) ZoneList<Expression*>(1, zone());
- args->Add(key, zone());
- auto to_name_key = CreateTempVar(factory()->NewCallRuntime(
- Runtime::kToName, args, kNoSourcePosition));
- key = factory()->NewVariableProxy(to_name_key);
+ Expression* excluded_property = key;
+
+ if (property->is_computed_name()) {
+ DCHECK(!key->IsPropertyName() || !key->IsNumberLiteral());
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(key, zone());
+ auto to_name_key = CreateTempVar(factory()->NewCallRuntime(
+ Runtime::kToName, args, kNoSourcePosition));
+ key = factory()->NewVariableProxy(to_name_key);
+ excluded_property = factory()->NewVariableProxy(to_name_key);
+ } else {
+ DCHECK(key->IsPropertyName() || key->IsNumberLiteral());
+ }
DCHECK(rest_runtime_callargs != nullptr);
- rest_runtime_callargs->Add(factory()->NewVariableProxy(to_name_key),
- zone());
+ rest_runtime_callargs->Add(excluded_property, zone());
}
value = factory()->NewProperty(factory()->NewVariableProxy(temp), key,
« 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