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

Side by Side Diff: src/preparser.cc

Issue 1281163002: [parser] partially revert "use-strict directives in function body affect init block" Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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/preparser.h ('k') | src/scopes.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 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 int function_token_position, FunctionLiteral::FunctionType type, 95 int function_token_position, FunctionLiteral::FunctionType type,
96 FunctionLiteral::ArityRestriction arity_restriction, 96 FunctionLiteral::ArityRestriction arity_restriction,
97 LanguageMode language_mode, bool* ok) { 97 LanguageMode language_mode, bool* ok) {
98 return pre_parser_->ParseFunctionLiteral( 98 return pre_parser_->ParseFunctionLiteral(
99 name, function_name_location, function_name_validity, kind, 99 name, function_name_location, function_name_validity, kind,
100 function_token_position, type, arity_restriction, language_mode, ok); 100 function_token_position, type, arity_restriction, language_mode, ok);
101 } 101 }
102 102
103 103
104 PreParser::PreParseResult PreParser::PreParseLazyFunction( 104 PreParser::PreParseResult PreParser::PreParseLazyFunction(
105 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, 105 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
106 Scanner::BookmarkScope* bookmark) { 106 ParserRecorder* log, Scanner::BookmarkScope* bookmark) {
107 log_ = log; 107 log_ = log;
108 // Lazy functions always have trivial outer scopes (no with/catch scopes). 108 // Lazy functions always have trivial outer scopes (no with/catch scopes).
109 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); 109 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE);
110 PreParserFactory top_factory(NULL); 110 PreParserFactory top_factory(NULL);
111 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, 111 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction,
112 &top_factory); 112 &top_factory);
113 scope_->SetLanguageMode(language_mode); 113 scope_->SetLanguageMode(language_mode);
114 Scope* function_scope = NewScope( 114 Scope* function_scope = NewScope(
115 scope_, IsArrowFunction(kind) ? ARROW_SCOPE : FUNCTION_SCOPE, kind); 115 scope_, IsArrowFunction(kind) ? ARROW_SCOPE : FUNCTION_SCOPE, kind);
116 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
116 PreParserFactory function_factory(NULL); 117 PreParserFactory function_factory(NULL);
117 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 118 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
118 &function_factory); 119 &function_factory);
119 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 120 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
120 bool ok = true; 121 bool ok = true;
121 int start_position = peek_position(); 122 int start_position = peek_position();
122 ParseLazyFunctionLiteralBody(&ok, bookmark); 123 ParseLazyFunctionLiteralBody(&ok, bookmark);
123 if (bookmark && bookmark->HasBeenReset()) { 124 if (bookmark && bookmark->HasBeenReset()) {
124 ; // Do nothing, as we've just aborted scanning this function. 125 ; // Do nothing, as we've just aborted scanning this function.
125 } else if (stack_overflow()) { 126 } else if (stack_overflow()) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 245 }
245 if (super_loc.beg_pos != old_super_loc.beg_pos && 246 if (super_loc.beg_pos != old_super_loc.beg_pos &&
246 super_loc.beg_pos != token_loc.beg_pos) { 247 super_loc.beg_pos != token_loc.beg_pos) {
247 ReportMessageAt(super_loc, MessageTemplate::kStrongConstructorSuper); 248 ReportMessageAt(super_loc, MessageTemplate::kStrongConstructorSuper);
248 *ok = false; 249 *ok = false;
249 return; 250 return;
250 } 251 }
251 } 252 }
252 253
253 if (directive_prologue) { 254 if (directive_prologue) {
254 if (statement.IsUseStrictLiteral()) { 255 bool use_strict_found = statement.IsUseStrictLiteral();
256 bool use_strong_found =
257 statement.IsUseStrongLiteral() && allow_strong_mode();
258
259 if (use_strict_found) {
255 scope_->SetLanguageMode( 260 scope_->SetLanguageMode(
256 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); 261 static_cast<LanguageMode>(scope_->language_mode() | STRICT));
257 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { 262 } else if (use_strong_found) {
258 scope_->SetLanguageMode(static_cast<LanguageMode>( 263 scope_->SetLanguageMode(static_cast<LanguageMode>(
259 scope_->language_mode() | STRONG)); 264 scope_->language_mode() | STRONG));
260 } else if (!statement.IsStringLiteral()) { 265 } else if (!statement.IsStringLiteral()) {
261 directive_prologue = false; 266 directive_prologue = false;
262 } 267 }
268
269 if (use_strict_found || use_strong_found) {
270 if (!scope_->HasSimpleParameters()) {
271 // A block declaration scope as a child scope of a function scope
272 // indicates that a function has a non-simple parameter list.
273 // TC39 deemed "use strict" directives to be an error in this case,
274 // on 29/7/2015. https://goo.gl/ueA7Ln
275 //
276 // In V8, this also applies to "use strong " directives.
277 PreParserTraits::ReportMessageAt(
278 token_loc, MessageTemplate::kIllegalLanguageModeDirective,
279 use_strict_found ? "use strict" : "use strong");
280 *ok = false;
281 return;
282 }
283 }
263 } 284 }
264 285
265 // If we're allowed to reset to a bookmark, we will do so when we see a long 286 // If we're allowed to reset to a bookmark, we will do so when we see a long
266 // and trivial function. 287 // and trivial function.
267 // Our current definition of 'long and trivial' is: 288 // Our current definition of 'long and trivial' is:
268 // - over 200 statements 289 // - over 200 statements
269 // - all starting with an identifier (i.e., no if, for, while, etc.) 290 // - all starting with an identifier (i.e., no if, for, while, etc.)
270 if (maybe_reset && (!starts_with_identifier || 291 if (maybe_reset && (!starts_with_identifier ||
271 ++count_statements > kLazyParseTrialLimit)) { 292 ++count_statements > kLazyParseTrialLimit)) {
272 if (count_statements > kLazyParseTrialLimit) { 293 if (count_statements > kLazyParseTrialLimit) {
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 function_scope->SetLanguageMode(language_mode); 1066 function_scope->SetLanguageMode(language_mode);
1046 PreParserFactory factory(NULL); 1067 PreParserFactory factory(NULL);
1047 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 1068 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
1048 &factory); 1069 &factory);
1049 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 1070 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
1050 ExpressionClassifier formals_classifier(&duplicate_finder); 1071 ExpressionClassifier formals_classifier(&duplicate_finder);
1051 1072
1052 Expect(Token::LPAREN, CHECK_OK); 1073 Expect(Token::LPAREN, CHECK_OK);
1053 int start_position = scanner()->location().beg_pos; 1074 int start_position = scanner()->location().beg_pos;
1054 function_scope->set_start_position(start_position); 1075 function_scope->set_start_position(start_position);
1055 PreParserFormalParameters formals(nullptr); 1076 PreParserFormalParameters formals(function_scope);
1056 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 1077 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
1057 Expect(Token::RPAREN, CHECK_OK); 1078 Expect(Token::RPAREN, CHECK_OK);
1058 int formals_end_position = scanner()->location().end_pos; 1079 int formals_end_position = scanner()->location().end_pos;
1059 1080
1060 CheckArityRestrictions(formals.arity, arity_restriction, 1081 CheckArityRestrictions(formals.arity, arity_restriction,
1061 formals.has_rest, start_position, 1082 formals.has_rest, start_position,
1062 formals_end_position, CHECK_OK); 1083 formals_end_position, CHECK_OK);
1063 1084
1064 // See Parser::ParseFunctionLiteral for more information about lazy parsing 1085 // See Parser::ParseFunctionLiteral for more information about lazy parsing
1065 // and lazy compilation. 1086 // and lazy compilation.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 ParseStatementList(Token::RBRACE, ok, bookmark); 1133 ParseStatementList(Token::RBRACE, ok, bookmark);
1113 if (!*ok) return; 1134 if (!*ok) return;
1114 if (bookmark && bookmark->HasBeenReset()) return; 1135 if (bookmark && bookmark->HasBeenReset()) return;
1115 1136
1116 // Position right after terminal '}'. 1137 // Position right after terminal '}'.
1117 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 1138 DCHECK_EQ(Token::RBRACE, scanner()->peek());
1118 int body_end = scanner()->peek_location().end_pos; 1139 int body_end = scanner()->peek_location().end_pos;
1119 log_->LogFunction(body_start, body_end, 1140 log_->LogFunction(body_start, body_end,
1120 function_state_->materialized_literal_count(), 1141 function_state_->materialized_literal_count(),
1121 function_state_->expected_property_count(), language_mode(), 1142 function_state_->expected_property_count(), language_mode(),
1122 scope_->uses_super_property(), scope_->calls_eval()); 1143 scope_->uses_super_property(), scope_->calls_eval(),
1144 scope_->has_simple_parameters());
1123 } 1145 }
1124 1146
1125 1147
1126 PreParserExpression PreParser::ParseClassLiteral( 1148 PreParserExpression PreParser::ParseClassLiteral(
1127 PreParserIdentifier name, Scanner::Location class_name_location, 1149 PreParserIdentifier name, Scanner::Location class_name_location,
1128 bool name_is_strict_reserved, int pos, bool* ok) { 1150 bool name_is_strict_reserved, int pos, bool* ok) {
1129 // All parts of a ClassDeclaration and ClassExpression are strict code. 1151 // All parts of a ClassDeclaration and ClassExpression are strict code.
1130 if (name_is_strict_reserved) { 1152 if (name_is_strict_reserved) {
1131 ReportMessageAt(class_name_location, 1153 ReportMessageAt(class_name_location,
1132 MessageTemplate::kUnexpectedStrictReserved); 1154 MessageTemplate::kUnexpectedStrictReserved);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 1221
1200 DCHECK(!spread_pos.IsValid()); 1222 DCHECK(!spread_pos.IsValid());
1201 1223
1202 return Expression::Default(); 1224 return Expression::Default();
1203 } 1225 }
1204 1226
1205 #undef CHECK_OK 1227 #undef CHECK_OK
1206 1228
1207 1229
1208 } } // v8::internal 1230 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698