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

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: add todo and test 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..59dd138cf3fb9456b419b6da7d8797740a5f367c 100644
--- a/src/parsing/pattern-rewriter.cc
+++ b/src/parsing/pattern-rewriter.cc
@@ -332,19 +332,61 @@ 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 { a, b, ...c } = temp
+ // becomes
+ // var c;
+ // c = %CopyDataPropertiesWithExcludedProperties(temp, a, b);
+ 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);
+ }
- // Computed property names contain expressions which might require
- // scope rewriting.
- if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key());
+ if (pattern->has_rest_property()) {
+ Expression* excluded_property = property->key();
+
+ // We create a temporary variable for a computed property name
+ // 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.
+ // the excluded_properties list.
+ if (!key->IsLiteral()) {
+ auto temp_key = CreateTempVar(key);
+ key = factory()->NewVariableProxy(temp_key);
+ excluded_property = factory()->NewVariableProxy(temp_key);
+ }
+
+ DCHECK(rest_runtime_callargs != nullptr);
+ rest_runtime_callargs->Add(excluded_property, zone());
+ }
+
+ 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