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

Unified Diff: src/rewriter.cc

Issue 1361403003: Implement ES6 completion semantics (--harmony-completion). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Proper rebase. Created 5 years, 2 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.cc ('k') | test/mjsunit/es6/block-for.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/rewriter.cc
diff --git a/src/rewriter.cc b/src/rewriter.cc
index 086a5a86f37ecb6cd8fb533eaac6ff913f9041f2..9df46c9beef236551026f893d1c89da3cefb970d 100644
--- a/src/rewriter.cc
+++ b/src/rewriter.cc
@@ -62,6 +62,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)
@@ -73,6 +76,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->statements()->Add(
+ factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
+ zone());
+ b->statements()->Add(s, zone());
+ return b;
+}
+
+
void Processor::Process(ZoneList<Statement*>* statements) {
for (int i = statements->length() - 1; i >= 0; --i) {
Visit(statements->at(i));
@@ -116,6 +133,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;
+ replacement_ = AssignUndefinedBefore(node);
+ }
}
@@ -127,6 +149,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);
+ }
}
@@ -166,6 +193,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);
+ }
}
@@ -198,6 +230,11 @@ void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) {
Visit(node->try_block());
node->set_try_block(replacement_->AsBlock());
replacement_ = node;
+
+ if (FLAG_harmony_completion && !is_set_) {
+ is_set_ = true;
+ replacement_ = AssignUndefinedBefore(node);
+ }
}
@@ -211,6 +248,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);
+ }
}
@@ -230,6 +272,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);
+ }
}
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/es6/block-for.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698