| 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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 // This function is only called to seek to the location | 604 // This function is only called to seek to the location |
| 605 // of the end of a function (at the "}" token). It doesn't matter | 605 // of the end of a function (at the "}" token). It doesn't matter |
| 606 // whether there was a line terminator in the part we skip. | 606 // whether there was a line terminator in the part we skip. |
| 607 has_line_terminator_before_next_ = false; | 607 has_line_terminator_before_next_ = false; |
| 608 has_multiline_comment_before_next_ = false; | 608 has_multiline_comment_before_next_ = false; |
| 609 } | 609 } |
| 610 Scan(); | 610 Scan(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 | 613 |
| 614 void Scanner::ScanEscape() { | 614 bool Scanner::ScanEscape() { |
| 615 uc32 c = c0_; | 615 uc32 c = c0_; |
| 616 Advance(); | 616 Advance(); |
| 617 | 617 |
| 618 // Skip escaped newlines. | 618 // Skip escaped newlines. |
| 619 if (unicode_cache_->IsLineTerminator(c)) { | 619 if (unicode_cache_->IsLineTerminator(c)) { |
| 620 // Allow CR+LF newlines in multiline string literals. | 620 // Allow CR+LF newlines in multiline string literals. |
| 621 if (IsCarriageReturn(c) && IsLineFeed(c0_)) Advance(); | 621 if (IsCarriageReturn(c) && IsLineFeed(c0_)) Advance(); |
| 622 // Allow LF+CR newlines in multiline string literals. | 622 // Allow LF+CR newlines in multiline string literals. |
| 623 if (IsLineFeed(c) && IsCarriageReturn(c0_)) Advance(); | 623 if (IsLineFeed(c) && IsCarriageReturn(c0_)) Advance(); |
| 624 return; | 624 return true; |
| 625 } | 625 } |
| 626 | 626 |
| 627 switch (c) { | 627 switch (c) { |
| 628 case '\'': // fall through | 628 case '\'': // fall through |
| 629 case '"' : // fall through | 629 case '"' : // fall through |
| 630 case '\\': break; | 630 case '\\': break; |
| 631 case 'b' : c = '\b'; break; | 631 case 'b' : c = '\b'; break; |
| 632 case 'f' : c = '\f'; break; | 632 case 'f' : c = '\f'; break; |
| 633 case 'n' : c = '\n'; break; | 633 case 'n' : c = '\n'; break; |
| 634 case 'r' : c = '\r'; break; | 634 case 'r' : c = '\r'; break; |
| 635 case 't' : c = '\t'; break; | 635 case 't' : c = '\t'; break; |
| 636 case 'u' : { | 636 case 'u' : { |
| 637 c = ScanHexNumber(4); | 637 c = ScanHexNumber(4); |
| 638 if (c < 0) c = 'u'; | 638 if (c < 0) return false; |
| 639 break; | 639 break; |
| 640 } | 640 } |
| 641 case 'v' : c = '\v'; break; | 641 case 'v' : c = '\v'; break; |
| 642 case 'x' : { | 642 case 'x' : { |
| 643 c = ScanHexNumber(2); | 643 c = ScanHexNumber(2); |
| 644 if (c < 0) c = 'x'; | 644 if (c < 0) return false; |
| 645 break; | 645 break; |
| 646 } | 646 } |
| 647 case '0' : // fall through | 647 case '0' : // fall through |
| 648 case '1' : // fall through | 648 case '1' : // fall through |
| 649 case '2' : // fall through | 649 case '2' : // fall through |
| 650 case '3' : // fall through | 650 case '3' : // fall through |
| 651 case '4' : // fall through | 651 case '4' : // fall through |
| 652 case '5' : // fall through | 652 case '5' : // fall through |
| 653 case '6' : // fall through | 653 case '6' : // fall through |
| 654 case '7' : c = ScanOctalEscape(c, 2); break; | 654 case '7' : c = ScanOctalEscape(c, 2); break; |
| 655 } | 655 } |
| 656 | 656 |
| 657 // According to ECMA-262, 3rd, 7.8.4 (p 18ff) these | 657 // According to ECMA-262, section 7.8.4, characters not covered by the |
| 658 // should be illegal, but they are commonly handled | 658 // above cases should be illegal, but they are commonly handled as |
| 659 // as non-escaped characters by JS VMs. | 659 // non-escaped characters by JS VMs. |
| 660 AddLiteralChar(c); | 660 AddLiteralChar(c); |
| 661 return true; |
| 661 } | 662 } |
| 662 | 663 |
| 663 | 664 |
| 664 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of | 665 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of |
| 665 // ECMA-262. Other JS VMs support them. | 666 // ECMA-262. Other JS VMs support them. |
| 666 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { | 667 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { |
| 667 uc32 x = c - '0'; | 668 uc32 x = c - '0'; |
| 668 int i = 0; | 669 int i = 0; |
| 669 for (; i < length; i++) { | 670 for (; i < length; i++) { |
| 670 int d = c0_ - '0'; | 671 int d = c0_ - '0'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 689 Token::Value Scanner::ScanString() { | 690 Token::Value Scanner::ScanString() { |
| 690 uc32 quote = c0_; | 691 uc32 quote = c0_; |
| 691 Advance(); // consume quote | 692 Advance(); // consume quote |
| 692 | 693 |
| 693 LiteralScope literal(this); | 694 LiteralScope literal(this); |
| 694 while (c0_ != quote && c0_ >= 0 | 695 while (c0_ != quote && c0_ >= 0 |
| 695 && !unicode_cache_->IsLineTerminator(c0_)) { | 696 && !unicode_cache_->IsLineTerminator(c0_)) { |
| 696 uc32 c = c0_; | 697 uc32 c = c0_; |
| 697 Advance(); | 698 Advance(); |
| 698 if (c == '\\') { | 699 if (c == '\\') { |
| 699 if (c0_ < 0) return Token::ILLEGAL; | 700 if (c0_ < 0 || !ScanEscape()) return Token::ILLEGAL; |
| 700 ScanEscape(); | |
| 701 } else { | 701 } else { |
| 702 AddLiteralChar(c); | 702 AddLiteralChar(c); |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 if (c0_ != quote) return Token::ILLEGAL; | 705 if (c0_ != quote) return Token::ILLEGAL; |
| 706 literal.Complete(); | 706 literal.Complete(); |
| 707 | 707 |
| 708 Advance(); // consume quote | 708 Advance(); // consume quote |
| 709 return Token::STRING; | 709 return Token::STRING; |
| 710 } | 710 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 } | 1079 } |
| 1080 } | 1080 } |
| 1081 } | 1081 } |
| 1082 literal.Complete(); | 1082 literal.Complete(); |
| 1083 | 1083 |
| 1084 next_.location.end_pos = source_pos() - 1; | 1084 next_.location.end_pos = source_pos() - 1; |
| 1085 return true; | 1085 return true; |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 } } // namespace v8::internal | 1088 } } // namespace v8::internal |
| OLD | NEW |