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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 3599 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 // TODO(caitp): This should be an error in sloppy mode too. 3610 // TODO(caitp): This should be an error in sloppy mode too.
3611 ReportMessageAt(parsing_result.first_initializer_loc, 3611 ReportMessageAt(parsing_result.first_initializer_loc,
3612 MessageTemplate::kForInLoopInitializer); 3612 MessageTemplate::kForInLoopInitializer);
3613 } 3613 }
3614 *ok = false; 3614 *ok = false;
3615 return nullptr; 3615 return nullptr;
3616 } 3616 }
3617 3617
3618 DCHECK(parsing_result.declarations.length() == 1); 3618 DCHECK(parsing_result.declarations.length() == 1);
3619 Block* init_block = nullptr; 3619 Block* init_block = nullptr;
3620 const AstRawString* name = parsing_result.SingleName();
3620 3621
3621 // special case for legacy for (var/const x =.... in) 3622 // special case for legacy for (var/const x =.... in)
3622 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && 3623 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) &&
3623 parsing_result.declarations[0].initializer != nullptr) { 3624 parsing_result.declarations[0].initializer != nullptr) {
3624 VariableProxy* single_var = scope_->NewUnresolved( 3625 VariableProxy* single_var = scope_->NewUnresolved(
3625 factory(), parsing_result.SingleName(), Variable::NORMAL, 3626 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
3626 each_beg_pos, each_end_pos);
3627 init_block = factory()->NewBlock( 3627 init_block = factory()->NewBlock(
3628 nullptr, 2, true, parsing_result.descriptor.declaration_pos); 3628 nullptr, 2, true, parsing_result.descriptor.declaration_pos);
3629 init_block->AddStatement( 3629 init_block->AddStatement(
3630 factory()->NewExpressionStatement( 3630 factory()->NewExpressionStatement(
3631 factory()->NewAssignment( 3631 factory()->NewAssignment(
3632 Token::ASSIGN, single_var, 3632 Token::ASSIGN, single_var,
3633 parsing_result.declarations[0].initializer, 3633 parsing_result.declarations[0].initializer,
3634 RelocInfo::kNoPosition), 3634 RelocInfo::kNoPosition),
3635 RelocInfo::kNoPosition), 3635 RelocInfo::kNoPosition),
3636 zone()); 3636 zone());
3637 } 3637 }
3638 3638
3639 // For some reason, we can't bind over catch parameters in for-of.
3640 if (mode == ForEachStatement::ITERATE &&
3641 IsDeclaredAsCatchParameter(scope_, name)) {
3642 ParserTraits::ReportMessageAt(parsing_result.first_initializer_loc,
3643 MessageTemplate::kVarRedeclaration,
3644 name);
3645 *ok = false;
3646 return nullptr;
3647 }
3648
3639 // Rewrite a for-in/of statement of the form 3649 // Rewrite a for-in/of statement of the form
3640 // 3650 //
3641 // for (let/const/var x in/of e) b 3651 // for (let/const/var x in/of e) b
3642 // 3652 //
3643 // into 3653 // into
3644 // 3654 //
3645 // { 3655 // {
3646 // <let x' be a temporary variable> 3656 // <let x' be a temporary variable>
3647 // for (x' in/of e) { 3657 // for (x' in/of e) {
3648 // let/const/var x; 3658 // let/const/var x;
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
4809 int position = decl->proxy()->position(); 4819 int position = decl->proxy()->position();
4810 Scanner::Location location = position == RelocInfo::kNoPosition 4820 Scanner::Location location = position == RelocInfo::kNoPosition
4811 ? Scanner::Location::invalid() 4821 ? Scanner::Location::invalid()
4812 : Scanner::Location(position, position + 1); 4822 : Scanner::Location(position, position + 1);
4813 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration, 4823 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
4814 name); 4824 name);
4815 *ok = false; 4825 *ok = false;
4816 } 4826 }
4817 } 4827 }
4818 4828
4829 bool Parser::IsDeclaredAsCatchParameter(Scope* scope,
4830 const AstRawString* name) {
4831 for (; scope != NULL; scope = scope->outer_scope())
4832 if (scope->is_catch_scope() && scope->LookupLocal(name)) return true;
4833 return false;
4834 }
4835
4819 4836
4820 // ---------------------------------------------------------------------------- 4837 // ----------------------------------------------------------------------------
4821 // Parser support 4838 // Parser support
4822 4839
4823 bool Parser::TargetStackContainsLabel(const AstRawString* label) { 4840 bool Parser::TargetStackContainsLabel(const AstRawString* label) {
4824 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 4841 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
4825 if (ContainsLabel(t->statement()->labels(), label)) return true; 4842 if (ContainsLabel(t->statement()->labels(), label)) return true;
4826 } 4843 }
4827 return false; 4844 return false;
4828 } 4845 }
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
6121 6138
6122 Expression* Parser::SpreadCallNew(Expression* function, 6139 Expression* Parser::SpreadCallNew(Expression* function,
6123 ZoneList<v8::internal::Expression*>* args, 6140 ZoneList<v8::internal::Expression*>* args,
6124 int pos) { 6141 int pos) {
6125 args->InsertAt(0, function, zone()); 6142 args->InsertAt(0, function, zone());
6126 6143
6127 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6144 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6128 } 6145 }
6129 } // namespace internal 6146 } // namespace internal
6130 } // namespace v8 6147 } // namespace v8
OLDNEW
« 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