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

Unified Diff: src/parser.cc

Issue 1318023004: Do not permit binding over catch parameters in for-of (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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.h ('k') | test/mjsunit/es6/try-catch-for-of.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 d993d20595de80567f267e8410dfe77edcbe450c..51d665ad5596c98062ee5bf392e12e360f44aedc 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3617,13 +3617,13 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
DCHECK(parsing_result.declarations.length() == 1);
Block* init_block = nullptr;
+ const AstRawString* name = parsing_result.SingleName();
// special case for legacy for (var/const x =.... in)
if (!IsLexicalVariableMode(parsing_result.descriptor.mode) &&
parsing_result.declarations[0].initializer != nullptr) {
VariableProxy* single_var = scope_->NewUnresolved(
- factory(), parsing_result.SingleName(), Variable::NORMAL,
- each_beg_pos, each_end_pos);
+ factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
init_block = factory()->NewBlock(
nullptr, 2, true, parsing_result.descriptor.declaration_pos);
init_block->AddStatement(
@@ -3636,6 +3636,16 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
zone());
}
+ // For some reason, we can't bind over catch parameters in for-of.
+ if (mode == ForEachStatement::ITERATE &&
+ IsDeclaredAsCatchParameter(scope_, name)) {
+ ParserTraits::ReportMessageAt(parsing_result.first_initializer_loc,
+ MessageTemplate::kVarRedeclaration,
+ name);
+ *ok = false;
+ return nullptr;
+ }
+
// Rewrite a for-in/of statement of the form
//
// for (let/const/var x in/of e) b
@@ -4816,6 +4826,13 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
}
}
+bool Parser::IsDeclaredAsCatchParameter(Scope* scope,
+ const AstRawString* name) {
+ for (; scope != NULL; scope = scope->outer_scope())
+ if (scope->is_catch_scope() && scope->LookupLocal(name)) return true;
+ return false;
+}
+
// ----------------------------------------------------------------------------
// Parser support
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/es6/try-catch-for-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698