| 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" |
| 11 #include "src/globals.h" | 11 #include "src/globals.h" |
| 12 #include "src/hashmap.h" | 12 #include "src/hashmap.h" |
| 13 #include "src/list.h" | 13 #include "src/list.h" |
| 14 #include "src/preparse-data.h" | 14 #include "src/preparse-data.h" |
| 15 #include "src/preparse-data-format.h" | 15 #include "src/preparse-data-format.h" |
| 16 #include "src/preparser.h" | 16 #include "src/preparser.h" |
| 17 #include "src/unicode.h" | 17 #include "src/unicode.h" |
| 18 #include "src/utils.h" | 18 #include "src/utils.h" |
| 19 | 19 |
| 20 namespace v8 { | 20 namespace v8 { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 void PreParserTraits::ReportMessageAt(Scanner::Location location, | 23 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
| 24 const char* message, const char* arg, | 24 MessageTemplate::Template message, |
| 25 const char* arg, |
| 25 ParseErrorType error_type) { | 26 ParseErrorType error_type) { |
| 26 ReportMessageAt(location.beg_pos, location.end_pos, message, arg, error_type); | 27 ReportMessageAt(location.beg_pos, location.end_pos, message, arg, error_type); |
| 27 } | 28 } |
| 28 | 29 |
| 29 | 30 |
| 30 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, | 31 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, |
| 31 const char* message, const char* arg, | 32 MessageTemplate::Template message, |
| 33 const char* arg, |
| 32 ParseErrorType error_type) { | 34 ParseErrorType error_type) { |
| 33 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); | 35 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); |
| 34 } | 36 } |
| 35 | 37 |
| 36 | 38 |
| 37 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { | 39 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
| 38 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { | 40 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { |
| 39 return PreParserIdentifier::FutureReserved(); | 41 return PreParserIdentifier::FutureReserved(); |
| 40 } else if (scanner->current_token() == | 42 } else if (scanner->current_token() == |
| 41 Token::FUTURE_STRICT_RESERVED_WORD) { | 43 Token::FUTURE_STRICT_RESERVED_WORD) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } else { | 127 } else { |
| 126 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 128 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 127 if (is_strict(scope_->language_mode())) { | 129 if (is_strict(scope_->language_mode())) { |
| 128 int end_pos = scanner()->location().end_pos; | 130 int end_pos = scanner()->location().end_pos; |
| 129 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 131 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
| 130 if (!ok) return kPreParseSuccess; | 132 if (!ok) return kPreParseSuccess; |
| 131 | 133 |
| 132 if (is_strong(scope_->language_mode()) && IsSubclassConstructor(kind)) { | 134 if (is_strong(scope_->language_mode()) && IsSubclassConstructor(kind)) { |
| 133 if (!function_state.super_location().IsValid()) { | 135 if (!function_state.super_location().IsValid()) { |
| 134 ReportMessageAt(Scanner::Location(start_position, start_position + 1), | 136 ReportMessageAt(Scanner::Location(start_position, start_position + 1), |
| 135 "strong_super_call_missing", kReferenceError); | 137 MessageTemplate::kStrongSuperCallMissing, |
| 138 kReferenceError); |
| 136 return kPreParseSuccess; | 139 return kPreParseSuccess; |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 } | 142 } |
| 140 } | 143 } |
| 141 return kPreParseSuccess; | 144 return kPreParseSuccess; |
| 142 } | 145 } |
| 143 | 146 |
| 144 | 147 |
| 145 PreParserExpression PreParserTraits::ParseClassLiteral( | 148 PreParserExpression PreParserTraits::ParseClassLiteral( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 Statement statement = ParseStatementListItem(ok); | 225 Statement statement = ParseStatementListItem(ok); |
| 223 if (!*ok) return; | 226 if (!*ok) return; |
| 224 | 227 |
| 225 if (is_strong(language_mode()) && | 228 if (is_strong(language_mode()) && |
| 226 scope_->is_function_scope() && | 229 scope_->is_function_scope() && |
| 227 i::IsConstructor(function_state_->kind())) { | 230 i::IsConstructor(function_state_->kind())) { |
| 228 Scanner::Location this_loc = function_state_->this_location(); | 231 Scanner::Location this_loc = function_state_->this_location(); |
| 229 Scanner::Location super_loc = function_state_->super_location(); | 232 Scanner::Location super_loc = function_state_->super_location(); |
| 230 if (this_loc.beg_pos != old_this_loc.beg_pos && | 233 if (this_loc.beg_pos != old_this_loc.beg_pos && |
| 231 this_loc.beg_pos != token_loc.beg_pos) { | 234 this_loc.beg_pos != token_loc.beg_pos) { |
| 232 ReportMessageAt(this_loc, "strong_constructor_this"); | 235 ReportMessageAt(this_loc, MessageTemplate::kStrongConstructorThis); |
| 233 *ok = false; | 236 *ok = false; |
| 234 return; | 237 return; |
| 235 } | 238 } |
| 236 if (super_loc.beg_pos != old_super_loc.beg_pos && | 239 if (super_loc.beg_pos != old_super_loc.beg_pos && |
| 237 super_loc.beg_pos != token_loc.beg_pos) { | 240 super_loc.beg_pos != token_loc.beg_pos) { |
| 238 ReportMessageAt(super_loc, "strong_constructor_super"); | 241 ReportMessageAt(super_loc, MessageTemplate::kStrongConstructorSuper); |
| 239 *ok = false; | 242 *ok = false; |
| 240 return; | 243 return; |
| 241 } | 244 } |
| 242 } | 245 } |
| 243 | 246 |
| 244 if (directive_prologue) { | 247 if (directive_prologue) { |
| 245 if (statement.IsUseStrictLiteral()) { | 248 if (statement.IsUseStrictLiteral()) { |
| 246 scope_->SetLanguageMode( | 249 scope_->SetLanguageMode( |
| 247 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 250 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
| 248 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { | 251 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // parsed into an empty statement. | 319 // parsed into an empty statement. |
| 317 | 320 |
| 318 // Keep the source position of the statement | 321 // Keep the source position of the statement |
| 319 switch (peek()) { | 322 switch (peek()) { |
| 320 case Token::LBRACE: | 323 case Token::LBRACE: |
| 321 return ParseBlock(ok); | 324 return ParseBlock(ok); |
| 322 | 325 |
| 323 case Token::SEMICOLON: | 326 case Token::SEMICOLON: |
| 324 if (is_strong(language_mode())) { | 327 if (is_strong(language_mode())) { |
| 325 PreParserTraits::ReportMessageAt(scanner()->peek_location(), | 328 PreParserTraits::ReportMessageAt(scanner()->peek_location(), |
| 326 "strong_empty"); | 329 MessageTemplate::kStrongEmpty); |
| 327 *ok = false; | 330 *ok = false; |
| 328 return Statement::Default(); | 331 return Statement::Default(); |
| 329 } | 332 } |
| 330 Next(); | 333 Next(); |
| 331 return Statement::Default(); | 334 return Statement::Default(); |
| 332 | 335 |
| 333 case Token::IF: | 336 case Token::IF: |
| 334 return ParseIfStatement(ok); | 337 return ParseIfStatement(ok); |
| 335 | 338 |
| 336 case Token::DO: | 339 case Token::DO: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 363 case Token::TRY: | 366 case Token::TRY: |
| 364 return ParseTryStatement(ok); | 367 return ParseTryStatement(ok); |
| 365 | 368 |
| 366 case Token::FUNCTION: { | 369 case Token::FUNCTION: { |
| 367 Scanner::Location start_location = scanner()->peek_location(); | 370 Scanner::Location start_location = scanner()->peek_location(); |
| 368 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 371 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
| 369 Scanner::Location end_location = scanner()->location(); | 372 Scanner::Location end_location = scanner()->location(); |
| 370 if (is_strict(language_mode())) { | 373 if (is_strict(language_mode())) { |
| 371 PreParserTraits::ReportMessageAt(start_location.beg_pos, | 374 PreParserTraits::ReportMessageAt(start_location.beg_pos, |
| 372 end_location.end_pos, | 375 end_location.end_pos, |
| 373 "strict_function"); | 376 MessageTemplate::kStrictFunction); |
| 374 *ok = false; | 377 *ok = false; |
| 375 return Statement::Default(); | 378 return Statement::Default(); |
| 376 } else { | 379 } else { |
| 377 return statement; | 380 return statement; |
| 378 } | 381 } |
| 379 } | 382 } |
| 380 | 383 |
| 381 case Token::DEBUGGER: | 384 case Token::DEBUGGER: |
| 382 return ParseDebuggerStatement(ok); | 385 return ParseDebuggerStatement(ok); |
| 383 | 386 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 : FunctionKind::kNormalFunction, | 419 : FunctionKind::kNormalFunction, |
| 417 pos, FunctionLiteral::DECLARATION, | 420 pos, FunctionLiteral::DECLARATION, |
| 418 FunctionLiteral::NORMAL_ARITY, CHECK_OK); | 421 FunctionLiteral::NORMAL_ARITY, CHECK_OK); |
| 419 return Statement::FunctionDeclaration(); | 422 return Statement::FunctionDeclaration(); |
| 420 } | 423 } |
| 421 | 424 |
| 422 | 425 |
| 423 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { | 426 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
| 424 Expect(Token::CLASS, CHECK_OK); | 427 Expect(Token::CLASS, CHECK_OK); |
| 425 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 428 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 426 ReportMessage("sloppy_lexical"); | 429 ReportMessage(MessageTemplate::kSloppyLexical); |
| 427 *ok = false; | 430 *ok = false; |
| 428 return Statement::Default(); | 431 return Statement::Default(); |
| 429 } | 432 } |
| 430 | 433 |
| 431 int pos = position(); | 434 int pos = position(); |
| 432 bool is_strict_reserved = false; | 435 bool is_strict_reserved = false; |
| 433 Identifier name = | 436 Identifier name = |
| 434 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 437 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 435 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | 438 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, |
| 436 CHECK_OK); | 439 CHECK_OK); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // Identifier '=' AssignmentExpression | 495 // Identifier '=' AssignmentExpression |
| 493 // | 496 // |
| 494 // TODO(ES6): | 497 // TODO(ES6): |
| 495 // ConstBinding :: | 498 // ConstBinding :: |
| 496 // BindingPattern '=' AssignmentExpression | 499 // BindingPattern '=' AssignmentExpression |
| 497 bool require_initializer = false; | 500 bool require_initializer = false; |
| 498 bool is_strict_const = false; | 501 bool is_strict_const = false; |
| 499 if (peek() == Token::VAR) { | 502 if (peek() == Token::VAR) { |
| 500 if (is_strong(language_mode())) { | 503 if (is_strong(language_mode())) { |
| 501 Scanner::Location location = scanner()->peek_location(); | 504 Scanner::Location location = scanner()->peek_location(); |
| 502 ReportMessageAt(location, "strong_var"); | 505 ReportMessageAt(location, MessageTemplate::kStrongVar); |
| 503 *ok = false; | 506 *ok = false; |
| 504 return Statement::Default(); | 507 return Statement::Default(); |
| 505 } | 508 } |
| 506 Consume(Token::VAR); | 509 Consume(Token::VAR); |
| 507 } else if (peek() == Token::CONST) { | 510 } else if (peek() == Token::CONST) { |
| 508 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: | 511 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: |
| 509 // | 512 // |
| 510 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 513 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
| 511 // | 514 // |
| 512 // * It is a Syntax Error if the code that matches this production is not | 515 // * It is a Syntax Error if the code that matches this production is not |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 switch (peek()) { | 613 switch (peek()) { |
| 611 case Token::SEMICOLON: | 614 case Token::SEMICOLON: |
| 612 Consume(Token::SEMICOLON); | 615 Consume(Token::SEMICOLON); |
| 613 break; | 616 break; |
| 614 case Token::RBRACE: | 617 case Token::RBRACE: |
| 615 case Token::EOS: | 618 case Token::EOS: |
| 616 break; | 619 break; |
| 617 default: | 620 default: |
| 618 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { | 621 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 619 ReportMessageAt(function_state_->this_location(), | 622 ReportMessageAt(function_state_->this_location(), |
| 620 is_this ? "strong_constructor_this" | 623 is_this |
| 621 : "strong_constructor_super"); | 624 ? MessageTemplate::kStrongConstructorThis |
| 625 : MessageTemplate::kStrongConstructorSuper); |
| 622 *ok = false; | 626 *ok = false; |
| 623 return Statement::Default(); | 627 return Statement::Default(); |
| 624 } | 628 } |
| 625 } | 629 } |
| 626 return Statement::ExpressionStatement(expr); | 630 return Statement::ExpressionStatement(expr); |
| 627 } | 631 } |
| 628 break; | 632 break; |
| 629 | 633 |
| 630 // TODO(arv): Handle `let [` | 634 // TODO(arv): Handle `let [` |
| 631 // https://code.google.com/p/v8/issues/detail?id=3847 | 635 // https://code.google.com/p/v8/issues/detail?id=3847 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 652 Statement statement = ParseStatement(ok); | 656 Statement statement = ParseStatement(ok); |
| 653 return statement.IsJumpStatement() ? Statement::Default() : statement; | 657 return statement.IsJumpStatement() ? Statement::Default() : statement; |
| 654 // Preparsing is disabled for extensions (because the extension details | 658 // Preparsing is disabled for extensions (because the extension details |
| 655 // aren't passed to lazily compiled functions), so we don't | 659 // aren't passed to lazily compiled functions), so we don't |
| 656 // accept "native function" in the preparser. | 660 // accept "native function" in the preparser. |
| 657 } | 661 } |
| 658 // Parsed expression statement. | 662 // Parsed expression statement. |
| 659 // Detect attempts at 'let' declarations in sloppy mode. | 663 // Detect attempts at 'let' declarations in sloppy mode. |
| 660 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && | 664 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && |
| 661 expr.IsIdentifier() && expr.AsIdentifier().IsLet()) { | 665 expr.IsIdentifier() && expr.AsIdentifier().IsLet()) { |
| 662 ReportMessage("sloppy_lexical", NULL); | 666 ReportMessage(MessageTemplate::kSloppyLexical, NULL); |
| 663 *ok = false; | 667 *ok = false; |
| 664 return Statement::Default(); | 668 return Statement::Default(); |
| 665 } | 669 } |
| 666 ExpectSemicolon(CHECK_OK); | 670 ExpectSemicolon(CHECK_OK); |
| 667 return Statement::ExpressionStatement(expr); | 671 return Statement::ExpressionStatement(expr); |
| 668 } | 672 } |
| 669 | 673 |
| 670 | 674 |
| 671 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { | 675 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { |
| 672 // IfStatement :: | 676 // IfStatement :: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 746 |
| 743 Token::Value tok = peek(); | 747 Token::Value tok = peek(); |
| 744 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 748 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 745 tok != Token::SEMICOLON && | 749 tok != Token::SEMICOLON && |
| 746 tok != Token::RBRACE && | 750 tok != Token::RBRACE && |
| 747 tok != Token::EOS) { | 751 tok != Token::EOS) { |
| 748 if (is_strong(language_mode()) && | 752 if (is_strong(language_mode()) && |
| 749 i::IsConstructor(function_state_->kind())) { | 753 i::IsConstructor(function_state_->kind())) { |
| 750 int pos = peek_position(); | 754 int pos = peek_position(); |
| 751 ReportMessageAt(Scanner::Location(pos, pos + 1), | 755 ReportMessageAt(Scanner::Location(pos, pos + 1), |
| 752 "strong_constructor_return_value"); | 756 MessageTemplate::kStrongConstructorReturnValue); |
| 753 *ok = false; | 757 *ok = false; |
| 754 return Statement::Default(); | 758 return Statement::Default(); |
| 755 } | 759 } |
| 756 ParseExpression(true, CHECK_OK); | 760 ParseExpression(true, CHECK_OK); |
| 757 } | 761 } |
| 758 ExpectSemicolon(CHECK_OK); | 762 ExpectSemicolon(CHECK_OK); |
| 759 return Statement::Jump(); | 763 return Statement::Jump(); |
| 760 } | 764 } |
| 761 | 765 |
| 762 | 766 |
| 763 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 767 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
| 764 // WithStatement :: | 768 // WithStatement :: |
| 765 // 'with' '(' Expression ')' Statement | 769 // 'with' '(' Expression ')' Statement |
| 766 Expect(Token::WITH, CHECK_OK); | 770 Expect(Token::WITH, CHECK_OK); |
| 767 if (is_strict(language_mode())) { | 771 if (is_strict(language_mode())) { |
| 768 ReportMessageAt(scanner()->location(), "strict_mode_with"); | 772 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); |
| 769 *ok = false; | 773 *ok = false; |
| 770 return Statement::Default(); | 774 return Statement::Default(); |
| 771 } | 775 } |
| 772 Expect(Token::LPAREN, CHECK_OK); | 776 Expect(Token::LPAREN, CHECK_OK); |
| 773 ParseExpression(true, CHECK_OK); | 777 ParseExpression(true, CHECK_OK); |
| 774 Expect(Token::RPAREN, CHECK_OK); | 778 Expect(Token::RPAREN, CHECK_OK); |
| 775 | 779 |
| 776 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 780 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
| 777 BlockState block_state(&scope_, with_scope); | 781 BlockState block_state(&scope_, with_scope); |
| 778 ParseSubStatement(CHECK_OK); | 782 ParseSubStatement(CHECK_OK); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 802 token = peek(); | 806 token = peek(); |
| 803 Statement statement = Statement::Jump(); | 807 Statement statement = Statement::Jump(); |
| 804 while (token != Token::CASE && | 808 while (token != Token::CASE && |
| 805 token != Token::DEFAULT && | 809 token != Token::DEFAULT && |
| 806 token != Token::RBRACE) { | 810 token != Token::RBRACE) { |
| 807 statement = ParseStatementListItem(CHECK_OK); | 811 statement = ParseStatementListItem(CHECK_OK); |
| 808 token = peek(); | 812 token = peek(); |
| 809 } | 813 } |
| 810 if (is_strong(language_mode()) && !statement.IsJumpStatement() && | 814 if (is_strong(language_mode()) && !statement.IsJumpStatement() && |
| 811 token != Token::RBRACE) { | 815 token != Token::RBRACE) { |
| 812 ReportMessageAt(scanner()->location(), "strong_switch_fallthrough"); | 816 ReportMessageAt(scanner()->location(), |
| 817 MessageTemplate::kStrongSwitchFallthrough); |
| 813 *ok = false; | 818 *ok = false; |
| 814 return Statement::Default(); | 819 return Statement::Default(); |
| 815 } | 820 } |
| 816 } | 821 } |
| 817 Expect(Token::RBRACE, ok); | 822 Expect(Token::RBRACE, ok); |
| 818 return Statement::Default(); | 823 return Statement::Default(); |
| 819 } | 824 } |
| 820 | 825 |
| 821 | 826 |
| 822 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { | 827 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 &first_initializer_loc, &bindings_loc, | 870 &first_initializer_loc, &bindings_loc, |
| 866 CHECK_OK); | 871 CHECK_OK); |
| 867 bool accept_IN = decl_count >= 1; | 872 bool accept_IN = decl_count >= 1; |
| 868 bool accept_OF = true; | 873 bool accept_OF = true; |
| 869 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { | 874 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { |
| 870 if (!*ok) return Statement::Default(); | 875 if (!*ok) return Statement::Default(); |
| 871 if (decl_count != 1) { | 876 if (decl_count != 1) { |
| 872 const char* loop_type = | 877 const char* loop_type = |
| 873 mode == ForEachStatement::ITERATE ? "for-of" : "for-in"; | 878 mode == ForEachStatement::ITERATE ? "for-of" : "for-in"; |
| 874 PreParserTraits::ReportMessageAt( | 879 PreParserTraits::ReportMessageAt( |
| 875 bindings_loc, "for_inof_loop_multi_bindings", loop_type); | 880 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings, |
| 881 loop_type); |
| 876 *ok = false; | 882 *ok = false; |
| 877 return Statement::Default(); | 883 return Statement::Default(); |
| 878 } | 884 } |
| 879 if (first_initializer_loc.IsValid() && | 885 if (first_initializer_loc.IsValid() && |
| 880 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE)) { | 886 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE)) { |
| 881 if (mode == ForEachStatement::ITERATE) { | 887 if (mode == ForEachStatement::ITERATE) { |
| 882 ReportMessageAt(first_initializer_loc, "for_of_loop_initializer"); | 888 ReportMessageAt(first_initializer_loc, |
| 889 MessageTemplate::kForOfLoopInitializer); |
| 883 } else { | 890 } else { |
| 884 // TODO(caitp): This should be an error in sloppy mode, too. | 891 // TODO(caitp): This should be an error in sloppy mode, too. |
| 885 ReportMessageAt(first_initializer_loc, "for_in_loop_initializer"); | 892 ReportMessageAt(first_initializer_loc, |
| 893 MessageTemplate::kForInLoopInitializer); |
| 886 } | 894 } |
| 887 *ok = false; | 895 *ok = false; |
| 888 return Statement::Default(); | 896 return Statement::Default(); |
| 889 } | 897 } |
| 890 ParseExpression(true, CHECK_OK); | 898 ParseExpression(true, CHECK_OK); |
| 891 Expect(Token::RPAREN, CHECK_OK); | 899 Expect(Token::RPAREN, CHECK_OK); |
| 892 ParseSubStatement(CHECK_OK); | 900 ParseSubStatement(CHECK_OK); |
| 893 return Statement::Default(); | 901 return Statement::Default(); |
| 894 } | 902 } |
| 895 } else { | 903 } else { |
| 896 Expression lhs = ParseExpression(false, CHECK_OK); | 904 Expression lhs = ParseExpression(false, CHECK_OK); |
| 897 is_let_identifier_expression = | 905 is_let_identifier_expression = |
| 898 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); | 906 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
| 899 if (CheckInOrOf(lhs.IsIdentifier(), &mode, ok)) { | 907 if (CheckInOrOf(lhs.IsIdentifier(), &mode, ok)) { |
| 900 if (!*ok) return Statement::Default(); | 908 if (!*ok) return Statement::Default(); |
| 901 ParseExpression(true, CHECK_OK); | 909 ParseExpression(true, CHECK_OK); |
| 902 Expect(Token::RPAREN, CHECK_OK); | 910 Expect(Token::RPAREN, CHECK_OK); |
| 903 ParseSubStatement(CHECK_OK); | 911 ParseSubStatement(CHECK_OK); |
| 904 return Statement::Default(); | 912 return Statement::Default(); |
| 905 } | 913 } |
| 906 } | 914 } |
| 907 } | 915 } |
| 908 | 916 |
| 909 // Parsed initializer at this point. | 917 // Parsed initializer at this point. |
| 910 // Detect attempts at 'let' declarations in sloppy mode. | 918 // Detect attempts at 'let' declarations in sloppy mode. |
| 911 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && | 919 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && |
| 912 is_let_identifier_expression) { | 920 is_let_identifier_expression) { |
| 913 ReportMessage("sloppy_lexical", NULL); | 921 ReportMessage(MessageTemplate::kSloppyLexical, NULL); |
| 914 *ok = false; | 922 *ok = false; |
| 915 return Statement::Default(); | 923 return Statement::Default(); |
| 916 } | 924 } |
| 917 Expect(Token::SEMICOLON, CHECK_OK); | 925 Expect(Token::SEMICOLON, CHECK_OK); |
| 918 | 926 |
| 919 if (peek() != Token::SEMICOLON) { | 927 if (peek() != Token::SEMICOLON) { |
| 920 ParseExpression(true, CHECK_OK); | 928 ParseExpression(true, CHECK_OK); |
| 921 } | 929 } |
| 922 Expect(Token::SEMICOLON, CHECK_OK); | 930 Expect(Token::SEMICOLON, CHECK_OK); |
| 923 | 931 |
| 924 if (peek() != Token::RPAREN) { | 932 if (peek() != Token::RPAREN) { |
| 925 ParseExpression(true, CHECK_OK); | 933 ParseExpression(true, CHECK_OK); |
| 926 } | 934 } |
| 927 Expect(Token::RPAREN, CHECK_OK); | 935 Expect(Token::RPAREN, CHECK_OK); |
| 928 | 936 |
| 929 ParseSubStatement(ok); | 937 ParseSubStatement(ok); |
| 930 return Statement::Default(); | 938 return Statement::Default(); |
| 931 } | 939 } |
| 932 | 940 |
| 933 | 941 |
| 934 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { | 942 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { |
| 935 // ThrowStatement :: | 943 // ThrowStatement :: |
| 936 // 'throw' [no line terminator] Expression ';' | 944 // 'throw' [no line terminator] Expression ';' |
| 937 | 945 |
| 938 Expect(Token::THROW, CHECK_OK); | 946 Expect(Token::THROW, CHECK_OK); |
| 939 if (scanner()->HasAnyLineTerminatorBeforeNext()) { | 947 if (scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 940 ReportMessageAt(scanner()->location(), "newline_after_throw"); | 948 ReportMessageAt(scanner()->location(), MessageTemplate::kNewlineAfterThrow); |
| 941 *ok = false; | 949 *ok = false; |
| 942 return Statement::Default(); | 950 return Statement::Default(); |
| 943 } | 951 } |
| 944 ParseExpression(true, CHECK_OK); | 952 ParseExpression(true, CHECK_OK); |
| 945 ExpectSemicolon(ok); | 953 ExpectSemicolon(ok); |
| 946 return Statement::Jump(); | 954 return Statement::Jump(); |
| 947 } | 955 } |
| 948 | 956 |
| 949 | 957 |
| 950 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { | 958 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
| 951 // TryStatement :: | 959 // TryStatement :: |
| 952 // 'try' Block Catch | 960 // 'try' Block Catch |
| 953 // 'try' Block Finally | 961 // 'try' Block Finally |
| 954 // 'try' Block Catch Finally | 962 // 'try' Block Catch Finally |
| 955 // | 963 // |
| 956 // Catch :: | 964 // Catch :: |
| 957 // 'catch' '(' Identifier ')' Block | 965 // 'catch' '(' Identifier ')' Block |
| 958 // | 966 // |
| 959 // Finally :: | 967 // Finally :: |
| 960 // 'finally' Block | 968 // 'finally' Block |
| 961 | 969 |
| 962 Expect(Token::TRY, CHECK_OK); | 970 Expect(Token::TRY, CHECK_OK); |
| 963 | 971 |
| 964 ParseBlock(CHECK_OK); | 972 ParseBlock(CHECK_OK); |
| 965 | 973 |
| 966 Token::Value tok = peek(); | 974 Token::Value tok = peek(); |
| 967 if (tok != Token::CATCH && tok != Token::FINALLY) { | 975 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 968 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); | 976 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); |
| 969 *ok = false; | 977 *ok = false; |
| 970 return Statement::Default(); | 978 return Statement::Default(); |
| 971 } | 979 } |
| 972 if (tok == Token::CATCH) { | 980 if (tok == Token::CATCH) { |
| 973 Consume(Token::CATCH); | 981 Consume(Token::CATCH); |
| 974 Expect(Token::LPAREN, CHECK_OK); | 982 Expect(Token::LPAREN, CHECK_OK); |
| 975 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 983 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
| 976 Expect(Token::RPAREN, CHECK_OK); | 984 Expect(Token::RPAREN, CHECK_OK); |
| 977 { | 985 { |
| 978 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 986 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 ValidateFormalParameters(&formals_classifier, language_mode(), | 1074 ValidateFormalParameters(&formals_classifier, language_mode(), |
| 1067 allow_duplicate_parameters, CHECK_OK); | 1075 allow_duplicate_parameters, CHECK_OK); |
| 1068 | 1076 |
| 1069 if (is_strict(language_mode())) { | 1077 if (is_strict(language_mode())) { |
| 1070 int end_position = scanner()->location().end_pos; | 1078 int end_position = scanner()->location().end_pos; |
| 1071 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1079 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 1072 } | 1080 } |
| 1073 | 1081 |
| 1074 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { | 1082 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { |
| 1075 if (!function_state.super_location().IsValid()) { | 1083 if (!function_state.super_location().IsValid()) { |
| 1076 ReportMessageAt(function_name_location, "strong_super_call_missing", | 1084 ReportMessageAt(function_name_location, |
| 1085 MessageTemplate::kStrongSuperCallMissing, |
| 1077 kReferenceError); | 1086 kReferenceError); |
| 1078 *ok = false; | 1087 *ok = false; |
| 1079 return Expression::Default(); | 1088 return Expression::Default(); |
| 1080 } | 1089 } |
| 1081 } | 1090 } |
| 1082 | 1091 |
| 1083 return Expression::Default(); | 1092 return Expression::Default(); |
| 1084 } | 1093 } |
| 1085 | 1094 |
| 1086 | 1095 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1099 function_state_->expected_property_count(), language_mode(), | 1108 function_state_->expected_property_count(), language_mode(), |
| 1100 scope_->uses_super_property()); | 1109 scope_->uses_super_property()); |
| 1101 } | 1110 } |
| 1102 | 1111 |
| 1103 | 1112 |
| 1104 PreParserExpression PreParser::ParseClassLiteral( | 1113 PreParserExpression PreParser::ParseClassLiteral( |
| 1105 PreParserIdentifier name, Scanner::Location class_name_location, | 1114 PreParserIdentifier name, Scanner::Location class_name_location, |
| 1106 bool name_is_strict_reserved, int pos, bool* ok) { | 1115 bool name_is_strict_reserved, int pos, bool* ok) { |
| 1107 // All parts of a ClassDeclaration and ClassExpression are strict code. | 1116 // All parts of a ClassDeclaration and ClassExpression are strict code. |
| 1108 if (name_is_strict_reserved) { | 1117 if (name_is_strict_reserved) { |
| 1109 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | 1118 ReportMessageAt(class_name_location, |
| 1119 MessageTemplate::kUnexpectedStrictReserved); |
| 1110 *ok = false; | 1120 *ok = false; |
| 1111 return EmptyExpression(); | 1121 return EmptyExpression(); |
| 1112 } | 1122 } |
| 1113 if (IsEvalOrArguments(name)) { | 1123 if (IsEvalOrArguments(name)) { |
| 1114 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 1124 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
| 1115 *ok = false; | 1125 *ok = false; |
| 1116 return EmptyExpression(); | 1126 return EmptyExpression(); |
| 1117 } | 1127 } |
| 1118 LanguageMode class_language_mode = language_mode(); | 1128 LanguageMode class_language_mode = language_mode(); |
| 1119 if (is_strong(class_language_mode) && IsUndefined(name)) { | 1129 if (is_strong(class_language_mode) && IsUndefined(name)) { |
| 1120 ReportMessageAt(class_name_location, "strong_undefined"); | 1130 ReportMessageAt(class_name_location, MessageTemplate::kStrongUndefined); |
| 1121 *ok = false; | 1131 *ok = false; |
| 1122 return EmptyExpression(); | 1132 return EmptyExpression(); |
| 1123 } | 1133 } |
| 1124 | 1134 |
| 1125 Scope* scope = NewScope(scope_, BLOCK_SCOPE); | 1135 Scope* scope = NewScope(scope_, BLOCK_SCOPE); |
| 1126 BlockState block_state(&scope_, scope); | 1136 BlockState block_state(&scope_, scope); |
| 1127 scope_->SetLanguageMode( | 1137 scope_->SetLanguageMode( |
| 1128 static_cast<LanguageMode>(class_language_mode | STRICT_BIT)); | 1138 static_cast<LanguageMode>(class_language_mode | STRICT_BIT)); |
| 1129 // TODO(marja): Make PreParser use scope names too. | 1139 // TODO(marja): Make PreParser use scope names too. |
| 1130 // scope_->SetScopeName(name); | 1140 // scope_->SetScopeName(name); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1186 |
| 1177 DCHECK(!spread_pos.IsValid()); | 1187 DCHECK(!spread_pos.IsValid()); |
| 1178 | 1188 |
| 1179 return Expression::Default(); | 1189 return Expression::Default(); |
| 1180 } | 1190 } |
| 1181 | 1191 |
| 1182 #undef CHECK_OK | 1192 #undef CHECK_OK |
| 1183 | 1193 |
| 1184 | 1194 |
| 1185 } } // v8::internal | 1195 } } // v8::internal |
| OLD | NEW |