| 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 |
| 58 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 120 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 59 LanguageMode mode, bool is_generator, ParserRecorder* log) { | 121 LanguageMode mode, bool is_generator, ParserRecorder* log) { |
| 60 log_ = log; | 122 log_ = log; |
| 61 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 123 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 62 Scope top_scope(&scope_, kTopLevelScope); | 124 Scope top_scope(&scope_, kTopLevelScope); |
| 63 set_language_mode(mode); | 125 set_language_mode(mode); |
| 64 Scope function_scope(&scope_, kFunctionScope); | 126 Scope function_scope(&scope_, kFunctionScope); |
| 65 function_scope.set_is_generator(is_generator); | 127 function_scope.set_is_generator(is_generator); |
| 66 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); | 128 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
| 67 bool ok = true; | 129 bool ok = true; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return ParseThrowStatement(ok); | 290 return ParseThrowStatement(ok); |
| 229 | 291 |
| 230 case Token::TRY: | 292 case Token::TRY: |
| 231 return ParseTryStatement(ok); | 293 return ParseTryStatement(ok); |
| 232 | 294 |
| 233 case Token::FUNCTION: { | 295 case Token::FUNCTION: { |
| 234 Scanner::Location start_location = scanner()->peek_location(); | 296 Scanner::Location start_location = scanner()->peek_location(); |
| 235 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 297 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
| 236 Scanner::Location end_location = scanner()->location(); | 298 Scanner::Location end_location = scanner()->location(); |
| 237 if (!scope_->is_classic_mode()) { | 299 if (!scope_->is_classic_mode()) { |
| 238 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | 300 traits_->ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 239 "strict_function", NULL); | 301 "strict_function", NULL); |
| 240 *ok = false; | 302 *ok = false; |
| 241 return Statement::Default(); | 303 return Statement::Default(); |
| 242 } else { | 304 } else { |
| 243 return statement; | 305 return statement; |
| 244 } | 306 } |
| 245 } | 307 } |
| 246 | 308 |
| 247 case Token::DEBUGGER: | 309 case Token::DEBUGGER: |
| 248 return ParseDebuggerStatement(ok); | 310 return ParseDebuggerStatement(ok); |
| 249 | 311 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // | 407 // |
| 346 // However disallowing const in classic mode will break compatibility with | 408 // However disallowing const in classic mode will break compatibility with |
| 347 // existing pages. Therefore we keep allowing const with the old | 409 // existing pages. Therefore we keep allowing const with the old |
| 348 // non-harmony semantics in classic mode. | 410 // non-harmony semantics in classic mode. |
| 349 Consume(Token::CONST); | 411 Consume(Token::CONST); |
| 350 switch (language_mode()) { | 412 switch (language_mode()) { |
| 351 case CLASSIC_MODE: | 413 case CLASSIC_MODE: |
| 352 break; | 414 break; |
| 353 case STRICT_MODE: { | 415 case STRICT_MODE: { |
| 354 Scanner::Location location = scanner()->peek_location(); | 416 Scanner::Location location = scanner()->peek_location(); |
| 355 ReportMessageAt(location, "strict_const", NULL); | 417 traits_->ReportMessageAt(location, "strict_const", NULL); |
| 356 *ok = false; | 418 *ok = false; |
| 357 return Statement::Default(); | 419 return Statement::Default(); |
| 358 } | 420 } |
| 359 case EXTENDED_MODE: | 421 case EXTENDED_MODE: |
| 360 if (var_context != kSourceElement && | 422 if (var_context != kSourceElement && |
| 361 var_context != kForStatement) { | 423 var_context != kForStatement) { |
| 362 Scanner::Location location = scanner()->peek_location(); | 424 Scanner::Location location = scanner()->peek_location(); |
| 363 ReportMessageAt(location.beg_pos, location.end_pos, | 425 traits_->ReportMessageAt(location.beg_pos, location.end_pos, |
| 364 "unprotected_const", NULL); | 426 "unprotected_const", NULL); |
| 365 *ok = false; | 427 *ok = false; |
| 366 return Statement::Default(); | 428 return Statement::Default(); |
| 367 } | 429 } |
| 368 require_initializer = true; | 430 require_initializer = true; |
| 369 break; | 431 break; |
| 370 } | 432 } |
| 371 } else if (peek() == Token::LET) { | 433 } else if (peek() == Token::LET) { |
| 372 // ES6 Draft Rev4 section 12.2.1: | 434 // ES6 Draft Rev4 section 12.2.1: |
| 373 // | 435 // |
| 374 // LetDeclaration : let LetBindingList ; | 436 // LetDeclaration : let LetBindingList ; |
| 375 // | 437 // |
| 376 // * It is a Syntax Error if the code that matches this production is not | 438 // * It is a Syntax Error if the code that matches this production is not |
| 377 // contained in extended code. | 439 // contained in extended code. |
| 378 if (!is_extended_mode()) { | 440 if (!is_extended_mode()) { |
| 379 Scanner::Location location = scanner()->peek_location(); | 441 Scanner::Location location = scanner()->peek_location(); |
| 380 ReportMessageAt(location.beg_pos, location.end_pos, | 442 traits_->ReportMessageAt(location.beg_pos, location.end_pos, |
| 381 "illegal_let", NULL); | 443 "illegal_let", NULL); |
| 382 *ok = false; | 444 *ok = false; |
| 383 return Statement::Default(); | 445 return Statement::Default(); |
| 384 } | 446 } |
| 385 Consume(Token::LET); | 447 Consume(Token::LET); |
| 386 if (var_context != kSourceElement && | 448 if (var_context != kSourceElement && |
| 387 var_context != kForStatement) { | 449 var_context != kForStatement) { |
| 388 Scanner::Location location = scanner()->peek_location(); | 450 Scanner::Location location = scanner()->peek_location(); |
| 389 ReportMessageAt(location.beg_pos, location.end_pos, | 451 traits_->ReportMessageAt(location.beg_pos, location.end_pos, |
| 390 "unprotected_let", NULL); | 452 "unprotected_let", NULL); |
| 391 *ok = false; | 453 *ok = false; |
| 392 return Statement::Default(); | 454 return Statement::Default(); |
| 393 } | 455 } |
| 394 } else { | 456 } else { |
| 395 *ok = false; | 457 *ok = false; |
| 396 return Statement::Default(); | 458 return Statement::Default(); |
| 397 } | 459 } |
| 398 | 460 |
| 399 // The scope of a var/const declared variable anywhere inside a function | 461 // 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 | 462 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 return Statement::Default(); | 587 return Statement::Default(); |
| 526 } | 588 } |
| 527 | 589 |
| 528 | 590 |
| 529 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 591 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
| 530 // WithStatement :: | 592 // WithStatement :: |
| 531 // 'with' '(' Expression ')' Statement | 593 // 'with' '(' Expression ')' Statement |
| 532 Expect(Token::WITH, CHECK_OK); | 594 Expect(Token::WITH, CHECK_OK); |
| 533 if (!scope_->is_classic_mode()) { | 595 if (!scope_->is_classic_mode()) { |
| 534 Scanner::Location location = scanner()->location(); | 596 Scanner::Location location = scanner()->location(); |
| 535 ReportMessageAt(location, "strict_mode_with", NULL); | 597 traits_->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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Scanner::Location pos = scanner()->location(); |
| 680 ReportMessageAt(pos, "newline_after_throw", NULL); | 742 traits_->ReportMessageAt(pos, "newline_after_throw", NULL); |
| 681 *ok = false; | 743 *ok = false; |
| 682 return Statement::Default(); | 744 return Statement::Default(); |
| 683 } | 745 } |
| 684 ParseExpression(true, CHECK_OK); | 746 ParseExpression(true, CHECK_OK); |
| 685 ExpectSemicolon(ok); | 747 ExpectSemicolon(ok); |
| 686 return Statement::Default(); | 748 return Statement::Default(); |
| 687 } | 749 } |
| 688 | 750 |
| 689 | 751 |
| 690 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { | 752 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
| 691 // TryStatement :: | 753 // TryStatement :: |
| 692 // 'try' Block Catch | 754 // 'try' Block Catch |
| 693 // 'try' Block Finally | 755 // 'try' Block Finally |
| 694 // 'try' Block Catch Finally | 756 // 'try' Block Catch Finally |
| 695 // | 757 // |
| 696 // Catch :: | 758 // Catch :: |
| 697 // 'catch' '(' Identifier ')' Block | 759 // 'catch' '(' Identifier ')' Block |
| 698 // | 760 // |
| 699 // Finally :: | 761 // Finally :: |
| 700 // 'finally' Block | 762 // 'finally' Block |
| 701 | 763 |
| 702 Expect(Token::TRY, CHECK_OK); | 764 Expect(Token::TRY, CHECK_OK); |
| 703 | 765 |
| 704 ParseBlock(CHECK_OK); | 766 ParseBlock(CHECK_OK); |
| 705 | 767 |
| 706 Token::Value tok = peek(); | 768 Token::Value tok = peek(); |
| 707 if (tok != Token::CATCH && tok != Token::FINALLY) { | 769 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 708 ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL); | 770 traits_->ReportMessageAt( |
| 771 scanner()->location(), "no_catch_or_finally", NULL); |
| 709 *ok = false; | 772 *ok = false; |
| 710 return Statement::Default(); | 773 return Statement::Default(); |
| 711 } | 774 } |
| 712 if (tok == Token::CATCH) { | 775 if (tok == Token::CATCH) { |
| 713 Consume(Token::CATCH); | 776 Consume(Token::CATCH); |
| 714 Expect(Token::LPAREN, CHECK_OK); | 777 Expect(Token::LPAREN, CHECK_OK); |
| 715 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 778 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
| 716 Expect(Token::RPAREN, CHECK_OK); | 779 Expect(Token::RPAREN, CHECK_OK); |
| 717 { Scope::InsideWith iw(scope_); | 780 { Scope::InsideWith iw(scope_); |
| 718 ParseBlock(CHECK_OK); | 781 ParseBlock(CHECK_OK); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 844 |
| 782 if (!Token::IsAssignmentOp(peek())) { | 845 if (!Token::IsAssignmentOp(peek())) { |
| 783 // Parsed conditional expression only (no assignment). | 846 // Parsed conditional expression only (no assignment). |
| 784 return expression; | 847 return expression; |
| 785 } | 848 } |
| 786 | 849 |
| 787 if (!scope_->is_classic_mode() && | 850 if (!scope_->is_classic_mode() && |
| 788 expression.IsIdentifier() && | 851 expression.IsIdentifier() && |
| 789 expression.AsIdentifier().IsEvalOrArguments()) { | 852 expression.AsIdentifier().IsEvalOrArguments()) { |
| 790 Scanner::Location after = scanner()->location(); | 853 Scanner::Location after = scanner()->location(); |
| 791 ReportMessageAt(before.beg_pos, after.end_pos, | 854 traits_->ReportMessageAt(before.beg_pos, after.end_pos, |
| 792 "strict_eval_arguments", NULL); | 855 "strict_eval_arguments", NULL); |
| 793 *ok = false; | 856 *ok = false; |
| 794 return Expression::Default(); | 857 return Expression::Default(); |
| 795 } | 858 } |
| 796 | 859 |
| 797 Token::Value op = Next(); // Get assignment operator. | 860 Token::Value op = Next(); // Get assignment operator. |
| 798 ParseAssignmentExpression(accept_IN, CHECK_OK); | 861 ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 799 | 862 |
| 800 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { | 863 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { |
| 801 scope_->AddProperty(); | 864 scope_->AddProperty(); |
| 802 } | 865 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 ParseUnaryExpression(ok); | 938 ParseUnaryExpression(ok); |
| 876 return Expression::Default(); | 939 return Expression::Default(); |
| 877 } else if (Token::IsCountOp(op)) { | 940 } else if (Token::IsCountOp(op)) { |
| 878 op = Next(); | 941 op = Next(); |
| 879 Scanner::Location before = scanner()->peek_location(); | 942 Scanner::Location before = scanner()->peek_location(); |
| 880 Expression expression = ParseUnaryExpression(CHECK_OK); | 943 Expression expression = ParseUnaryExpression(CHECK_OK); |
| 881 if (!scope_->is_classic_mode() && | 944 if (!scope_->is_classic_mode() && |
| 882 expression.IsIdentifier() && | 945 expression.IsIdentifier() && |
| 883 expression.AsIdentifier().IsEvalOrArguments()) { | 946 expression.AsIdentifier().IsEvalOrArguments()) { |
| 884 Scanner::Location after = scanner()->location(); | 947 Scanner::Location after = scanner()->location(); |
| 885 ReportMessageAt(before.beg_pos, after.end_pos, | 948 traits_->ReportMessageAt(before.beg_pos, after.end_pos, |
| 886 "strict_eval_arguments", NULL); | 949 "strict_eval_arguments", NULL); |
| 887 *ok = false; | 950 *ok = false; |
| 888 } | 951 } |
| 889 return Expression::Default(); | 952 return Expression::Default(); |
| 890 } else { | 953 } else { |
| 891 return ParsePostfixExpression(ok); | 954 return ParsePostfixExpression(ok); |
| 892 } | 955 } |
| 893 } | 956 } |
| 894 | 957 |
| 895 | 958 |
| 896 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 959 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
| 897 // PostfixExpression :: | 960 // PostfixExpression :: |
| 898 // LeftHandSideExpression ('++' | '--')? | 961 // LeftHandSideExpression ('++' | '--')? |
| 899 | 962 |
| 900 Scanner::Location before = scanner()->peek_location(); | 963 Scanner::Location before = scanner()->peek_location(); |
| 901 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 964 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
| 902 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 965 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 903 Token::IsCountOp(peek())) { | 966 Token::IsCountOp(peek())) { |
| 904 if (!scope_->is_classic_mode() && | 967 if (!scope_->is_classic_mode() && |
| 905 expression.IsIdentifier() && | 968 expression.IsIdentifier() && |
| 906 expression.AsIdentifier().IsEvalOrArguments()) { | 969 expression.AsIdentifier().IsEvalOrArguments()) { |
| 907 Scanner::Location after = scanner()->location(); | 970 Scanner::Location after = scanner()->location(); |
| 908 ReportMessageAt(before.beg_pos, after.end_pos, | 971 traits_->ReportMessageAt(before.beg_pos, after.end_pos, |
| 909 "strict_eval_arguments", NULL); | 972 "strict_eval_arguments", NULL); |
| 910 *ok = false; | 973 *ok = false; |
| 911 return Expression::Default(); | 974 return Expression::Default(); |
| 912 } | 975 } |
| 913 Next(); | 976 Next(); |
| 914 return Expression::Default(); | 977 return Expression::Default(); |
| 915 } | 978 } |
| 916 return expression; | 979 return expression; |
| 917 } | 980 } |
| 918 | 981 |
| 919 | 982 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 | 1305 |
| 1243 scope_->NextMaterializedLiteralIndex(); | 1306 scope_->NextMaterializedLiteralIndex(); |
| 1244 return Expression::Default(); | 1307 return Expression::Default(); |
| 1245 } | 1308 } |
| 1246 | 1309 |
| 1247 | 1310 |
| 1248 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, | 1311 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, |
| 1249 bool* ok) { | 1312 bool* ok) { |
| 1250 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1313 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
| 1251 Next(); | 1314 Next(); |
| 1252 ReportMessageAt(scanner()->location(), "unterminated_regexp", NULL); | 1315 traits_->ReportMessageAt( |
| 1316 scanner()->location(), "unterminated_regexp", NULL); |
| 1253 *ok = false; | 1317 *ok = false; |
| 1254 return Expression::Default(); | 1318 return Expression::Default(); |
| 1255 } | 1319 } |
| 1256 | 1320 |
| 1257 scope_->NextMaterializedLiteralIndex(); | 1321 scope_->NextMaterializedLiteralIndex(); |
| 1258 | 1322 |
| 1259 if (!scanner()->ScanRegExpFlags()) { | 1323 if (!scanner()->ScanRegExpFlags()) { |
| 1260 Next(); | 1324 Next(); |
| 1261 ReportMessageAt(scanner()->location(), "invalid_regexp_flags", NULL); | 1325 traits_->ReportMessageAt( |
| 1326 scanner()->location(), "invalid_regexp_flags", NULL); |
| 1262 *ok = false; | 1327 *ok = false; |
| 1263 return Expression::Default(); | 1328 return Expression::Default(); |
| 1264 } | 1329 } |
| 1265 Next(); | 1330 Next(); |
| 1266 return Expression::Default(); | 1331 return Expression::Default(); |
| 1267 } | 1332 } |
| 1268 | 1333 |
| 1269 | 1334 |
| 1270 PreParser::Arguments PreParser::ParseArguments(bool* ok) { | 1335 PreParser::Arguments PreParser::ParseArguments(bool* ok) { |
| 1271 // Arguments :: | 1336 // Arguments :: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 ParseLazyFunctionLiteralBody(CHECK_OK); | 1424 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1360 } else { | 1425 } else { |
| 1361 ParseSourceElements(Token::RBRACE, ok); | 1426 ParseSourceElements(Token::RBRACE, ok); |
| 1362 } | 1427 } |
| 1363 Expect(Token::RBRACE, CHECK_OK); | 1428 Expect(Token::RBRACE, CHECK_OK); |
| 1364 | 1429 |
| 1365 // Validate strict mode. We can do this only after parsing the function, | 1430 // Validate strict mode. We can do this only after parsing the function, |
| 1366 // since the function can declare itself strict. | 1431 // since the function can declare itself strict. |
| 1367 if (!scope_->is_classic_mode()) { | 1432 if (!scope_->is_classic_mode()) { |
| 1368 if (function_name.IsEvalOrArguments()) { | 1433 if (function_name.IsEvalOrArguments()) { |
| 1369 ReportMessageAt(function_name_location, "strict_eval_arguments", NULL); | 1434 traits_->ReportMessageAt( |
| 1435 function_name_location, "strict_eval_arguments", NULL); |
| 1370 *ok = false; | 1436 *ok = false; |
| 1371 return Expression::Default(); | 1437 return Expression::Default(); |
| 1372 } | 1438 } |
| 1373 if (name_is_strict_reserved) { | 1439 if (name_is_strict_reserved) { |
| 1374 ReportMessageAt( | 1440 traits_->ReportMessageAt( |
| 1375 function_name_location, "unexpected_strict_reserved", NULL); | 1441 function_name_location, "unexpected_strict_reserved", NULL); |
| 1376 *ok = false; | 1442 *ok = false; |
| 1377 return Expression::Default(); | 1443 return Expression::Default(); |
| 1378 } | 1444 } |
| 1379 if (eval_args_error_loc.IsValid()) { | 1445 if (eval_args_error_loc.IsValid()) { |
| 1380 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments", | 1446 traits_->ReportMessageAt(eval_args_error_loc, "strict_eval_arguments", |
| 1381 Vector<const char*>::empty()); | 1447 Vector<const char*>::empty()); |
| 1382 *ok = false; | 1448 *ok = false; |
| 1383 return Expression::Default(); | 1449 return Expression::Default(); |
| 1384 } | 1450 } |
| 1385 if (dupe_error_loc.IsValid()) { | 1451 if (dupe_error_loc.IsValid()) { |
| 1386 ReportMessageAt(dupe_error_loc, "strict_param_dupe", | 1452 traits_->ReportMessageAt(dupe_error_loc, "strict_param_dupe", |
| 1387 Vector<const char*>::empty()); | 1453 Vector<const char*>::empty()); |
| 1388 *ok = false; | 1454 *ok = false; |
| 1389 return Expression::Default(); | 1455 return Expression::Default(); |
| 1390 } | 1456 } |
| 1391 if (reserved_error_loc.IsValid()) { | 1457 if (reserved_error_loc.IsValid()) { |
| 1392 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved", | 1458 traits_->ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved", |
| 1393 Vector<const char*>::empty()); | 1459 Vector<const char*>::empty()); |
| 1394 *ok = false; | 1460 *ok = false; |
| 1395 return Expression::Default(); | 1461 return Expression::Default(); |
| 1396 } | 1462 } |
| 1397 | 1463 |
| 1398 int end_position = scanner()->location().end_pos; | 1464 int end_position = scanner()->location().end_pos; |
| 1399 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1465 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
| 1400 return Expression::StrictFunction(); | 1466 return Expression::StrictFunction(); |
| 1401 } | 1467 } |
| 1402 | 1468 |
| 1403 return Expression::Default(); | 1469 return Expression::Default(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 scanner()->literal_length() == kUseStrictLength && | 1523 scanner()->literal_length() == kUseStrictLength && |
| 1458 !scanner()->literal_contains_escapes() && | 1524 !scanner()->literal_contains_escapes() && |
| 1459 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, | 1525 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, |
| 1460 kUseStrictLength)) { | 1526 kUseStrictLength)) { |
| 1461 return Expression::UseStrictStringLiteral(); | 1527 return Expression::UseStrictStringLiteral(); |
| 1462 } | 1528 } |
| 1463 return Expression::StringLiteral(); | 1529 return Expression::StringLiteral(); |
| 1464 } | 1530 } |
| 1465 | 1531 |
| 1466 | 1532 |
| 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 | 1533 } } // v8::internal |
| OLD | NEW |