Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/scanner-base.cc

Issue 7669017: Revert 8942 "Make scanner not accept invalid unicode escapes in identifiers" (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scanner-base.h ('k') | test/mjsunit/regress/regress-1620.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 // ---------------------------------------------------------------------------- 37 // ----------------------------------------------------------------------------
38 // Scanner 38 // Scanner
39 39
40 Scanner::Scanner(UnicodeCache* unicode_cache) 40 Scanner::Scanner(UnicodeCache* unicode_cache)
41 : unicode_cache_(unicode_cache) { } 41 : unicode_cache_(unicode_cache) { }
42 42
43 43
44 uc32 Scanner::ScanHexNumber(int expected_length) { 44 uc32 Scanner::ScanHexEscape(uc32 c, int length) {
45 ASSERT(expected_length <= 4); // prevent overflow 45 ASSERT(length <= 4); // prevent overflow
46 46
47 uc32 digits[4]; 47 uc32 digits[4];
48 uc32 x = 0; 48 uc32 x = 0;
49 for (int i = 0; i < expected_length; i++) { 49 for (int i = 0; i < length; i++) {
50 digits[i] = c0_; 50 digits[i] = c0_;
51 int d = HexValue(c0_); 51 int d = HexValue(c0_);
52 if (d < 0) { 52 if (d < 0) {
53 // According to ECMA-262, 3rd, 7.8.4, page 18, these hex escapes 53 // According to ECMA-262, 3rd, 7.8.4, page 18, these hex escapes
54 // should be illegal, but other JS VMs just return the 54 // should be illegal, but other JS VMs just return the
55 // non-escaped version of the original character. 55 // non-escaped version of the original character.
56 56
57 // Push back digits that we have advanced past. 57 // Push back digits read, except the last one (in c0_).
58 for (int j = i-1; j >= 0; j--) { 58 for (int j = i-1; j >= 0; j--) {
59 PushBack(digits[j]); 59 PushBack(digits[j]);
60 } 60 }
61 return unibrow::Utf8::kBadChar; 61 // Notice: No handling of error - treat it as "\u"->"u".
62 return c;
62 } 63 }
63 x = x * 16 + d; 64 x = x * 16 + d;
64 Advance(); 65 Advance();
65 } 66 }
66 67
67 return x; 68 return x;
68 } 69 }
69 70
70 71
71 72
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 632
632 switch (c) { 633 switch (c) {
633 case '\'': // fall through 634 case '\'': // fall through
634 case '"' : // fall through 635 case '"' : // fall through
635 case '\\': break; 636 case '\\': break;
636 case 'b' : c = '\b'; break; 637 case 'b' : c = '\b'; break;
637 case 'f' : c = '\f'; break; 638 case 'f' : c = '\f'; break;
638 case 'n' : c = '\n'; break; 639 case 'n' : c = '\n'; break;
639 case 'r' : c = '\r'; break; 640 case 'r' : c = '\r'; break;
640 case 't' : c = '\t'; break; 641 case 't' : c = '\t'; break;
641 case 'u' : { 642 case 'u' : c = ScanHexEscape(c, 4); break;
642 c = ScanHexNumber(4);
643 if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'u';
644 break;
645 }
646 case 'v' : c = '\v'; break; 643 case 'v' : c = '\v'; break;
647 case 'x' : { 644 case 'x' : c = ScanHexEscape(c, 2); break;
648 c = ScanHexNumber(2);
649 if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'x';
650 break;
651 }
652 case '0' : // fall through 645 case '0' : // fall through
653 case '1' : // fall through 646 case '1' : // fall through
654 case '2' : // fall through 647 case '2' : // fall through
655 case '3' : // fall through 648 case '3' : // fall through
656 case '4' : // fall through 649 case '4' : // fall through
657 case '5' : // fall through 650 case '5' : // fall through
658 case '6' : // fall through 651 case '6' : // fall through
659 case '7' : c = ScanOctalEscape(c, 2); break; 652 case '7' : c = ScanOctalEscape(c, 2); break;
660 } 653 }
661 654
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 literal.Complete(); 796 literal.Complete();
804 797
805 return Token::NUMBER; 798 return Token::NUMBER;
806 } 799 }
807 800
808 801
809 uc32 JavaScriptScanner::ScanIdentifierUnicodeEscape() { 802 uc32 JavaScriptScanner::ScanIdentifierUnicodeEscape() {
810 Advance(); 803 Advance();
811 if (c0_ != 'u') return unibrow::Utf8::kBadChar; 804 if (c0_ != 'u') return unibrow::Utf8::kBadChar;
812 Advance(); 805 Advance();
813 uc32 c = ScanHexNumber(4); 806 uc32 c = ScanHexEscape('u', 4);
814 // We do not allow a unicode escape sequence to start another 807 // We do not allow a unicode escape sequence to start another
815 // unicode escape sequence. 808 // unicode escape sequence.
816 if (c == '\\') return unibrow::Utf8::kBadChar; 809 if (c == '\\') return unibrow::Utf8::kBadChar;
817 return c; 810 return c;
818 } 811 }
819 812
820 813
821 // ---------------------------------------------------------------------------- 814 // ----------------------------------------------------------------------------
822 // Keyword Matcher 815 // Keyword Matcher
823 816
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 } 1039 }
1047 AddLiteralCharAdvance(); 1040 AddLiteralCharAdvance();
1048 } 1041 }
1049 literal.Complete(); 1042 literal.Complete();
1050 1043
1051 next_.location.end_pos = source_pos() - 1; 1044 next_.location.end_pos = source_pos() - 1;
1052 return true; 1045 return true;
1053 } 1046 }
1054 1047
1055 } } // namespace v8::internal 1048 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner-base.h ('k') | test/mjsunit/regress/regress-1620.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698