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

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: Remove comment 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
Index: src/parsing/pattern-rewriter.cc
diff --git a/src/parsing/pattern-rewriter.cc b/src/parsing/pattern-rewriter.cc
index edd283e9d62f7a484b4f16a7149b0ab4d7903ae2..881817f9771c1a1fb3bca24864caa5cf274a7bf7 100644
--- a/src/parsing/pattern-rewriter.cc
+++ b/src/parsing/pattern-rewriter.cc
@@ -332,19 +332,59 @@ void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
Variable** temp_var) {
auto temp = *temp_var = CreateTempVar(current_value_);
+ ZoneList<Expression*>* excluded_properties;
+ if (pattern->has_rest_property()) {
+ int non_rest_properties = pattern->properties()->length() - 1;
+ excluded_properties =
+ new (zone()) ZoneList<Expression*>(non_rest_properties, zone());
+ } else {
+ excluded_properties = new (zone()) ZoneList<Expression*>(0, 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 { a, b, ...c } = temp
+ // becomes
+ // var c;
+ // c = %CopyDataProperties(temp, [a, b]);
adamk 2017/01/10 23:22:56 Can you add something about the desugaring of comp
gsathya 2017/01/12 21:27:41 There's a comment below where I handle the compute
adamk 2017/01/12 22:43:08 Yeah, I was thinking that this should basically re
+ auto args = new (zone()) ZoneList<Expression*>(2, zone());
+ args->Add(factory()->NewVariableProxy(temp), zone());
+ args->Add(
+ factory()->NewArrayLiteral(
+ excluded_properties, pattern->literal_index(), kNoSourcePosition),
+ zone());
- // Computed property names contain expressions which might require
- // scope rewriting.
- if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key());
+ value = factory()->NewCallRuntime(
+ Runtime::kCopyDataPropertiesWithExcludedProperties, args,
+ kNoSourcePosition);
+ } else {
+ Expression* key = property->key();
+
+ if (!key->IsLiteral()) {
+ // Computed property names contain expressions which might require
+ // scope rewriting.
+ RewriteParameterScopes(key);
+
+ // We create a temporary variable for a computed property name
+ // so that we don't evaluate it twice when we include it in
+ // the excluded_properties list.
+ key = factory()->NewVariableProxy(CreateTempVar(key));
adamk 2017/01/10 23:22:56 You need to assign CreateTempVar to something so t
gsathya 2017/01/12 21:27:41 Done.
+ }
+
+ if (pattern->has_rest_property()) {
+ excluded_properties->Add(key, zone());
adamk 2017/01/10 23:22:56 As noted above, this needs to be a NewVariableProx
gsathya 2017/01/12 21:27:41 Done.
+ }
+
+ 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);
}
}

Powered by Google App Engine
This is Rietveld 408576698