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

Unified Diff: src/pattern-rewriter.cc

Issue 1146683002: [destructuring] Implement initializers in patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased onto ToT 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/parser.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 9f24a395a25c4a24d1a17a9e7f75eb0b97bef1ee..a97c009708cdd1ffbb793654a1b5838339cf3e8c 100644
--- a/src/pattern-rewriter.cc
+++ b/src/pattern-rewriter.cc
@@ -208,17 +208,22 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
}
-void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) {
- auto temp = TemporaryDeclarationScope()->NewTemporary(
- ast_value_factory()->empty_string());
+Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) {
+ auto temp_scope = descriptor_->parser->scope_->DeclarationScope();
+ auto temp = temp_scope->NewTemporary(ast_value_factory()->empty_string());
auto assignment =
factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp),
- current_value_, RelocInfo::kNoPosition);
+ value, RelocInfo::kNoPosition);
block_->AddStatement(
factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
zone());
+ return temp;
+}
+
+void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) {
+ auto temp = CreateTempVar(current_value_);
if (pattern->properties()->length() == 0) {
block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp),
zone());
@@ -240,7 +245,20 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) {
void Parser::PatternRewriter::VisitAssignment(Assignment* node) {
- // TODO(dslomov): implement.
+ // let {<pattern> = <init>} = <value>
+ // becomes
+ // temp = <value>;
+ // <pattern> = temp === undefined ? <init> : temp;
+ DCHECK(node->op() == Token::ASSIGN);
+ auto temp = CreateTempVar(current_value_);
+ Expression* is_undefined = factory()->NewCompareOperation(
+ Token::EQ_STRICT, factory()->NewVariableProxy(temp),
+ factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
+ RelocInfo::kNoPosition);
+ Expression* value = factory()->NewConditional(
+ is_undefined, node->value(), factory()->NewVariableProxy(temp),
+ RelocInfo::kNoPosition);
+ RecurseIntoSubpattern(node->target(), value);
}
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698