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

Unified Diff: src/parser.cc

Issue 1404803002: Add a lexical scope for the body of a with statement (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-542100.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 be80956b69323bd8890d0da824f5f83cbfa2c36f..5a5ed39ed08b06ce973debae1c47249c910f094e 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2956,13 +2956,28 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
scope_->DeclarationScope()->RecordWithStatement();
Scope* with_scope = NewScope(scope_, WITH_SCOPE);
- Statement* stmt;
+ Block* body;
{ BlockState block_state(&scope_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos);
- stmt = ParseSubStatement(labels, CHECK_OK);
+
+ // The body of the with statement must be enclosed in an additional
+ // lexical scope in case the body is a FunctionDeclaration.
+ body = factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition);
+ Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
+ block_scope->set_start_position(scanner()->location().beg_pos);
+ {
+ BlockState block_state(&scope_, block_scope);
+ Target target(&this->target_stack_, body);
+ Statement* stmt = ParseSubStatement(labels, CHECK_OK);
+ body->statements()->Add(stmt, zone());
+ block_scope->set_end_position(scanner()->location().end_pos);
+ block_scope = block_scope->FinalizeBlockScope();
+ body->set_scope(block_scope);
+ }
+
with_scope->set_end_position(scanner()->location().end_pos);
}
- return factory()->NewWithStatement(with_scope, expr, stmt, pos);
+ return factory()->NewWithStatement(with_scope, expr, body, pos);
}
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-542100.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698