Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 return Statement::Default(); | 271 return Statement::Default(); |
| 272 } | 272 } |
| 273 return ParseSubStatement(allow_function, ok); | 273 return ParseSubStatement(allow_function, ok); |
| 274 } | 274 } |
| 275 | 275 |
| 276 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 276 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
| 277 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 277 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 278 (legacy && allow_harmony_restrictive_declarations())) { | 278 (legacy && allow_harmony_restrictive_declarations())) { |
| 279 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 279 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
| 280 } else { | 280 } else { |
| 281 return ParseFunctionDeclaration(CHECK_OK); | 281 return ParseOnlyFunctionDeclaration(ok); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 PreParser::Statement PreParser::ParseSubStatement( | 285 PreParser::Statement PreParser::ParseSubStatement( |
| 286 AllowLabelledFunctionStatement allow_function, bool* ok) { | 286 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 287 // Statement :: | 287 // Statement :: |
| 288 // Block | 288 // Block |
| 289 // VariableStatement | 289 // VariableStatement |
| 290 // EmptyStatement | 290 // EmptyStatement |
| 291 // ExpressionStatement | 291 // ExpressionStatement |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 *bindings_loc = | 539 *bindings_loc = |
| 540 Scanner::Location(bindings_start, scanner()->location().end_pos); | 540 Scanner::Location(bindings_start, scanner()->location().end_pos); |
| 541 } | 541 } |
| 542 | 542 |
| 543 if (num_decl != nullptr) *num_decl = nvars; | 543 if (num_decl != nullptr) *num_decl = nvars; |
| 544 if (is_lexical != nullptr) *is_lexical = lexical; | 544 if (is_lexical != nullptr) *is_lexical = lexical; |
| 545 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; | 545 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; |
| 546 return Statement::Default(); | 546 return Statement::Default(); |
| 547 } | 547 } |
| 548 | 548 |
| 549 PreParser::Statement PreParser::ParseOnlyFunctionDeclaration(bool* ok) { | |
| 550 Consume(Token::FUNCTION); | |
| 551 int pos = position(); | |
| 552 bool is_generator = Check(Token::MUL); | |
| 553 if (allow_harmony_restrictive_declarations() && is_generator) { | |
| 554 PreParserTraits::ReportMessageAt( | |
| 555 scanner()->location(), | |
| 556 MessageTemplate::kGeneratorInLegacyContext); | |
| 557 *ok = false; | |
| 558 return Statement::Default(); | |
| 559 } | |
| 560 bool is_strict_reserved = false; | |
| 561 Identifier name = | |
| 562 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | |
| 563 ParseFunctionLiteral(name, scanner()->location(), | |
| 564 is_strict_reserved ? kFunctionNameIsStrictReserved | |
| 565 : kFunctionNameValidityUnknown, | |
| 566 is_generator ? FunctionKind::kGeneratorFunction | |
| 567 : FunctionKind::kNormalFunction, | |
| 568 pos, FunctionLiteral::kDeclaration, | |
|
adamk
2016/04/20 19:09:28
This is a lot of boilerplate to copy; what if you
Dan Ehrenberg
2016/04/26 22:24:19
Done
| |
| 569 language_mode(), CHECK_OK); | |
| 570 return Statement::FunctionDeclaration(); | |
| 571 } | |
| 572 | |
| 549 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( | 573 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( |
| 550 AllowLabelledFunctionStatement allow_function, bool* ok) { | 574 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 551 // ExpressionStatement | LabelledStatement :: | 575 // ExpressionStatement | LabelledStatement :: |
| 552 // Expression ';' | 576 // Expression ';' |
| 553 // Identifier ':' Statement | 577 // Identifier ':' Statement |
| 554 | 578 |
| 555 switch (peek()) { | 579 switch (peek()) { |
| 556 case Token::FUNCTION: | 580 case Token::FUNCTION: |
| 557 case Token::LBRACE: | 581 case Token::LBRACE: |
| 558 UNREACHABLE(); // Always handled by the callers. | 582 UNREACHABLE(); // Always handled by the callers. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 576 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { | 600 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { |
| 577 // Expression is a single identifier, and not, e.g., a parenthesized | 601 // Expression is a single identifier, and not, e.g., a parenthesized |
| 578 // identifier. | 602 // identifier. |
| 579 DCHECK(!expr.AsIdentifier().IsFutureReserved()); | 603 DCHECK(!expr.AsIdentifier().IsFutureReserved()); |
| 580 DCHECK(is_sloppy(language_mode()) || | 604 DCHECK(is_sloppy(language_mode()) || |
| 581 !IsFutureStrictReserved(expr.AsIdentifier())); | 605 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 582 Consume(Token::COLON); | 606 Consume(Token::COLON); |
| 583 // ES#sec-labelled-function-declarations Labelled Function Declarations | 607 // ES#sec-labelled-function-declarations Labelled Function Declarations |
| 584 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 608 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| 585 if (allow_function == kAllowLabelledFunctionStatement) { | 609 if (allow_function == kAllowLabelledFunctionStatement) { |
| 586 return ParseFunctionDeclaration(ok); | 610 return ParseOnlyFunctionDeclaration(ok); |
| 587 } else { | 611 } else { |
| 588 return ParseScopedStatement(true, ok); | 612 return ParseScopedStatement(true, ok); |
| 589 } | 613 } |
| 590 } | 614 } |
| 591 Statement statement = | 615 Statement statement = |
| 592 ParseStatement(kDisallowLabelledFunctionStatement, ok); | 616 ParseStatement(kDisallowLabelledFunctionStatement, ok); |
| 593 return statement.IsJumpStatement() ? Statement::Default() : statement; | 617 return statement.IsJumpStatement() ? Statement::Default() : statement; |
| 594 // Preparsing is disabled for extensions (because the extension details | 618 // Preparsing is disabled for extensions (because the extension details |
| 595 // aren't passed to lazily compiled functions), so we don't | 619 // aren't passed to lazily compiled functions), so we don't |
| 596 // accept "native function" in the preparser. | 620 // accept "native function" in the preparser. |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1124 Expect(Token::RBRACE, CHECK_OK); | 1148 Expect(Token::RBRACE, CHECK_OK); |
| 1125 return PreParserExpression::Default(); | 1149 return PreParserExpression::Default(); |
| 1126 } | 1150 } |
| 1127 } | 1151 } |
| 1128 | 1152 |
| 1129 #undef CHECK_OK | 1153 #undef CHECK_OK |
| 1130 | 1154 |
| 1131 | 1155 |
| 1132 } // namespace internal | 1156 } // namespace internal |
| 1133 } // namespace v8 | 1157 } // namespace v8 |
| OLD | NEW |