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

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

Issue 1913203002: Widen --harmony-for-in flag to throw errors in PreParser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 | « no previous file | src/parsing/parser-base.h » ('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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 parsing_on_main_thread_(true) { 778 parsing_on_main_thread_(true) {
779 // Even though we were passed ParseInfo, we should not store it in 779 // Even though we were passed ParseInfo, we should not store it in
780 // Parser - this makes sure that Isolate is not accidentally accessed via 780 // Parser - this makes sure that Isolate is not accidentally accessed via
781 // ParseInfo during background parsing. 781 // ParseInfo during background parsing.
782 DCHECK(!info->script().is_null() || info->source_stream() != NULL); 782 DCHECK(!info->script().is_null() || info->source_stream() != NULL);
783 set_allow_lazy(info->allow_lazy_parsing()); 783 set_allow_lazy(info->allow_lazy_parsing());
784 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 784 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
785 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && 785 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
786 info->isolate()->is_tail_call_elimination_enabled()); 786 info->isolate()->is_tail_call_elimination_enabled());
787 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 787 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
788 set_allow_harmony_for_in(FLAG_harmony_for_in);
788 set_allow_harmony_function_name(FLAG_harmony_function_name); 789 set_allow_harmony_function_name(FLAG_harmony_function_name);
789 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 790 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
790 set_allow_harmony_restrictive_declarations( 791 set_allow_harmony_restrictive_declarations(
791 FLAG_harmony_restrictive_declarations); 792 FLAG_harmony_restrictive_declarations);
792 set_allow_harmony_exponentiation_operator( 793 set_allow_harmony_exponentiation_operator(
793 FLAG_harmony_exponentiation_operator); 794 FLAG_harmony_exponentiation_operator);
794 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 795 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
795 ++feature) { 796 ++feature) {
796 use_counts_[feature] = 0; 797 use_counts_[feature] = 0;
797 } 798 }
(...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 MessageTemplate::kForInOfLoopMultiBindings, 3480 MessageTemplate::kForInOfLoopMultiBindings,
3480 ForEachStatement::VisitModeString(mode)); 3481 ForEachStatement::VisitModeString(mode));
3481 *ok = false; 3482 *ok = false;
3482 return nullptr; 3483 return nullptr;
3483 } 3484 }
3484 DeclarationParsingResult::Declaration& decl = 3485 DeclarationParsingResult::Declaration& decl =
3485 parsing_result.declarations[0]; 3486 parsing_result.declarations[0];
3486 if (parsing_result.first_initializer_loc.IsValid() && 3487 if (parsing_result.first_initializer_loc.IsValid() &&
3487 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || 3488 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE ||
3488 IsLexicalVariableMode(parsing_result.descriptor.mode) || 3489 IsLexicalVariableMode(parsing_result.descriptor.mode) ||
3489 !decl.pattern->IsVariableProxy())) { 3490 !decl.pattern->IsVariableProxy() || allow_harmony_for_in())) {
3491 // Only increment the use count if we would have let this through
3492 // without the flag.
3493 if (allow_harmony_for_in()) {
3494 ++use_counts_[v8::Isolate::kForInInitializer];
3495 }
3490 ParserTraits::ReportMessageAt( 3496 ParserTraits::ReportMessageAt(
3491 parsing_result.first_initializer_loc, 3497 parsing_result.first_initializer_loc,
3492 MessageTemplate::kForInOfLoopInitializer, 3498 MessageTemplate::kForInOfLoopInitializer,
3493 ForEachStatement::VisitModeString(mode)); 3499 ForEachStatement::VisitModeString(mode));
3494 *ok = false; 3500 *ok = false;
3495 return nullptr; 3501 return nullptr;
3496 } 3502 }
3497 3503
3498 Block* init_block = nullptr; 3504 Block* init_block = nullptr;
3499 3505
3500 // special case for legacy for (var/const x =.... in) 3506 // special case for legacy for (var/const x =.... in)
3501 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && 3507 if (!IsLexicalVariableMode(parsing_result.descriptor.mode) &&
3502 decl.pattern->IsVariableProxy() && decl.initializer != nullptr) { 3508 decl.pattern->IsVariableProxy() && decl.initializer != nullptr) {
3509 DCHECK(!allow_harmony_for_in());
3503 ++use_counts_[v8::Isolate::kForInInitializer]; 3510 ++use_counts_[v8::Isolate::kForInInitializer];
3504 if (FLAG_harmony_for_in) {
3505 // TODO(rossberg): This error is not currently generated in the
3506 // preparser, because that would lose some of the use counts
3507 // recorded above. Once either the use counter or the flag is
3508 // removed, the preparser should be adjusted.
3509 ParserTraits::ReportMessageAt(
3510 parsing_result.first_initializer_loc,
3511 MessageTemplate::kForInOfLoopInitializer,
3512 ForEachStatement::VisitModeString(mode));
3513 *ok = false;
3514 return nullptr;
3515 }
3516 const AstRawString* name = 3511 const AstRawString* name =
3517 decl.pattern->AsVariableProxy()->raw_name(); 3512 decl.pattern->AsVariableProxy()->raw_name();
3518 VariableProxy* single_var = scope_->NewUnresolved( 3513 VariableProxy* single_var = scope_->NewUnresolved(
3519 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); 3514 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
3520 init_block = factory()->NewBlock( 3515 init_block = factory()->NewBlock(
3521 nullptr, 2, true, parsing_result.descriptor.declaration_pos); 3516 nullptr, 2, true, parsing_result.descriptor.declaration_pos);
3522 init_block->statements()->Add( 3517 init_block->statements()->Add(
3523 factory()->NewExpressionStatement( 3518 factory()->NewExpressionStatement(
3524 factory()->NewAssignment(Token::ASSIGN, single_var, 3519 factory()->NewAssignment(Token::ASSIGN, single_var,
3525 decl.initializer, 3520 decl.initializer,
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4597 4592
4598 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 4593 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
4599 4594
4600 if (reusable_preparser_ == NULL) { 4595 if (reusable_preparser_ == NULL) {
4601 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 4596 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
4602 NULL, stack_limit_); 4597 NULL, stack_limit_);
4603 reusable_preparser_->set_allow_lazy(true); 4598 reusable_preparser_->set_allow_lazy(true);
4604 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4599 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4605 SET_ALLOW(natives); 4600 SET_ALLOW(natives);
4606 SET_ALLOW(harmony_do_expressions); 4601 SET_ALLOW(harmony_do_expressions);
4602 SET_ALLOW(harmony_for_in);
4607 SET_ALLOW(harmony_function_name); 4603 SET_ALLOW(harmony_function_name);
4608 SET_ALLOW(harmony_function_sent); 4604 SET_ALLOW(harmony_function_sent);
4609 SET_ALLOW(harmony_exponentiation_operator); 4605 SET_ALLOW(harmony_exponentiation_operator);
4610 SET_ALLOW(harmony_restrictive_declarations); 4606 SET_ALLOW(harmony_restrictive_declarations);
4611 #undef SET_ALLOW 4607 #undef SET_ALLOW
4612 } 4608 }
4613 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4609 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4614 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4610 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4615 logger, bookmark); 4611 logger, bookmark, use_counts_);
4616 if (pre_parse_timer_ != NULL) { 4612 if (pre_parse_timer_ != NULL) {
4617 pre_parse_timer_->Stop(); 4613 pre_parse_timer_->Stop();
4618 } 4614 }
4619 return result; 4615 return result;
4620 } 4616 }
4621 4617
4622 4618
4623 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, 4619 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
4624 Scanner::Location class_name_location, 4620 Scanner::Location class_name_location,
4625 bool name_is_strict_reserved, int pos, 4621 bool name_is_strict_reserved, int pos,
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
6799 try_block, target); 6795 try_block, target);
6800 final_loop = target; 6796 final_loop = target;
6801 } 6797 }
6802 6798
6803 return final_loop; 6799 return final_loop;
6804 } 6800 }
6805 6801
6806 6802
6807 } // namespace internal 6803 } // namespace internal
6808 } // namespace v8 6804 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698