| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // Usually defined in math.h, but not in MSVC until VS2013+. | 48 // Usually defined in math.h, but not in MSVC until VS2013+. |
| 49 // Abstracted to work | 49 // Abstracted to work |
| 50 int isfinite(double value); | 50 int isfinite(double value); |
| 51 | 51 |
| 52 } // namespace std | 52 } // namespace std |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 namespace v8 { | 55 namespace v8 { |
| 56 namespace internal { | 56 namespace internal { |
| 57 | 57 |
| 58 bool PreParserTraits::is_classic_mode() const { |
| 59 return pre_parser_->scope_->language_mode() == CLASSIC_MODE; |
| 60 } |
| 61 |
| 62 |
| 63 bool PreParserTraits::is_generator() const { |
| 64 return pre_parser_->scope_->is_generator(); |
| 65 } |
| 66 |
| 67 |
| 68 int PreParserTraits::NextMaterializedLiteralIndex() { |
| 69 return pre_parser_->scope_->NextMaterializedLiteralIndex(); |
| 70 } |
| 71 |
| 72 |
| 73 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
| 74 const char* message, |
| 75 Vector<const char*> args) { |
| 76 ReportMessageAt(location.beg_pos, |
| 77 location.end_pos, |
| 78 message, |
| 79 args.length() > 0 ? args[0] : NULL); |
| 80 } |
| 81 |
| 82 |
| 83 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
| 84 const char* type, |
| 85 const char* name_opt) { |
| 86 pre_parser_->log_ |
| 87 ->LogMessage(location.beg_pos, location.end_pos, type, name_opt); |
| 88 } |
| 89 |
| 90 |
| 91 void PreParserTraits::ReportMessageAt(int start_pos, |
| 92 int end_pos, |
| 93 const char* type, |
| 94 const char* name_opt) { |
| 95 pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt); |
| 96 } |
| 97 |
| 98 |
| 99 PreParserIdentifier PreParserTraits::GetSymbol() { |
| 100 Scanner* scanner = pre_parser_->scanner(); |
| 101 pre_parser_->LogSymbol(); |
| 102 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { |
| 103 return PreParserIdentifier::FutureReserved(); |
| 104 } else if (scanner->current_token() == |
| 105 Token::FUTURE_STRICT_RESERVED_WORD) { |
| 106 return PreParserIdentifier::FutureStrictReserved(); |
| 107 } else if (scanner->current_token() == Token::YIELD) { |
| 108 return PreParserIdentifier::Yield(); |
| 109 } |
| 110 if (scanner->is_literal_ascii()) { |
| 111 // Detect strict-mode poison words. |
| 112 if (scanner->literal_length() == 4 && |
| 113 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) { |
| 114 return PreParserIdentifier::Eval(); |
| 115 } |
| 116 if (scanner->literal_length() == 9 && |
| 117 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) { |
| 118 return PreParserIdentifier::Arguments(); |
| 119 } |
| 120 } |
| 121 return PreParserIdentifier::Default(); |
| 122 } |
| 123 |
| 124 |
| 58 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 125 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 59 LanguageMode mode, bool is_generator, ParserRecorder* log) { | 126 LanguageMode mode, bool is_generator, ParserRecorder* log) { |
| 60 log_ = log; | 127 log_ = log; |
| 61 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 128 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 62 Scope top_scope(&scope_, kTopLevelScope); | 129 Scope top_scope(&scope_, kTopLevelScope); |
| 63 set_language_mode(mode); | 130 set_language_mode(mode); |
| 64 Scope function_scope(&scope_, kFunctionScope); | 131 Scope function_scope(&scope_, kFunctionScope); |
| 65 function_scope.set_is_generator(is_generator); | 132 function_scope.set_is_generator(is_generator); |
| 66 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); | 133 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
| 67 bool ok = true; | 134 bool ok = true; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return ParseThrowStatement(ok); | 295 return ParseThrowStatement(ok); |
| 229 | 296 |
| 230 case Token::TRY: | 297 case Token::TRY: |
| 231 return ParseTryStatement(ok); | 298 return ParseTryStatement(ok); |
| 232 | 299 |
| 233 case Token::FUNCTION: { | 300 case Token::FUNCTION: { |
| 234 Scanner::Location start_location = scanner()->peek_location(); | 301 Scanner::Location start_location = scanner()->peek_location(); |
| 235 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 302 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
| 236 Scanner::Location end_location = scanner()->location(); | 303 Scanner::Location end_location = scanner()->location(); |
| 237 if (!scope_->is_classic_mode()) { | 304 if (!scope_->is_classic_mode()) { |
| 238 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | 305 PreParserTraits::ReportMessageAt(start_location.beg_pos, |
| 239 "strict_function", NULL); | 306 end_location.end_pos, |
| 307 "strict_function", |
| 308 NULL); |
| 240 *ok = false; | 309 *ok = false; |
| 241 return Statement::Default(); | 310 return Statement::Default(); |
| 242 } else { | 311 } else { |
| 243 return statement; | 312 return statement; |
| 244 } | 313 } |
| 245 } | 314 } |
| 246 | 315 |
| 247 case Token::DEBUGGER: | 316 case Token::DEBUGGER: |
| 248 return ParseDebuggerStatement(ok); | 317 return ParseDebuggerStatement(ok); |
| 249 | 318 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // | 414 // |
| 346 // However disallowing const in classic mode will break compatibility with | 415 // However disallowing const in classic mode will break compatibility with |
| 347 // existing pages. Therefore we keep allowing const with the old | 416 // existing pages. Therefore we keep allowing const with the old |
| 348 // non-harmony semantics in classic mode. | 417 // non-harmony semantics in classic mode. |
| 349 Consume(Token::CONST); | 418 Consume(Token::CONST); |
| 350 switch (language_mode()) { | 419 switch (language_mode()) { |
| 351 case CLASSIC_MODE: | 420 case CLASSIC_MODE: |
| 352 break; | 421 break; |
| 353 case STRICT_MODE: { | 422 case STRICT_MODE: { |
| 354 Scanner::Location location = scanner()->peek_location(); | 423 Scanner::Location location = scanner()->peek_location(); |
| 355 ReportMessageAt(location, "strict_const", NULL); | 424 ReportMessageAt(location, "strict_const"); |
| 356 *ok = false; | 425 *ok = false; |
| 357 return Statement::Default(); | 426 return Statement::Default(); |
| 358 } | 427 } |
| 359 case EXTENDED_MODE: | 428 case EXTENDED_MODE: |
| 360 if (var_context != kSourceElement && | 429 if (var_context != kSourceElement && |
| 361 var_context != kForStatement) { | 430 var_context != kForStatement) { |
| 362 Scanner::Location location = scanner()->peek_location(); | 431 ReportMessageAt(scanner()->peek_location(), "unprotected_const"); |
| 363 ReportMessageAt(location.beg_pos, location.end_pos, | |
| 364 "unprotected_const", NULL); | |
| 365 *ok = false; | 432 *ok = false; |
| 366 return Statement::Default(); | 433 return Statement::Default(); |
| 367 } | 434 } |
| 368 require_initializer = true; | 435 require_initializer = true; |
| 369 break; | 436 break; |
| 370 } | 437 } |
| 371 } else if (peek() == Token::LET) { | 438 } else if (peek() == Token::LET) { |
| 372 // ES6 Draft Rev4 section 12.2.1: | 439 // ES6 Draft Rev4 section 12.2.1: |
| 373 // | 440 // |
| 374 // LetDeclaration : let LetBindingList ; | 441 // LetDeclaration : let LetBindingList ; |
| 375 // | 442 // |
| 376 // * It is a Syntax Error if the code that matches this production is not | 443 // * It is a Syntax Error if the code that matches this production is not |
| 377 // contained in extended code. | 444 // contained in extended code. |
| 378 if (!is_extended_mode()) { | 445 if (!is_extended_mode()) { |
| 379 Scanner::Location location = scanner()->peek_location(); | 446 ReportMessageAt(scanner()->peek_location(), "illegal_let"); |
| 380 ReportMessageAt(location.beg_pos, location.end_pos, | |
| 381 "illegal_let", NULL); | |
| 382 *ok = false; | 447 *ok = false; |
| 383 return Statement::Default(); | 448 return Statement::Default(); |
| 384 } | 449 } |
| 385 Consume(Token::LET); | 450 Consume(Token::LET); |
| 386 if (var_context != kSourceElement && | 451 if (var_context != kSourceElement && |
| 387 var_context != kForStatement) { | 452 var_context != kForStatement) { |
| 388 Scanner::Location location = scanner()->peek_location(); | 453 ReportMessageAt(scanner()->peek_location(), "unprotected_let"); |
| 389 ReportMessageAt(location.beg_pos, location.end_pos, | |
| 390 "unprotected_let", NULL); | |
| 391 *ok = false; | 454 *ok = false; |
| 392 return Statement::Default(); | 455 return Statement::Default(); |
| 393 } | 456 } |
| 394 } else { | 457 } else { |
| 395 *ok = false; | 458 *ok = false; |
| 396 return Statement::Default(); | 459 return Statement::Default(); |
| 397 } | 460 } |
| 398 | 461 |
| 399 // The scope of a var/const declared variable anywhere inside a function | 462 // The scope of a var/const declared variable anywhere inside a function |
| 400 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 463 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 ExpectSemicolon(CHECK_OK); | 587 ExpectSemicolon(CHECK_OK); |
| 525 return Statement::Default(); | 588 return Statement::Default(); |
| 526 } | 589 } |
| 527 | 590 |
| 528 | 591 |
| 529 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 592 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
| 530 // WithStatement :: | 593 // WithStatement :: |
| 531 // 'with' '(' Expression ')' Statement | 594 // 'with' '(' Expression ')' Statement |
| 532 Expect(Token::WITH, CHECK_OK); | 595 Expect(Token::WITH, CHECK_OK); |
| 533 if (!scope_->is_classic_mode()) { | 596 if (!scope_->is_classic_mode()) { |
| 534 Scanner::Location location = scanner()->location(); | 597 ReportMessageAt(scanner()->location(), "strict_mode_with"); |
| 535 ReportMessageAt(location, "strict_mode_with", NULL); | |
| 536 *ok = false; | 598 *ok = false; |
| 537 return Statement::Default(); | 599 return Statement::Default(); |
| 538 } | 600 } |
| 539 Expect(Token::LPAREN, CHECK_OK); | 601 Expect(Token::LPAREN, CHECK_OK); |
| 540 ParseExpression(true, CHECK_OK); | 602 ParseExpression(true, CHECK_OK); |
| 541 Expect(Token::RPAREN, CHECK_OK); | 603 Expect(Token::RPAREN, CHECK_OK); |
| 542 | 604 |
| 543 Scope::InsideWith iw(scope_); | 605 Scope::InsideWith iw(scope_); |
| 544 ParseStatement(CHECK_OK); | 606 ParseStatement(CHECK_OK); |
| 545 return Statement::Default(); | 607 return Statement::Default(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 return Statement::Default(); | 731 return Statement::Default(); |
| 670 } | 732 } |
| 671 | 733 |
| 672 | 734 |
| 673 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { | 735 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { |
| 674 // ThrowStatement :: | 736 // ThrowStatement :: |
| 675 // 'throw' [no line terminator] Expression ';' | 737 // 'throw' [no line terminator] Expression ';' |
| 676 | 738 |
| 677 Expect(Token::THROW, CHECK_OK); | 739 Expect(Token::THROW, CHECK_OK); |
| 678 if (scanner()->HasAnyLineTerminatorBeforeNext()) { | 740 if (scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 679 Scanner::Location pos = scanner()->location(); | 741 ReportMessageAt(scanner()->location(), "newline_after_throw"); |
| 680 ReportMessageAt(pos, "newline_after_throw", NULL); | |
| 681 *ok = false; | 742 *ok = false; |
| 682 return Statement::Default(); | 743 return Statement::Default(); |
| 683 } | 744 } |
| 684 ParseExpression(true, CHECK_OK); | 745 ParseExpression(true, CHECK_OK); |
| 685 ExpectSemicolon(ok); | 746 ExpectSemicolon(ok); |
| 686 return Statement::Default(); | 747 return Statement::Default(); |
| 687 } | 748 } |
| 688 | 749 |
| 689 | 750 |
| 690 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { | 751 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
| 691 // TryStatement :: | 752 // TryStatement :: |
| 692 // 'try' Block Catch | 753 // 'try' Block Catch |
| 693 // 'try' Block Finally | 754 // 'try' Block Finally |
| 694 // 'try' Block Catch Finally | 755 // 'try' Block Catch Finally |
| 695 // | 756 // |
| 696 // Catch :: | 757 // Catch :: |
| 697 // 'catch' '(' Identifier ')' Block | 758 // 'catch' '(' Identifier ')' Block |
| 698 // | 759 // |
| 699 // Finally :: | 760 // Finally :: |
| 700 // 'finally' Block | 761 // 'finally' Block |
| 701 | 762 |
| 702 Expect(Token::TRY, CHECK_OK); | 763 Expect(Token::TRY, CHECK_OK); |
| 703 | 764 |
| 704 ParseBlock(CHECK_OK); | 765 ParseBlock(CHECK_OK); |
| 705 | 766 |
| 706 Token::Value tok = peek(); | 767 Token::Value tok = peek(); |
| 707 if (tok != Token::CATCH && tok != Token::FINALLY) { | 768 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 708 ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL); | 769 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); |
| 709 *ok = false; | 770 *ok = false; |
| 710 return Statement::Default(); | 771 return Statement::Default(); |
| 711 } | 772 } |
| 712 if (tok == Token::CATCH) { | 773 if (tok == Token::CATCH) { |
| 713 Consume(Token::CATCH); | 774 Consume(Token::CATCH); |
| 714 Expect(Token::LPAREN, CHECK_OK); | 775 Expect(Token::LPAREN, CHECK_OK); |
| 715 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 776 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
| 716 Expect(Token::RPAREN, CHECK_OK); | 777 Expect(Token::RPAREN, CHECK_OK); |
| 717 { Scope::InsideWith iw(scope_); | 778 { Scope::InsideWith iw(scope_); |
| 718 ParseBlock(CHECK_OK); | 779 ParseBlock(CHECK_OK); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 842 |
| 782 if (!Token::IsAssignmentOp(peek())) { | 843 if (!Token::IsAssignmentOp(peek())) { |
| 783 // Parsed conditional expression only (no assignment). | 844 // Parsed conditional expression only (no assignment). |
| 784 return expression; | 845 return expression; |
| 785 } | 846 } |
| 786 | 847 |
| 787 if (!scope_->is_classic_mode() && | 848 if (!scope_->is_classic_mode() && |
| 788 expression.IsIdentifier() && | 849 expression.IsIdentifier() && |
| 789 expression.AsIdentifier().IsEvalOrArguments()) { | 850 expression.AsIdentifier().IsEvalOrArguments()) { |
| 790 Scanner::Location after = scanner()->location(); | 851 Scanner::Location after = scanner()->location(); |
| 791 ReportMessageAt(before.beg_pos, after.end_pos, | 852 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
| 792 "strict_eval_arguments", NULL); | 853 "strict_eval_arguments", NULL); |
| 793 *ok = false; | 854 *ok = false; |
| 794 return Expression::Default(); | 855 return Expression::Default(); |
| 795 } | 856 } |
| 796 | 857 |
| 797 Token::Value op = Next(); // Get assignment operator. | 858 Token::Value op = Next(); // Get assignment operator. |
| 798 ParseAssignmentExpression(accept_IN, CHECK_OK); | 859 ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 799 | 860 |
| 800 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { | 861 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { |
| 801 scope_->AddProperty(); | 862 scope_->AddProperty(); |
| 802 } | 863 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 ParseUnaryExpression(ok); | 936 ParseUnaryExpression(ok); |
| 876 return Expression::Default(); | 937 return Expression::Default(); |
| 877 } else if (Token::IsCountOp(op)) { | 938 } else if (Token::IsCountOp(op)) { |
| 878 op = Next(); | 939 op = Next(); |
| 879 Scanner::Location before = scanner()->peek_location(); | 940 Scanner::Location before = scanner()->peek_location(); |
| 880 Expression expression = ParseUnaryExpression(CHECK_OK); | 941 Expression expression = ParseUnaryExpression(CHECK_OK); |
| 881 if (!scope_->is_classic_mode() && | 942 if (!scope_->is_classic_mode() && |
| 882 expression.IsIdentifier() && | 943 expression.IsIdentifier() && |
| 883 expression.AsIdentifier().IsEvalOrArguments()) { | 944 expression.AsIdentifier().IsEvalOrArguments()) { |
| 884 Scanner::Location after = scanner()->location(); | 945 Scanner::Location after = scanner()->location(); |
| 885 ReportMessageAt(before.beg_pos, after.end_pos, | 946 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
| 886 "strict_eval_arguments", NULL); | 947 "strict_eval_arguments", NULL); |
| 887 *ok = false; | 948 *ok = false; |
| 888 } | 949 } |
| 889 return Expression::Default(); | 950 return Expression::Default(); |
| 890 } else { | 951 } else { |
| 891 return ParsePostfixExpression(ok); | 952 return ParsePostfixExpression(ok); |
| 892 } | 953 } |
| 893 } | 954 } |
| 894 | 955 |
| 895 | 956 |
| 896 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 957 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
| 897 // PostfixExpression :: | 958 // PostfixExpression :: |
| 898 // LeftHandSideExpression ('++' | '--')? | 959 // LeftHandSideExpression ('++' | '--')? |
| 899 | 960 |
| 900 Scanner::Location before = scanner()->peek_location(); | 961 Scanner::Location before = scanner()->peek_location(); |
| 901 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 962 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
| 902 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 963 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 903 Token::IsCountOp(peek())) { | 964 Token::IsCountOp(peek())) { |
| 904 if (!scope_->is_classic_mode() && | 965 if (!scope_->is_classic_mode() && |
| 905 expression.IsIdentifier() && | 966 expression.IsIdentifier() && |
| 906 expression.AsIdentifier().IsEvalOrArguments()) { | 967 expression.AsIdentifier().IsEvalOrArguments()) { |
| 907 Scanner::Location after = scanner()->location(); | 968 Scanner::Location after = scanner()->location(); |
| 908 ReportMessageAt(before.beg_pos, after.end_pos, | 969 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
| 909 "strict_eval_arguments", NULL); | 970 "strict_eval_arguments", NULL); |
| 910 *ok = false; | 971 *ok = false; |
| 911 return Expression::Default(); | 972 return Expression::Default(); |
| 912 } | 973 } |
| 913 Next(); | 974 Next(); |
| 914 return Expression::Default(); | 975 return Expression::Default(); |
| 915 } | 976 } |
| 916 return expression; | 977 return expression; |
| 917 } | 978 } |
| 918 | 979 |
| 919 | 980 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 // TODO(1240767): Consider allowing trailing comma. | 1299 // TODO(1240767): Consider allowing trailing comma. |
| 1239 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 1300 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
| 1240 } | 1301 } |
| 1241 Expect(Token::RBRACE, CHECK_OK); | 1302 Expect(Token::RBRACE, CHECK_OK); |
| 1242 | 1303 |
| 1243 scope_->NextMaterializedLiteralIndex(); | 1304 scope_->NextMaterializedLiteralIndex(); |
| 1244 return Expression::Default(); | 1305 return Expression::Default(); |
| 1245 } | 1306 } |
| 1246 | 1307 |
| 1247 | 1308 |
| 1248 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, | |
| 1249 bool* ok) { | |
| 1250 if (!scanner()->ScanRegExpPattern(seen_equal)) { | |
| 1251 Next(); | |
| 1252 ReportMessageAt(scanner()->location(), "unterminated_regexp", NULL); | |
| 1253 *ok = false; | |
| 1254 return Expression::Default(); | |
| 1255 } | |
| 1256 | |
| 1257 scope_->NextMaterializedLiteralIndex(); | |
| 1258 | |
| 1259 if (!scanner()->ScanRegExpFlags()) { | |
| 1260 Next(); | |
| 1261 ReportMessageAt(scanner()->location(), "invalid_regexp_flags", NULL); | |
| 1262 *ok = false; | |
| 1263 return Expression::Default(); | |
| 1264 } | |
| 1265 Next(); | |
| 1266 return Expression::Default(); | |
| 1267 } | |
| 1268 | |
| 1269 | |
| 1270 PreParser::Arguments PreParser::ParseArguments(bool* ok) { | 1309 PreParser::Arguments PreParser::ParseArguments(bool* ok) { |
| 1271 // Arguments :: | 1310 // Arguments :: |
| 1272 // '(' (AssignmentExpression)*[','] ')' | 1311 // '(' (AssignmentExpression)*[','] ')' |
| 1273 | 1312 |
| 1274 Expect(Token::LPAREN, ok); | 1313 Expect(Token::LPAREN, ok); |
| 1275 if (!*ok) return -1; | 1314 if (!*ok) return -1; |
| 1276 bool done = (peek() == Token::RPAREN); | 1315 bool done = (peek() == Token::RPAREN); |
| 1277 int argc = 0; | 1316 int argc = 0; |
| 1278 while (!done) { | 1317 while (!done) { |
| 1279 ParseAssignmentExpression(true, ok); | 1318 ParseAssignmentExpression(true, ok); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 ParseLazyFunctionLiteralBody(CHECK_OK); | 1398 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1360 } else { | 1399 } else { |
| 1361 ParseSourceElements(Token::RBRACE, ok); | 1400 ParseSourceElements(Token::RBRACE, ok); |
| 1362 } | 1401 } |
| 1363 Expect(Token::RBRACE, CHECK_OK); | 1402 Expect(Token::RBRACE, CHECK_OK); |
| 1364 | 1403 |
| 1365 // Validate strict mode. We can do this only after parsing the function, | 1404 // Validate strict mode. We can do this only after parsing the function, |
| 1366 // since the function can declare itself strict. | 1405 // since the function can declare itself strict. |
| 1367 if (!scope_->is_classic_mode()) { | 1406 if (!scope_->is_classic_mode()) { |
| 1368 if (function_name.IsEvalOrArguments()) { | 1407 if (function_name.IsEvalOrArguments()) { |
| 1369 ReportMessageAt(function_name_location, "strict_eval_arguments", NULL); | 1408 ReportMessageAt(function_name_location, "strict_eval_arguments"); |
| 1370 *ok = false; | 1409 *ok = false; |
| 1371 return Expression::Default(); | 1410 return Expression::Default(); |
| 1372 } | 1411 } |
| 1373 if (name_is_strict_reserved) { | 1412 if (name_is_strict_reserved) { |
| 1374 ReportMessageAt( | 1413 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); |
| 1375 function_name_location, "unexpected_strict_reserved", NULL); | |
| 1376 *ok = false; | 1414 *ok = false; |
| 1377 return Expression::Default(); | 1415 return Expression::Default(); |
| 1378 } | 1416 } |
| 1379 if (eval_args_error_loc.IsValid()) { | 1417 if (eval_args_error_loc.IsValid()) { |
| 1380 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments", | 1418 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments"); |
| 1381 Vector<const char*>::empty()); | |
| 1382 *ok = false; | 1419 *ok = false; |
| 1383 return Expression::Default(); | 1420 return Expression::Default(); |
| 1384 } | 1421 } |
| 1385 if (dupe_error_loc.IsValid()) { | 1422 if (dupe_error_loc.IsValid()) { |
| 1386 ReportMessageAt(dupe_error_loc, "strict_param_dupe", | 1423 ReportMessageAt(dupe_error_loc, "strict_param_dupe"); |
| 1387 Vector<const char*>::empty()); | |
| 1388 *ok = false; | 1424 *ok = false; |
| 1389 return Expression::Default(); | 1425 return Expression::Default(); |
| 1390 } | 1426 } |
| 1391 if (reserved_error_loc.IsValid()) { | 1427 if (reserved_error_loc.IsValid()) { |
| 1392 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved", | 1428 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved"); |
| 1393 Vector<const char*>::empty()); | |
| 1394 *ok = false; | 1429 *ok = false; |
| 1395 return Expression::Default(); | 1430 return Expression::Default(); |
| 1396 } | 1431 } |
| 1397 | 1432 |
| 1398 int end_position = scanner()->location().end_pos; | 1433 int end_position = scanner()->location().end_pos; |
| 1399 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1434 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
| 1400 return Expression::StrictFunction(); | 1435 return Expression::StrictFunction(); |
| 1401 } | 1436 } |
| 1402 | 1437 |
| 1403 return Expression::Default(); | 1438 return Expression::Default(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 scanner()->literal_length() == kUseStrictLength && | 1492 scanner()->literal_length() == kUseStrictLength && |
| 1458 !scanner()->literal_contains_escapes() && | 1493 !scanner()->literal_contains_escapes() && |
| 1459 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, | 1494 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, |
| 1460 kUseStrictLength)) { | 1495 kUseStrictLength)) { |
| 1461 return Expression::UseStrictStringLiteral(); | 1496 return Expression::UseStrictStringLiteral(); |
| 1462 } | 1497 } |
| 1463 return Expression::StringLiteral(); | 1498 return Expression::StringLiteral(); |
| 1464 } | 1499 } |
| 1465 | 1500 |
| 1466 | 1501 |
| 1467 PreParser::Identifier PreParser::GetIdentifierSymbol() { | |
| 1468 LogSymbol(); | |
| 1469 if (scanner()->current_token() == Token::FUTURE_RESERVED_WORD) { | |
| 1470 return Identifier::FutureReserved(); | |
| 1471 } else if (scanner()->current_token() == | |
| 1472 Token::FUTURE_STRICT_RESERVED_WORD) { | |
| 1473 return Identifier::FutureStrictReserved(); | |
| 1474 } else if (scanner()->current_token() == Token::YIELD) { | |
| 1475 return Identifier::Yield(); | |
| 1476 } | |
| 1477 if (scanner()->is_literal_ascii()) { | |
| 1478 // Detect strict-mode poison words. | |
| 1479 if (scanner()->literal_length() == 4 && | |
| 1480 !strncmp(scanner()->literal_ascii_string().start(), "eval", 4)) { | |
| 1481 return Identifier::Eval(); | |
| 1482 } | |
| 1483 if (scanner()->literal_length() == 9 && | |
| 1484 !strncmp(scanner()->literal_ascii_string().start(), "arguments", 9)) { | |
| 1485 return Identifier::Arguments(); | |
| 1486 } | |
| 1487 } | |
| 1488 return Identifier::Default(); | |
| 1489 } | |
| 1490 | |
| 1491 | |
| 1492 // Parses an identifier that is valid for the current scope, in particular it | |
| 1493 // fails on strict mode future reserved keywords in a strict scope. If | |
| 1494 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | |
| 1495 // "arguments" as identifier even in strict mode (this is needed in cases like | |
| 1496 // "var foo = eval;"). | |
| 1497 PreParser::Identifier PreParser::ParseIdentifier( | |
| 1498 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | |
| 1499 bool* ok) { | |
| 1500 Token::Value next = Next(); | |
| 1501 if (next == Token::IDENTIFIER) { | |
| 1502 PreParser::Identifier name = GetIdentifierSymbol(); | |
| 1503 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && | |
| 1504 !scope_->is_classic_mode() && name.IsEvalOrArguments()) { | |
| 1505 ReportMessageAt(scanner()->location(), "strict_eval_arguments", NULL); | |
| 1506 *ok = false; | |
| 1507 } | |
| 1508 return name; | |
| 1509 } else if (scope_->is_classic_mode() && | |
| 1510 (next == Token::FUTURE_STRICT_RESERVED_WORD || | |
| 1511 (next == Token::YIELD && !scope_->is_generator()))) { | |
| 1512 return GetIdentifierSymbol(); | |
| 1513 } else { | |
| 1514 ReportUnexpectedToken(next); | |
| 1515 *ok = false; | |
| 1516 return Identifier::Default(); | |
| 1517 } | |
| 1518 } | |
| 1519 | |
| 1520 | |
| 1521 // Parses and identifier or a strict mode future reserved word, and indicate | |
| 1522 // whether it is strict mode future reserved. | |
| 1523 PreParser::Identifier PreParser::ParseIdentifierOrStrictReservedWord( | |
| 1524 bool* is_strict_reserved, bool* ok) { | |
| 1525 Token::Value next = Next(); | |
| 1526 if (next == Token::IDENTIFIER) { | |
| 1527 *is_strict_reserved = false; | |
| 1528 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || | |
| 1529 (next == Token::YIELD && !scope_->is_generator())) { | |
| 1530 *is_strict_reserved = true; | |
| 1531 } else { | |
| 1532 ReportUnexpectedToken(next); | |
| 1533 *ok = false; | |
| 1534 return Identifier::Default(); | |
| 1535 } | |
| 1536 return GetIdentifierSymbol(); | |
| 1537 } | |
| 1538 | |
| 1539 | |
| 1540 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { | |
| 1541 Token::Value next = Next(); | |
| 1542 if (next != Token::IDENTIFIER && | |
| 1543 next != Token::FUTURE_RESERVED_WORD && | |
| 1544 next != Token::FUTURE_STRICT_RESERVED_WORD && | |
| 1545 !Token::IsKeyword(next)) { | |
| 1546 ReportUnexpectedToken(next); | |
| 1547 *ok = false; | |
| 1548 return Identifier::Default(); | |
| 1549 } | |
| 1550 return GetIdentifierSymbol(); | |
| 1551 } | |
| 1552 | |
| 1553 #undef CHECK_OK | |
| 1554 | |
| 1555 | |
| 1556 // This function reads an identifier and determines whether or not it | |
| 1557 // is 'get' or 'set'. | |
| 1558 PreParser::Identifier PreParser::ParseIdentifierNameOrGetOrSet(bool* is_get, | |
| 1559 bool* is_set, | |
| 1560 bool* ok) { | |
| 1561 Identifier result = ParseIdentifierName(ok); | |
| 1562 if (!*ok) return Identifier::Default(); | |
| 1563 if (scanner()->is_literal_ascii() && | |
| 1564 scanner()->literal_length() == 3) { | |
| 1565 const char* token = scanner()->literal_ascii_string().start(); | |
| 1566 *is_get = strncmp(token, "get", 3) == 0; | |
| 1567 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | |
| 1568 } | |
| 1569 return result; | |
| 1570 } | |
| 1571 | |
| 1572 | |
| 1573 void PreParser::ObjectLiteralChecker::CheckProperty(Token::Value property, | |
| 1574 PropertyKind type, | |
| 1575 bool* ok) { | |
| 1576 int old; | |
| 1577 if (property == Token::NUMBER) { | |
| 1578 old = finder_.AddNumber(scanner()->literal_ascii_string(), type); | |
| 1579 } else if (scanner()->is_literal_ascii()) { | |
| 1580 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type); | |
| 1581 } else { | |
| 1582 old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type); | |
| 1583 } | |
| 1584 PropertyKind old_type = static_cast<PropertyKind>(old); | |
| 1585 if (HasConflict(old_type, type)) { | |
| 1586 if (IsDataDataConflict(old_type, type)) { | |
| 1587 // Both are data properties. | |
| 1588 if (language_mode_ == CLASSIC_MODE) return; | |
| 1589 parser()->ReportMessageAt(scanner()->location(), | |
| 1590 "strict_duplicate_property"); | |
| 1591 } else if (IsDataAccessorConflict(old_type, type)) { | |
| 1592 // Both a data and an accessor property with the same name. | |
| 1593 parser()->ReportMessageAt(scanner()->location(), | |
| 1594 "accessor_data_property"); | |
| 1595 } else { | |
| 1596 ASSERT(IsAccessorAccessorConflict(old_type, type)); | |
| 1597 // Both accessors of the same type. | |
| 1598 parser()->ReportMessageAt(scanner()->location(), | |
| 1599 "accessor_get_set"); | |
| 1600 } | |
| 1601 *ok = false; | |
| 1602 } | |
| 1603 } | |
| 1604 | |
| 1605 } } // v8::internal | 1502 } } // v8::internal |
| OLD | NEW |