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

Side by Side Diff: src/parsing/parser.cc

Issue 1911963003: Add flag for disallowing for-in initializers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added comment Created 4 years, 8 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/flag-definitions.h ('k') | test/mjsunit/harmony/for-in.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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 3482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 *ok = false; 3493 *ok = false;
3494 return nullptr; 3494 return nullptr;
3495 } 3495 }
3496 3496
3497 Block* init_block = nullptr; 3497 Block* init_block = nullptr;
3498 3498
3499 // special case for legacy for (var/const x =.... in) 3499 // special case for legacy for (var/const x =.... in)
3500 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && 3500 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) &&
3501 decl.pattern->IsVariableProxy() && decl.initializer != nullptr) { 3501 decl.pattern->IsVariableProxy() && decl.initializer != nullptr) {
3502 ++use_counts_[v8::Isolate::kForInInitializer]; 3502 ++use_counts_[v8::Isolate::kForInInitializer];
3503 if (FLAG_harmony_for_in) {
3504 // TODO(rossberg): This error is not currently generated in the
3505 // preparser, because that would lose some of the use counts
3506 // recorded above. Once either the use counter or the flag is
3507 // removed, the preparser should be adjusted.
3508 ParserTraits::ReportMessageAt(
3509 parsing_result.first_initializer_loc,
3510 MessageTemplate::kForInOfLoopInitializer,
3511 ForEachStatement::VisitModeString(mode));
3512 *ok = false;
3513 return nullptr;
3514 }
3503 const AstRawString* name = 3515 const AstRawString* name =
3504 decl.pattern->AsVariableProxy()->raw_name(); 3516 decl.pattern->AsVariableProxy()->raw_name();
3505 VariableProxy* single_var = scope_->NewUnresolved( 3517 VariableProxy* single_var = scope_->NewUnresolved(
3506 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); 3518 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
3507 init_block = factory()->NewBlock( 3519 init_block = factory()->NewBlock(
3508 nullptr, 2, true, parsing_result.descriptor.declaration_pos); 3520 nullptr, 2, true, parsing_result.descriptor.declaration_pos);
3509 init_block->statements()->Add( 3521 init_block->statements()->Add(
3510 factory()->NewExpressionStatement( 3522 factory()->NewExpressionStatement(
3511 factory()->NewAssignment(Token::ASSIGN, single_var, 3523 factory()->NewAssignment(Token::ASSIGN, single_var,
3512 decl.initializer, 3524 decl.initializer,
(...skipping 3270 matching lines...) Expand 10 before | Expand all | Expand 10 after
6783 try_block, target); 6795 try_block, target);
6784 final_loop = target; 6796 final_loop = target;
6785 } 6797 }
6786 6798
6787 return final_loop; 6799 return final_loop;
6788 } 6800 }
6789 6801
6790 6802
6791 } // namespace internal 6803 } // namespace internal
6792 } // namespace v8 6804 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/harmony/for-in.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698