Index: src/rewriter.cc |
diff --git a/src/rewriter.cc b/src/rewriter.cc |
index 2de25407e3fe608bb95857be826023be69b83ac4..bd4630c0923e683739d6d0d30ecf835b046b827b 100644 |
--- a/src/rewriter.cc |
+++ b/src/rewriter.cc |
@@ -49,6 +49,9 @@ class Processor: public AstVisitor { |
Token::ASSIGN, result_proxy, value, RelocInfo::kNoPosition); |
} |
+ // Inserts '.result = undefined' in front of the given statement. |
+ Statement* AssignUndefinedBefore(Statement* s); |
+ |
// Node visitors. |
#define DEF_VISIT(type) virtual void Visit##type(type* node) override; |
AST_NODE_LIST(DEF_VISIT) |
@@ -60,6 +63,20 @@ class Processor: public AstVisitor { |
}; |
+Statement* Processor::AssignUndefinedBefore(Statement* s) { |
+ Expression* result_proxy = factory()->NewVariableProxy(result_); |
+ Expression* undef = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
+ Expression* assignment = factory()->NewAssignment( |
+ Token::ASSIGN, result_proxy, undef, RelocInfo::kNoPosition); |
+ Block* b = factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
+ b->AddStatement( |
+ factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
+ zone()); |
+ b->AddStatement(s, zone()); |
+ return b; |
+} |
+ |
+ |
void Processor::Process(ZoneList<Statement*>* statements) { |
for (int i = statements->length() - 1; i >= 0; --i) { |
Visit(statements->at(i)); |
@@ -103,6 +120,11 @@ void Processor::VisitIfStatement(IfStatement* node) { |
node->set_else_statement(replacement_); |
is_set_ = is_set_ && set_in_then; |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
rossberg
2015/09/28 14:09:22
Why not move this into AssignUndefinedBeforeNode?
neis
2015/10/05 10:57:28
I prefer the is_set_ logic to be explicit in the V
|
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |
@@ -114,6 +136,11 @@ void Processor::VisitIterationStatement(IterationStatement* node) { |
node->set_body(replacement_); |
is_set_ = is_set_ && set_after; |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |
@@ -153,6 +180,11 @@ void Processor::VisitTryCatchStatement(TryCatchStatement* node) { |
node->set_catch_block(static_cast<Block*>(replacement_)); |
is_set_ = is_set_ && set_in_try; |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |
@@ -163,6 +195,11 @@ void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
Visit(node->try_block()); // Exception will not be caught. |
node->set_try_block(static_cast<Block*>(replacement_)); |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |
@@ -176,6 +213,11 @@ void Processor::VisitSwitchStatement(SwitchStatement* node) { |
} |
is_set_ = is_set_ && set_after; |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |
@@ -195,6 +237,11 @@ void Processor::VisitWithStatement(WithStatement* node) { |
Visit(node->statement()); |
node->set_statement(replacement_); |
replacement_ = node; |
+ |
+ if (FLAG_harmony_completion && !is_set_) { |
+ is_set_ = true; |
+ replacement_ = AssignUndefinedBefore(node); |
+ } |
} |