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

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: fix nits 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/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('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 9eb3f0665be3030344a7fc4522310b6159eb2e77..9847b223f2be07f39e34453d7fd2188e206d928c 100644
--- a/src/parsing/pattern-rewriter.cc
+++ b/src/parsing/pattern-rewriter.cc
@@ -340,19 +340,62 @@ void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
Variable** temp_var) {
auto temp = *temp_var = CreateTempVar(current_value_);
+ ZoneList<Expression*>* rest_runtime_callargs = nullptr;
+ if (pattern->has_rest_property()) {
+ // non_rest_properties_count = pattern->properties()->length - 1;
+ // args_length = 1 + non_rest_properties_count because we need to
+ // pass temp as well to the runtime function.
+ int args_length = pattern->properties()->length();
+ rest_runtime_callargs =
+ new (zone()) ZoneList<Expression*>(args_length, zone());
+ rest_runtime_callargs->Add(factory()->NewVariableProxy(temp), zone());
+ }
+
block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone());
for (ObjectLiteralProperty* property : *pattern->properties()) {
PatternContext context = SetInitializerContextIfNeeded(property->value());
+ Expression* value;
+
+ 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 c;
+ // c = %CopyDataPropertiesWithExcludedProperties(temp, temp1, temp2);
+ value = factory()->NewCallRuntime(
+ Runtime::kCopyDataPropertiesWithExcludedProperties,
+ rest_runtime_callargs, kNoSourcePosition);
+ } else {
+ Expression* key = property->key();
+
+ if (!key->IsLiteral()) {
+ // Computed property names contain expressions which might require
+ // scope rewriting.
+ 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);
+
+ DCHECK(rest_runtime_callargs != nullptr);
+ rest_runtime_callargs->Add(factory()->NewVariableProxy(to_name_key),
+ zone());
+ }
- // Computed property names contain expressions which might require
- // scope rewriting.
- if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key());
+ value = factory()->NewProperty(factory()->NewVariableProxy(temp), key,
+ kNoSourcePosition);
+ }
- RecurseIntoSubpattern(
- property->value(),
- factory()->NewProperty(factory()->NewVariableProxy(temp),
- property->key(), kNoSourcePosition));
+ RecurseIntoSubpattern(property->value(), value);
set_context(context);
}
}
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698