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

Unified Diff: src/parser.cc

Issue 377833003: Fix for-loop with const/let and empty condition/iteration statements. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | « no previous file | test/mjsunit/harmony/empty-for.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 261de4eed78e2021a3c8ff4dfa21dd7513bcb977..89d3ecb6180506df96171ec715261c7cf575a17c 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3001,7 +3001,7 @@ Statement* Parser::DesugarLetBindingsInForStatement(
}
// Make statement: if (flag == 1) { flag = 0; } else { next; }.
- {
+ if (next) {
Expression* compare = NULL;
// Make compare expresion: flag == 1.
{
@@ -3026,7 +3026,7 @@ Statement* Parser::DesugarLetBindingsInForStatement(
// Make statement: if (cond) { } else { break; }.
- {
+ if (cond) {
Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK);
Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition);
@@ -3248,11 +3248,31 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
scope_ = saved_scope;
for_scope->set_end_position(scanner()->location().end_pos);
} else {
- loop->Initialize(init, cond, next, body);
- result = loop;
scope_ = saved_scope;
for_scope->set_end_position(scanner()->location().end_pos);
- for_scope->FinalizeBlockScope();
+ for_scope = for_scope->FinalizeBlockScope();
+ if (for_scope) {
+ // Rewrite a for statement of the form
+ // for (const x = i; c; n) b
+ //
+ // into
+ //
+ // {
+ // const x = i;
+ // for (; c; n) b
+ // }
+ ASSERT(init != NULL);
+ Block* block =
+ factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
+ block->AddStatement(init, zone());
+ block->AddStatement(loop, zone());
+ block->set_scope(for_scope);
+ loop->Initialize(NULL, cond, next, body);
+ result = block;
+ } else {
+ loop->Initialize(init, cond, next, body);
+ result = loop;
+ }
}
return result;
}
« no previous file with comments | « no previous file | test/mjsunit/harmony/empty-for.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698