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

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

Issue 1900033003: Disallow generator declarations in certain locations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 7 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // 172 //
173 // HoistableDeclaration[Yield, Default] : 173 // HoistableDeclaration[Yield, Default] :
174 // FunctionDeclaration[?Yield, ?Default] 174 // FunctionDeclaration[?Yield, ?Default]
175 // GeneratorDeclaration[?Yield, ?Default] 175 // GeneratorDeclaration[?Yield, ?Default]
176 // 176 //
177 // LexicalDeclaration[In, Yield] : 177 // LexicalDeclaration[In, Yield] :
178 // LetOrConst BindingList[?In, ?Yield] ; 178 // LetOrConst BindingList[?In, ?Yield] ;
179 179
180 switch (peek()) { 180 switch (peek()) {
181 case Token::FUNCTION: 181 case Token::FUNCTION:
182 return ParseFunctionDeclaration(ok); 182 return ParseHoistableDeclaration(ok);
183 case Token::CLASS: 183 case Token::CLASS:
184 return ParseClassDeclaration(ok); 184 return ParseClassDeclaration(ok);
185 case Token::CONST: 185 case Token::CONST:
186 return ParseVariableStatement(kStatementListItem, ok); 186 return ParseVariableStatement(kStatementListItem, ok);
187 case Token::LET: 187 case Token::LET:
188 if (IsNextLetKeyword()) { 188 if (IsNextLetKeyword()) {
189 return ParseVariableStatement(kStatementListItem, ok); 189 return ParseVariableStatement(kStatementListItem, ok);
190 } 190 }
191 break; 191 break;
192 default: 192 default:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 371
372 case Token::VAR: 372 case Token::VAR:
373 return ParseVariableStatement(kStatement, ok); 373 return ParseVariableStatement(kStatement, ok);
374 374
375 default: 375 default:
376 return ParseExpressionOrLabelledStatement(allow_function, ok); 376 return ParseExpressionOrLabelledStatement(allow_function, ok);
377 } 377 }
378 } 378 }
379 379
380 380
381 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { 381 PreParser::Statement PreParser::ParseHoistableDeclaration(
382 // FunctionDeclaration :: 382 int pos, bool is_generator, bool* ok) {
383 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
384 // GeneratorDeclaration ::
385 // 'function' '*' Identifier '(' FormalParameterListopt ')'
386 // '{' FunctionBody '}'
387 Expect(Token::FUNCTION, CHECK_OK);
388 int pos = position();
389 bool is_generator = Check(Token::MUL);
390 bool is_strict_reserved = false; 383 bool is_strict_reserved = false;
391 Identifier name = ParseIdentifierOrStrictReservedWord( 384 Identifier name = ParseIdentifierOrStrictReservedWord(
392 &is_strict_reserved, CHECK_OK); 385 &is_strict_reserved, CHECK_OK);
393 ParseFunctionLiteral(name, scanner()->location(), 386 ParseFunctionLiteral(name, scanner()->location(),
394 is_strict_reserved ? kFunctionNameIsStrictReserved 387 is_strict_reserved ? kFunctionNameIsStrictReserved
395 : kFunctionNameValidityUnknown, 388 : kFunctionNameValidityUnknown,
396 is_generator ? FunctionKind::kGeneratorFunction 389 is_generator ? FunctionKind::kGeneratorFunction
397 : FunctionKind::kNormalFunction, 390 : FunctionKind::kNormalFunction,
398 pos, FunctionLiteral::kDeclaration, language_mode(), 391 pos, FunctionLiteral::kDeclaration, language_mode(),
399 CHECK_OK); 392 CHECK_OK);
400 return Statement::FunctionDeclaration(); 393 return Statement::FunctionDeclaration();
401 } 394 }
402 395
403 396
397 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) {
398 // FunctionDeclaration ::
399 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
400 // GeneratorDeclaration ::
401 // 'function' '*' Identifier '(' FormalParameterListopt ')'
402 // '{' FunctionBody '}'
403 Expect(Token::FUNCTION, CHECK_OK);
404 int pos = position();
405 bool is_generator = Check(Token::MUL);
406 return ParseHoistableDeclaration(pos, is_generator, CHECK_OK);
407 }
408
409
404 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { 410 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
405 Expect(Token::CLASS, CHECK_OK); 411 Expect(Token::CLASS, CHECK_OK);
406 412
407 int pos = position(); 413 int pos = position();
408 bool is_strict_reserved = false; 414 bool is_strict_reserved = false;
409 Identifier name = 415 Identifier name =
410 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 416 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
411 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, 417 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
412 CHECK_OK); 418 CHECK_OK);
413 return Statement::Default(); 419 return Statement::Default();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 *bindings_loc = 552 *bindings_loc =
547 Scanner::Location(bindings_start, scanner()->location().end_pos); 553 Scanner::Location(bindings_start, scanner()->location().end_pos);
548 } 554 }
549 555
550 if (num_decl != nullptr) *num_decl = nvars; 556 if (num_decl != nullptr) *num_decl = nvars;
551 if (is_lexical != nullptr) *is_lexical = lexical; 557 if (is_lexical != nullptr) *is_lexical = lexical;
552 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; 558 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern;
553 return Statement::Default(); 559 return Statement::Default();
554 } 560 }
555 561
562 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
563 Consume(Token::FUNCTION);
564 int pos = position();
565 bool is_generator = Check(Token::MUL);
566 if (allow_harmony_restrictive_declarations() && is_generator) {
567 PreParserTraits::ReportMessageAt(
568 scanner()->location(),
569 MessageTemplate::kGeneratorInLegacyContext);
570 *ok = false;
571 return Statement::Default();
572 }
573 return ParseHoistableDeclaration(pos, is_generator, ok);
574 }
575
556 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( 576 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
557 AllowLabelledFunctionStatement allow_function, bool* ok) { 577 AllowLabelledFunctionStatement allow_function, bool* ok) {
558 // ExpressionStatement | LabelledStatement :: 578 // ExpressionStatement | LabelledStatement ::
559 // Expression ';' 579 // Expression ';'
560 // Identifier ':' Statement 580 // Identifier ':' Statement
561 581
562 switch (peek()) { 582 switch (peek()) {
563 case Token::FUNCTION: 583 case Token::FUNCTION:
564 case Token::LBRACE: 584 case Token::LBRACE:
565 UNREACHABLE(); // Always handled by the callers. 585 UNREACHABLE(); // Always handled by the callers.
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 } 1218 }
1199 Expect(Token::RBRACE, CHECK_OK); 1219 Expect(Token::RBRACE, CHECK_OK);
1200 return PreParserExpression::Default(); 1220 return PreParserExpression::Default();
1201 } 1221 }
1202 1222
1203 #undef CHECK_OK 1223 #undef CHECK_OK
1204 1224
1205 1225
1206 } // namespace internal 1226 } // namespace internal
1207 } // namespace v8 1227 } // 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