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

Unified Diff: src/parser.cc

Issue 1396663004: Fix scopes for body of sloppy-mode for-in/of loop (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 | « no previous file | test/mjsunit/regress/regress-542099.js » ('j') | test/mjsunit/regress/regress-542099.js » ('J')
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 9113e8c7a4e3ba46b936b38d1f4627ff0c426cf4..108cca23d922e6a190a497d4d0058eb1353de82b 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3794,17 +3794,25 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// Make a block around the statement in case a lexical binding
// is introduced, e.g. by a FunctionDeclaration.
+ // This block must not be based on for_scope because if a lexical
rossberg 2015/10/13 10:52:04 What does "be based on" mean?
Dan Ehrenberg 2015/10/13 14:58:40 Clarified wording
+ // binding is introduced which overlaps with the for-in/of, the
+ // top level should actually point to the outer scope.
+ Scope* body_scope = NewScope(for_scope, BLOCK_SCOPE);
+ scope_ = body_scope;
Block* block =
factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
Statement* body = ParseSubStatement(NULL, CHECK_OK);
block->statements()->Add(body, zone());
InitializeForEachStatement(loop, expression, enumerable, block);
scope_ = saved_scope;
+ body_scope->set_end_position(scanner()->location().end_pos);
+ body_scope = body_scope->FinalizeBlockScope();
+ if (body_scope != nullptr) {
+ block->set_scope(body_scope);
+ }
for_scope->set_end_position(scanner()->location().end_pos);
for_scope = for_scope->FinalizeBlockScope();
- if (for_scope != nullptr) {
- block->set_scope(for_scope);
- }
+ DCHECK(for_scope == nullptr);
// Parsed for-in loop.
return loop;
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-542099.js » ('j') | test/mjsunit/regress/regress-542099.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698