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

Side by Side Diff: src/preparser.cc

Issue 1300103005: [parser] disallow language mode directive in body of function with non-simple parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: flag implications don't work in test suite? 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/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 !scope_->HasSimpleParameters()) {
271 // TC39 deemed "use strict" directives to be an error when occurring
272 // in the body of a function with non-simple parameter list, on
273 // 29/7/2015. https://goo.gl/ueA7Ln
274 //
275 // In V8, this also applies to "use strong " directives.
276 PreParserTraits::ReportMessageAt(
277 token_loc, MessageTemplate::kIllegalLanguageModeDirective,
278 use_strict_found ? "use strict" : "use strong");
279 *ok = false;
280 return;
281 }
263 } 282 }
264 283
265 // If we're allowed to reset to a bookmark, we will do so when we see a long 284 // If we're allowed to reset to a bookmark, we will do so when we see a long
266 // and trivial function. 285 // and trivial function.
267 // Our current definition of 'long and trivial' is: 286 // Our current definition of 'long and trivial' is:
268 // - over 200 statements 287 // - over 200 statements
269 // - all starting with an identifier (i.e., no if, for, while, etc.) 288 // - all starting with an identifier (i.e., no if, for, while, etc.)
270 if (maybe_reset && (!starts_with_identifier || 289 if (maybe_reset && (!starts_with_identifier ||
271 ++count_statements > kLazyParseTrialLimit)) { 290 ++count_statements > kLazyParseTrialLimit)) {
272 if (count_statements > kLazyParseTrialLimit) { 291 if (count_statements > kLazyParseTrialLimit) {
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 function_scope->SetLanguageMode(language_mode); 1069 function_scope->SetLanguageMode(language_mode);
1051 PreParserFactory factory(NULL); 1070 PreParserFactory factory(NULL);
1052 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 1071 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
1053 &factory); 1072 &factory);
1054 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 1073 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
1055 ExpressionClassifier formals_classifier(&duplicate_finder); 1074 ExpressionClassifier formals_classifier(&duplicate_finder);
1056 1075
1057 Expect(Token::LPAREN, CHECK_OK); 1076 Expect(Token::LPAREN, CHECK_OK);
1058 int start_position = scanner()->location().beg_pos; 1077 int start_position = scanner()->location().beg_pos;
1059 function_scope->set_start_position(start_position); 1078 function_scope->set_start_position(start_position);
1060 PreParserFormalParameters formals(nullptr); 1079 PreParserFormalParameters formals(function_scope);
1061 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 1080 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
1062 Expect(Token::RPAREN, CHECK_OK); 1081 Expect(Token::RPAREN, CHECK_OK);
1063 int formals_end_position = scanner()->location().end_pos; 1082 int formals_end_position = scanner()->location().end_pos;
1064 1083
1065 CheckArityRestrictions(formals.arity, arity_restriction, 1084 CheckArityRestrictions(formals.arity, arity_restriction,
1066 formals.has_rest, start_position, 1085 formals.has_rest, start_position,
1067 formals_end_position, CHECK_OK); 1086 formals_end_position, CHECK_OK);
1068 1087
1069 // See Parser::ParseFunctionLiteral for more information about lazy parsing 1088 // See Parser::ParseFunctionLiteral for more information about lazy parsing
1070 // and lazy compilation. 1089 // and lazy compilation.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 1223
1205 DCHECK(!spread_pos.IsValid()); 1224 DCHECK(!spread_pos.IsValid());
1206 1225
1207 return Expression::Default(); 1226 return Expression::Default();
1208 } 1227 }
1209 1228
1210 #undef CHECK_OK 1229 #undef CHECK_OK
1211 1230
1212 1231
1213 } } // v8::internal 1232 } } // 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