| 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 void PreParserTraits::ReportMessageAt(Scanner::Location location, | |
| 69 const char* message, | |
| 70 Vector<const char*> args) { | |
| 71 ReportMessageAt(location.beg_pos, | |
| 72 location.end_pos, | |
| 73 message, | |
| 74 args.length() > 0 ? args[0] : NULL); | |
| 75 } | |
| 76 | |
| 77 | |
| 78 void PreParserTraits::ReportMessageAt(Scanner::Location location, | |
| 79 const char* type, | |
| 80 const char* name_opt) { | |
| 81 pre_parser_->log_ | |
| 82 ->LogMessage(location.beg_pos, location.end_pos, type, name_opt); | |
| 83 } | |
| 84 | |
| 85 | |
| 86 void PreParserTraits::ReportMessageAt(int start_pos, | |
| 87 int end_pos, | |
| 88 const char* type, | |
| 89 const char* name_opt) { | |
| 90 pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt); | |
| 91 } | |
| 92 | |
| 93 | |
| 94 PreParserIdentifier PreParserTraits::GetSymbol() { | |
| 95 Scanner* scanner = pre_parser_->scanner(); | |
| 96 pre_parser_->LogSymbol(); | |
| 97 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { | |
| 98 return PreParserIdentifier::FutureReserved(); | |
| 99 } else if (scanner->current_token() == | |
| 100 Token::FUTURE_STRICT_RESERVED_WORD) { | |
| 101 return PreParserIdentifier::FutureStrictReserved(); | |
| 102 } else if (scanner->current_token() == Token::YIELD) { | |
| 103 return PreParserIdentifier::Yield(); | |
| 104 } | |
| 105 if (scanner->is_literal_ascii()) { | |
| 106 // Detect strict-mode poison words. | |
| 107 if (scanner->literal_length() == 4 && | |
| 108 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) { | |
| 109 return PreParserIdentifier::Eval(); | |
| 110 } | |
| 111 if (scanner->literal_length() == 9 && | |
| 112 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) { | |
| 113 return PreParserIdentifier::Arguments(); | |
| 114 } | |
| 115 } | |
| 116 return PreParserIdentifier::Default(); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 58 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 121 LanguageMode mode, bool is_generator, ParserRecorder* log) { | 59 LanguageMode mode, bool is_generator, ParserRecorder* log) { |
| 122 log_ = log; | 60 log_ = log; |
| 123 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 61 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 124 Scope top_scope(&scope_, kTopLevelScope); | 62 Scope top_scope(&scope_, kTopLevelScope); |
| 125 set_language_mode(mode); | 63 set_language_mode(mode); |
| 126 Scope function_scope(&scope_, kFunctionScope); | 64 Scope function_scope(&scope_, kFunctionScope); |
| 127 function_scope.set_is_generator(is_generator); | 65 function_scope.set_is_generator(is_generator); |
| 128 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); | 66 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
| 129 bool ok = true; | 67 bool ok = true; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return ParseThrowStatement(ok); | 228 return ParseThrowStatement(ok); |
| 291 | 229 |
| 292 case Token::TRY: | 230 case Token::TRY: |
| 293 return ParseTryStatement(ok); | 231 return ParseTryStatement(ok); |
| 294 | 232 |
| 295 case Token::FUNCTION: { | 233 case Token::FUNCTION: { |
| 296 Scanner::Location start_location = scanner()->peek_location(); | 234 Scanner::Location start_location = scanner()->peek_location(); |
| 297 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 235 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
| 298 Scanner::Location end_location = scanner()->location(); | 236 Scanner::Location end_location = scanner()->location(); |
| 299 if (!scope_->is_classic_mode()) { | 237 if (!scope_->is_classic_mode()) { |
| 300 PreParserTraits::ReportMessageAt(start_location.beg_pos, | 238 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 301 end_location.end_pos, | 239 "strict_function", NULL); |
| 302 "strict_function", | |
| 303 NULL); | |
| 304 *ok = false; | 240 *ok = false; |
| 305 return Statement::Default(); | 241 return Statement::Default(); |
| 306 } else { | 242 } else { |
| 307 return statement; | 243 return statement; |
| 308 } | 244 } |
| 309 } | 245 } |
| 310 | 246 |
| 311 case Token::DEBUGGER: | 247 case Token::DEBUGGER: |
| 312 return ParseDebuggerStatement(ok); | 248 return ParseDebuggerStatement(ok); |
| 313 | 249 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // | 345 // |
| 410 // However disallowing const in classic mode will break compatibility with | 346 // However disallowing const in classic mode will break compatibility with |
| 411 // existing pages. Therefore we keep allowing const with the old | 347 // existing pages. Therefore we keep allowing const with the old |
| 412 // non-harmony semantics in classic mode. | 348 // non-harmony semantics in classic mode. |
| 413 Consume(Token::CONST); | 349 Consume(Token::CONST); |
| 414 switch (language_mode()) { | 350 switch (language_mode()) { |
| 415 case CLASSIC_MODE: | 351 case CLASSIC_MODE: |
| 416 break; | 352 break; |
| 417 case STRICT_MODE: { | 353 case STRICT_MODE: { |
| 418 Scanner::Location location = scanner()->peek_location(); | 354 Scanner::Location location = scanner()->peek_location(); |
| 419 ReportMessageAt(location, "strict_const"); | 355 ReportMessageAt(location, "strict_const", NULL); |
| 420 *ok = false; | 356 *ok = false; |
| 421 return Statement::Default(); | 357 return Statement::Default(); |
| 422 } | 358 } |
| 423 case EXTENDED_MODE: | 359 case EXTENDED_MODE: |
| 424 if (var_context != kSourceElement && | 360 if (var_context != kSourceElement && |
| 425 var_context != kForStatement) { | 361 var_context != kForStatement) { |
| 426 ReportMessageAt(scanner()->peek_location(), "unprotected_const"); | 362 Scanner::Location location = scanner()->peek_location(); |
| 363 ReportMessageAt(location.beg_pos, location.end_pos, |
| 364 "unprotected_const", NULL); |
| 427 *ok = false; | 365 *ok = false; |
| 428 return Statement::Default(); | 366 return Statement::Default(); |
| 429 } | 367 } |
| 430 require_initializer = true; | 368 require_initializer = true; |
| 431 break; | 369 break; |
| 432 } | 370 } |
| 433 } else if (peek() == Token::LET) { | 371 } else if (peek() == Token::LET) { |
| 434 // ES6 Draft Rev4 section 12.2.1: | 372 // ES6 Draft Rev4 section 12.2.1: |
| 435 // | 373 // |
| 436 // LetDeclaration : let LetBindingList ; | 374 // LetDeclaration : let LetBindingList ; |
| 437 // | 375 // |
| 438 // * It is a Syntax Error if the code that matches this production is not | 376 // * It is a Syntax Error if the code that matches this production is not |
| 439 // contained in extended code. | 377 // contained in extended code. |
| 440 if (!is_extended_mode()) { | 378 if (!is_extended_mode()) { |
| 441 ReportMessageAt(scanner()->peek_location(), "illegal_let"); | 379 Scanner::Location location = scanner()->peek_location(); |
| 380 ReportMessageAt(location.beg_pos, location.end_pos, |
| 381 "illegal_let", NULL); |
| 442 *ok = false; | 382 *ok = false; |
| 443 return Statement::Default(); | 383 return Statement::Default(); |
| 444 } | 384 } |
| 445 Consume(Token::LET); | 385 Consume(Token::LET); |
| 446 if (var_context != kSourceElement && | 386 if (var_context != kSourceElement && |
| 447 var_context != kForStatement) { | 387 var_context != kForStatement) { |
| 448 ReportMessageAt(scanner()->peek_location(), "unprotected_let"); | 388 Scanner::Location location = scanner()->peek_location(); |
| 389 ReportMessageAt(location.beg_pos, location.end_pos, |
| 390 "unprotected_let", NULL); |
| 449 *ok = false; | 391 *ok = false; |
| 450 return Statement::Default(); | 392 return Statement::Default(); |
| 451 } | 393 } |
| 452 } else { | 394 } else { |
| 453 *ok = false; | 395 *ok = false; |
| 454 return Statement::Default(); | 396 return Statement::Default(); |
| 455 } | 397 } |
| 456 | 398 |
| 457 // The scope of a var/const declared variable anywhere inside a function | 399 // The scope of a var/const declared variable anywhere inside a function |
| 458 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 400 // 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... |
| 582 ExpectSemicolon(CHECK_OK); | 524 ExpectSemicolon(CHECK_OK); |
| 583 return Statement::Default(); | 525 return Statement::Default(); |
| 584 } | 526 } |
| 585 | 527 |
| 586 | 528 |
| 587 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 529 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
| 588 // WithStatement :: | 530 // WithStatement :: |
| 589 // 'with' '(' Expression ')' Statement | 531 // 'with' '(' Expression ')' Statement |
| 590 Expect(Token::WITH, CHECK_OK); | 532 Expect(Token::WITH, CHECK_OK); |
| 591 if (!scope_->is_classic_mode()) { | 533 if (!scope_->is_classic_mode()) { |
| 592 ReportMessageAt(scanner()->location(), "strict_mode_with"); | 534 Scanner::Location location = scanner()->location(); |
| 535 ReportMessageAt(location, "strict_mode_with", NULL); |
| 593 *ok = false; | 536 *ok = false; |
| 594 return Statement::Default(); | 537 return Statement::Default(); |
| 595 } | 538 } |
| 596 Expect(Token::LPAREN, CHECK_OK); | 539 Expect(Token::LPAREN, CHECK_OK); |
| 597 ParseExpression(true, CHECK_OK); | 540 ParseExpression(true, CHECK_OK); |
| 598 Expect(Token::RPAREN, CHECK_OK); | 541 Expect(Token::RPAREN, CHECK_OK); |
| 599 | 542 |
| 600 Scope::InsideWith iw(scope_); | 543 Scope::InsideWith iw(scope_); |
| 601 ParseStatement(CHECK_OK); | 544 ParseStatement(CHECK_OK); |
| 602 return Statement::Default(); | 545 return Statement::Default(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return Statement::Default(); | 669 return Statement::Default(); |
| 727 } | 670 } |
| 728 | 671 |
| 729 | 672 |
| 730 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { | 673 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { |
| 731 // ThrowStatement :: | 674 // ThrowStatement :: |
| 732 // 'throw' [no line terminator] Expression ';' | 675 // 'throw' [no line terminator] Expression ';' |
| 733 | 676 |
| 734 Expect(Token::THROW, CHECK_OK); | 677 Expect(Token::THROW, CHECK_OK); |
| 735 if (scanner()->HasAnyLineTerminatorBeforeNext()) { | 678 if (scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 736 ReportMessageAt(scanner()->location(), "newline_after_throw"); | 679 Scanner::Location pos = scanner()->location(); |
| 680 ReportMessageAt(pos, "newline_after_throw", NULL); |
| 737 *ok = false; | 681 *ok = false; |
| 738 return Statement::Default(); | 682 return Statement::Default(); |
| 739 } | 683 } |
| 740 ParseExpression(true, CHECK_OK); | 684 ParseExpression(true, CHECK_OK); |
| 741 ExpectSemicolon(ok); | 685 ExpectSemicolon(ok); |
| 742 return Statement::Default(); | 686 return Statement::Default(); |
| 743 } | 687 } |
| 744 | 688 |
| 745 | 689 |
| 746 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { | 690 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
| 747 // TryStatement :: | 691 // TryStatement :: |
| 748 // 'try' Block Catch | 692 // 'try' Block Catch |
| 749 // 'try' Block Finally | 693 // 'try' Block Finally |
| 750 // 'try' Block Catch Finally | 694 // 'try' Block Catch Finally |
| 751 // | 695 // |
| 752 // Catch :: | 696 // Catch :: |
| 753 // 'catch' '(' Identifier ')' Block | 697 // 'catch' '(' Identifier ')' Block |
| 754 // | 698 // |
| 755 // Finally :: | 699 // Finally :: |
| 756 // 'finally' Block | 700 // 'finally' Block |
| 757 | 701 |
| 758 Expect(Token::TRY, CHECK_OK); | 702 Expect(Token::TRY, CHECK_OK); |
| 759 | 703 |
| 760 ParseBlock(CHECK_OK); | 704 ParseBlock(CHECK_OK); |
| 761 | 705 |
| 762 Token::Value tok = peek(); | 706 Token::Value tok = peek(); |
| 763 if (tok != Token::CATCH && tok != Token::FINALLY) { | 707 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 764 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); | 708 ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL); |
| 765 *ok = false; | 709 *ok = false; |
| 766 return Statement::Default(); | 710 return Statement::Default(); |
| 767 } | 711 } |
| 768 if (tok == Token::CATCH) { | 712 if (tok == Token::CATCH) { |
| 769 Consume(Token::CATCH); | 713 Consume(Token::CATCH); |
| 770 Expect(Token::LPAREN, CHECK_OK); | 714 Expect(Token::LPAREN, CHECK_OK); |
| 771 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 715 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
| 772 Expect(Token::RPAREN, CHECK_OK); | 716 Expect(Token::RPAREN, CHECK_OK); |
| 773 { Scope::InsideWith iw(scope_); | 717 { Scope::InsideWith iw(scope_); |
| 774 ParseBlock(CHECK_OK); | 718 ParseBlock(CHECK_OK); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 | 781 |
| 838 if (!Token::IsAssignmentOp(peek())) { | 782 if (!Token::IsAssignmentOp(peek())) { |
| 839 // Parsed conditional expression only (no assignment). | 783 // Parsed conditional expression only (no assignment). |
| 840 return expression; | 784 return expression; |
| 841 } | 785 } |
| 842 | 786 |
| 843 if (!scope_->is_classic_mode() && | 787 if (!scope_->is_classic_mode() && |
| 844 expression.IsIdentifier() && | 788 expression.IsIdentifier() && |
| 845 expression.AsIdentifier().IsEvalOrArguments()) { | 789 expression.AsIdentifier().IsEvalOrArguments()) { |
| 846 Scanner::Location after = scanner()->location(); | 790 Scanner::Location after = scanner()->location(); |
| 847 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 791 ReportMessageAt(before.beg_pos, after.end_pos, |
| 848 "strict_eval_arguments", NULL); | 792 "strict_eval_arguments", NULL); |
| 849 *ok = false; | 793 *ok = false; |
| 850 return Expression::Default(); | 794 return Expression::Default(); |
| 851 } | 795 } |
| 852 | 796 |
| 853 Token::Value op = Next(); // Get assignment operator. | 797 Token::Value op = Next(); // Get assignment operator. |
| 854 ParseAssignmentExpression(accept_IN, CHECK_OK); | 798 ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 855 | 799 |
| 856 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { | 800 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { |
| 857 scope_->AddProperty(); | 801 scope_->AddProperty(); |
| 858 } | 802 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 ParseUnaryExpression(ok); | 875 ParseUnaryExpression(ok); |
| 932 return Expression::Default(); | 876 return Expression::Default(); |
| 933 } else if (Token::IsCountOp(op)) { | 877 } else if (Token::IsCountOp(op)) { |
| 934 op = Next(); | 878 op = Next(); |
| 935 Scanner::Location before = scanner()->peek_location(); | 879 Scanner::Location before = scanner()->peek_location(); |
| 936 Expression expression = ParseUnaryExpression(CHECK_OK); | 880 Expression expression = ParseUnaryExpression(CHECK_OK); |
| 937 if (!scope_->is_classic_mode() && | 881 if (!scope_->is_classic_mode() && |
| 938 expression.IsIdentifier() && | 882 expression.IsIdentifier() && |
| 939 expression.AsIdentifier().IsEvalOrArguments()) { | 883 expression.AsIdentifier().IsEvalOrArguments()) { |
| 940 Scanner::Location after = scanner()->location(); | 884 Scanner::Location after = scanner()->location(); |
| 941 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 885 ReportMessageAt(before.beg_pos, after.end_pos, |
| 942 "strict_eval_arguments", NULL); | 886 "strict_eval_arguments", NULL); |
| 943 *ok = false; | 887 *ok = false; |
| 944 } | 888 } |
| 945 return Expression::Default(); | 889 return Expression::Default(); |
| 946 } else { | 890 } else { |
| 947 return ParsePostfixExpression(ok); | 891 return ParsePostfixExpression(ok); |
| 948 } | 892 } |
| 949 } | 893 } |
| 950 | 894 |
| 951 | 895 |
| 952 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 896 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
| 953 // PostfixExpression :: | 897 // PostfixExpression :: |
| 954 // LeftHandSideExpression ('++' | '--')? | 898 // LeftHandSideExpression ('++' | '--')? |
| 955 | 899 |
| 956 Scanner::Location before = scanner()->peek_location(); | 900 Scanner::Location before = scanner()->peek_location(); |
| 957 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 901 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
| 958 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 902 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 959 Token::IsCountOp(peek())) { | 903 Token::IsCountOp(peek())) { |
| 960 if (!scope_->is_classic_mode() && | 904 if (!scope_->is_classic_mode() && |
| 961 expression.IsIdentifier() && | 905 expression.IsIdentifier() && |
| 962 expression.AsIdentifier().IsEvalOrArguments()) { | 906 expression.AsIdentifier().IsEvalOrArguments()) { |
| 963 Scanner::Location after = scanner()->location(); | 907 Scanner::Location after = scanner()->location(); |
| 964 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 908 ReportMessageAt(before.beg_pos, after.end_pos, |
| 965 "strict_eval_arguments", NULL); | 909 "strict_eval_arguments", NULL); |
| 966 *ok = false; | 910 *ok = false; |
| 967 return Expression::Default(); | 911 return Expression::Default(); |
| 968 } | 912 } |
| 969 Next(); | 913 Next(); |
| 970 return Expression::Default(); | 914 return Expression::Default(); |
| 971 } | 915 } |
| 972 return expression; | 916 return expression; |
| 973 } | 917 } |
| 974 | 918 |
| 975 | 919 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 | 1242 |
| 1299 scope_->NextMaterializedLiteralIndex(); | 1243 scope_->NextMaterializedLiteralIndex(); |
| 1300 return Expression::Default(); | 1244 return Expression::Default(); |
| 1301 } | 1245 } |
| 1302 | 1246 |
| 1303 | 1247 |
| 1304 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, | 1248 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, |
| 1305 bool* ok) { | 1249 bool* ok) { |
| 1306 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1250 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
| 1307 Next(); | 1251 Next(); |
| 1308 ReportMessageAt(scanner()->location(), "unterminated_regexp"); | 1252 ReportMessageAt(scanner()->location(), "unterminated_regexp", NULL); |
| 1309 *ok = false; | 1253 *ok = false; |
| 1310 return Expression::Default(); | 1254 return Expression::Default(); |
| 1311 } | 1255 } |
| 1312 | 1256 |
| 1313 scope_->NextMaterializedLiteralIndex(); | 1257 scope_->NextMaterializedLiteralIndex(); |
| 1314 | 1258 |
| 1315 if (!scanner()->ScanRegExpFlags()) { | 1259 if (!scanner()->ScanRegExpFlags()) { |
| 1316 Next(); | 1260 Next(); |
| 1317 ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); | 1261 ReportMessageAt(scanner()->location(), "invalid_regexp_flags", NULL); |
| 1318 *ok = false; | 1262 *ok = false; |
| 1319 return Expression::Default(); | 1263 return Expression::Default(); |
| 1320 } | 1264 } |
| 1321 Next(); | 1265 Next(); |
| 1322 return Expression::Default(); | 1266 return Expression::Default(); |
| 1323 } | 1267 } |
| 1324 | 1268 |
| 1325 | 1269 |
| 1326 PreParser::Arguments PreParser::ParseArguments(bool* ok) { | 1270 PreParser::Arguments PreParser::ParseArguments(bool* ok) { |
| 1327 // Arguments :: | 1271 // Arguments :: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 ParseLazyFunctionLiteralBody(CHECK_OK); | 1359 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1416 } else { | 1360 } else { |
| 1417 ParseSourceElements(Token::RBRACE, ok); | 1361 ParseSourceElements(Token::RBRACE, ok); |
| 1418 } | 1362 } |
| 1419 Expect(Token::RBRACE, CHECK_OK); | 1363 Expect(Token::RBRACE, CHECK_OK); |
| 1420 | 1364 |
| 1421 // Validate strict mode. We can do this only after parsing the function, | 1365 // Validate strict mode. We can do this only after parsing the function, |
| 1422 // since the function can declare itself strict. | 1366 // since the function can declare itself strict. |
| 1423 if (!scope_->is_classic_mode()) { | 1367 if (!scope_->is_classic_mode()) { |
| 1424 if (function_name.IsEvalOrArguments()) { | 1368 if (function_name.IsEvalOrArguments()) { |
| 1425 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 1369 ReportMessageAt(function_name_location, "strict_eval_arguments", NULL); |
| 1426 *ok = false; | 1370 *ok = false; |
| 1427 return Expression::Default(); | 1371 return Expression::Default(); |
| 1428 } | 1372 } |
| 1429 if (name_is_strict_reserved) { | 1373 if (name_is_strict_reserved) { |
| 1430 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); | 1374 ReportMessageAt( |
| 1375 function_name_location, "unexpected_strict_reserved", NULL); |
| 1431 *ok = false; | 1376 *ok = false; |
| 1432 return Expression::Default(); | 1377 return Expression::Default(); |
| 1433 } | 1378 } |
| 1434 if (eval_args_error_loc.IsValid()) { | 1379 if (eval_args_error_loc.IsValid()) { |
| 1435 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments"); | 1380 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments", |
| 1381 Vector<const char*>::empty()); |
| 1436 *ok = false; | 1382 *ok = false; |
| 1437 return Expression::Default(); | 1383 return Expression::Default(); |
| 1438 } | 1384 } |
| 1439 if (dupe_error_loc.IsValid()) { | 1385 if (dupe_error_loc.IsValid()) { |
| 1440 ReportMessageAt(dupe_error_loc, "strict_param_dupe"); | 1386 ReportMessageAt(dupe_error_loc, "strict_param_dupe", |
| 1387 Vector<const char*>::empty()); |
| 1441 *ok = false; | 1388 *ok = false; |
| 1442 return Expression::Default(); | 1389 return Expression::Default(); |
| 1443 } | 1390 } |
| 1444 if (reserved_error_loc.IsValid()) { | 1391 if (reserved_error_loc.IsValid()) { |
| 1445 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved"); | 1392 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved", |
| 1393 Vector<const char*>::empty()); |
| 1446 *ok = false; | 1394 *ok = false; |
| 1447 return Expression::Default(); | 1395 return Expression::Default(); |
| 1448 } | 1396 } |
| 1449 | 1397 |
| 1450 int end_position = scanner()->location().end_pos; | 1398 int end_position = scanner()->location().end_pos; |
| 1451 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1399 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
| 1452 return Expression::StrictFunction(); | 1400 return Expression::StrictFunction(); |
| 1453 } | 1401 } |
| 1454 | 1402 |
| 1455 return Expression::Default(); | 1403 return Expression::Default(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 scanner()->literal_length() == kUseStrictLength && | 1457 scanner()->literal_length() == kUseStrictLength && |
| 1510 !scanner()->literal_contains_escapes() && | 1458 !scanner()->literal_contains_escapes() && |
| 1511 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, | 1459 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, |
| 1512 kUseStrictLength)) { | 1460 kUseStrictLength)) { |
| 1513 return Expression::UseStrictStringLiteral(); | 1461 return Expression::UseStrictStringLiteral(); |
| 1514 } | 1462 } |
| 1515 return Expression::StringLiteral(); | 1463 return Expression::StringLiteral(); |
| 1516 } | 1464 } |
| 1517 | 1465 |
| 1518 | 1466 |
| 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 |
| 1519 } } // v8::internal | 1605 } } // v8::internal |
| OLD | NEW |