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

Unified Diff: src/pattern-rewriter.cc

Issue 1151503002: [destructuring] Implement spread binding patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments addressed Created 5 years, 7 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/ast-value-factory.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pattern-rewriter.cc
diff --git a/src/pattern-rewriter.cc b/src/pattern-rewriter.cc
index 52ff8f60f10bca57bc487195f8107e0ddea3ad8e..8767b1f8d7424bf5e31279320c014aecc609f269 100644
--- a/src/pattern-rewriter.cc
+++ b/src/pattern-rewriter.cc
@@ -246,7 +246,14 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) {
factory()->NewBooleanLiteral(false, RelocInfo::kNoPosition));
auto result = CreateTempVar();
auto v = CreateTempVar();
+
+ Spread* spread = nullptr;
for (Expression* value : *node->values()) {
+ if (value->IsSpread()) {
+ spread = value->AsSpread();
+ break;
+ }
+
// if (!done) {
// result = IteratorNext(iterator);
// v = (done = result.done) ? undefined : result.value;
@@ -296,6 +303,39 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) {
RecurseIntoSubpattern(value, factory()->NewVariableProxy(v));
}
}
+
+ if (spread != nullptr) {
+ // array = [];
+ // if (!done) $concatIterableToArray(array, iterator);
+ auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone());
+ auto array = CreateTempVar(factory()->NewArrayLiteral(
+ empty_exprs,
+ // Reuse pattern's literal index - it is unused since there is no
arv (Not doing code reviews) 2015/05/20 14:40:50 nice.
+ // actual literal allocated.
+ node->literal_index(), is_strong(descriptor_->parser->language_mode()),
+ RelocInfo::kNoPosition));
+
+ auto arguments = new (zone()) ZoneList<Expression*>(2, zone());
+ arguments->Add(factory()->NewVariableProxy(array), zone());
+ arguments->Add(factory()->NewVariableProxy(iterator), zone());
+ auto spread_into_array_call = factory()->NewCallRuntime(
+ ast_value_factory()->concat_iterable_to_array_string(), nullptr,
+ arguments, RelocInfo::kNoPosition);
+
+ auto if_statement = factory()->NewIfStatement(
+ factory()->NewUnaryOperation(Token::NOT,
+ factory()->NewVariableProxy(done),
+ RelocInfo::kNoPosition),
+ factory()->NewExpressionStatement(spread_into_array_call,
+ RelocInfo::kNoPosition),
+ factory()->NewEmptyStatement(RelocInfo::kNoPosition),
+ RelocInfo::kNoPosition);
+ block_->AddStatement(if_statement, zone());
+
+
+ RecurseIntoSubpattern(spread->expression(),
+ factory()->NewVariableProxy(array));
+ }
}
« no previous file with comments | « src/ast-value-factory.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698