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/preparser.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 | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 PreParserExpression PreParserTraits::ParseFunctionLiteral( 91 PreParserExpression PreParserTraits::ParseFunctionLiteral(
92 PreParserIdentifier name, Scanner::Location function_name_location, 92 PreParserIdentifier name, Scanner::Location function_name_location,
93 FunctionNameValidity function_name_validity, FunctionKind kind, 93 FunctionNameValidity function_name_validity, FunctionKind kind,
94 int function_token_position, FunctionLiteral::FunctionType type, 94 int function_token_position, FunctionLiteral::FunctionType type,
95 LanguageMode language_mode, bool* ok) { 95 LanguageMode language_mode, bool* ok) {
96 return pre_parser_->ParseFunctionLiteral( 96 return pre_parser_->ParseFunctionLiteral(
97 name, function_name_location, function_name_validity, kind, 97 name, function_name_location, function_name_validity, kind,
98 function_token_position, type, language_mode, ok); 98 function_token_position, type, language_mode, ok);
99 } 99 }
100 100
101
102 PreParser::PreParseResult PreParser::PreParseLazyFunction( 101 PreParser::PreParseResult PreParser::PreParseLazyFunction(
103 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, 102 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
104 ParserRecorder* log, Scanner::BookmarkScope* bookmark) { 103 ParserRecorder* log, Scanner::BookmarkScope* bookmark, int* use_counts) {
105 log_ = log; 104 log_ = log;
105 use_counts_ = use_counts;
106 // Lazy functions always have trivial outer scopes (no with/catch scopes). 106 // Lazy functions always have trivial outer scopes (no with/catch scopes).
107 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); 107 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE);
108 PreParserFactory top_factory(NULL); 108 PreParserFactory top_factory(NULL);
109 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, 109 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction,
110 &top_factory); 110 &top_factory);
111 scope_->SetLanguageMode(language_mode); 111 scope_->SetLanguageMode(language_mode);
112 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); 112 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind);
113 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); 113 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
114 PreParserFactory function_factory(NULL); 114 PreParserFactory function_factory(NULL);
115 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 115 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
116 &function_factory); 116 &function_factory);
117 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 117 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
118 bool ok = true; 118 bool ok = true;
119 int start_position = peek_position(); 119 int start_position = peek_position();
120 ParseLazyFunctionLiteralBody(&ok, bookmark); 120 ParseLazyFunctionLiteralBody(&ok, bookmark);
121 use_counts_ = nullptr;
121 if (bookmark && bookmark->HasBeenReset()) { 122 if (bookmark && bookmark->HasBeenReset()) {
122 // Do nothing, as we've just aborted scanning this function. 123 // Do nothing, as we've just aborted scanning this function.
123 } else if (stack_overflow()) { 124 } else if (stack_overflow()) {
124 return kPreParseStackOverflow; 125 return kPreParseStackOverflow;
125 } else if (!ok) { 126 } else if (!ok) {
126 ReportUnexpectedToken(scanner()->current_token()); 127 ReportUnexpectedToken(scanner()->current_token());
127 } else { 128 } else {
128 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 129 DCHECK_EQ(Token::RBRACE, scanner()->peek());
129 if (is_strict(scope_->language_mode())) { 130 if (is_strict(scope_->language_mode())) {
130 int end_pos = scanner()->location().end_pos; 131 int end_pos = scanner()->location().end_pos;
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 if (!*ok) return Statement::Default(); 805 if (!*ok) return Statement::Default();
805 if (decl_count != 1) { 806 if (decl_count != 1) {
806 PreParserTraits::ReportMessageAt( 807 PreParserTraits::ReportMessageAt(
807 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings, 808 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings,
808 ForEachStatement::VisitModeString(mode)); 809 ForEachStatement::VisitModeString(mode));
809 *ok = false; 810 *ok = false;
810 return Statement::Default(); 811 return Statement::Default();
811 } 812 }
812 if (first_initializer_loc.IsValid() && 813 if (first_initializer_loc.IsValid() &&
813 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || 814 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE ||
814 is_lexical || is_binding_pattern)) { 815 is_lexical || is_binding_pattern || allow_harmony_for_in())) {
816 // Only increment the use count if we would have let this through
817 // without the flag.
818 if (use_counts_ != nullptr && allow_harmony_for_in()) {
819 ++use_counts_[v8::Isolate::kForInInitializer];
820 }
815 PreParserTraits::ReportMessageAt( 821 PreParserTraits::ReportMessageAt(
816 first_initializer_loc, MessageTemplate::kForInOfLoopInitializer, 822 first_initializer_loc, MessageTemplate::kForInOfLoopInitializer,
817 ForEachStatement::VisitModeString(mode)); 823 ForEachStatement::VisitModeString(mode));
818 *ok = false; 824 *ok = false;
819 return Statement::Default(); 825 return Statement::Default();
820 } 826 }
821 827
822 if (mode == ForEachStatement::ITERATE) { 828 if (mode == ForEachStatement::ITERATE) {
823 ExpressionClassifier classifier(this); 829 ExpressionClassifier classifier(this);
824 ParseAssignmentExpression(true, &classifier, CHECK_OK); 830 ParseAssignmentExpression(true, &classifier, CHECK_OK);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 } 1157 }
1152 Expect(Token::RBRACE, CHECK_OK); 1158 Expect(Token::RBRACE, CHECK_OK);
1153 return PreParserExpression::Default(); 1159 return PreParserExpression::Default();
1154 } 1160 }
1155 1161
1156 #undef CHECK_OK 1162 #undef CHECK_OK
1157 1163
1158 1164
1159 } // namespace internal 1165 } // namespace internal
1160 } // namespace v8 1166 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698