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

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

Issue 7663005: Make scanner not accept invalid unicode escapes in identifiers. (Closed) Base URL: https://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::ScanHexEscape(uc32 c, int length) { 44 uc32 Scanner::ScanHexNumber(int expected_length) {
45 ASSERT(length <= 4); // prevent overflow 45 ASSERT(expected_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 < length; i++) { 49 for (int i = 0; i < expected_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 read, except the last one (in c0_). 57 // Push back digits that we have advanced past.
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 // Notice: No handling of error - treat it as "\u"->"u". 61 return unibrow::Utf8::kBadChar;
62 return c;
63 } 62 }
64 x = x * 16 + d; 63 x = x * 16 + d;
65 Advance(); 64 Advance();
66 } 65 }
67 66
68 return x; 67 return x;
69 } 68 }
70 69
71 70
72 71
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 630
632 switch (c) { 631 switch (c) {
633 case '\'': // fall through 632 case '\'': // fall through
634 case '"' : // fall through 633 case '"' : // fall through
635 case '\\': break; 634 case '\\': break;
636 case 'b' : c = '\b'; break; 635 case 'b' : c = '\b'; break;
637 case 'f' : c = '\f'; break; 636 case 'f' : c = '\f'; break;
638 case 'n' : c = '\n'; break; 637 case 'n' : c = '\n'; break;
639 case 'r' : c = '\r'; break; 638 case 'r' : c = '\r'; break;
640 case 't' : c = '\t'; break; 639 case 't' : c = '\t'; break;
641 case 'u' : c = ScanHexEscape(c, 4); break; 640 case 'u' : {
641 c = ScanHexNumber(4);
642 if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'u';
643 break;
644 }
642 case 'v' : c = '\v'; break; 645 case 'v' : c = '\v'; break;
643 case 'x' : c = ScanHexEscape(c, 2); break; 646 case 'x' : {
647 c = ScanHexNumber(2);
648 if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'x';
649 break;
650 }
644 case '0' : // fall through 651 case '0' : // fall through
645 case '1' : // fall through 652 case '1' : // fall through
646 case '2' : // fall through 653 case '2' : // fall through
647 case '3' : // fall through 654 case '3' : // fall through
648 case '4' : // fall through 655 case '4' : // fall through
649 case '5' : // fall through 656 case '5' : // fall through
650 case '6' : // fall through 657 case '6' : // fall through
651 case '7' : c = ScanOctalEscape(c, 2); break; 658 case '7' : c = ScanOctalEscape(c, 2); break;
652 } 659 }
653 660
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 literal.Complete(); 802 literal.Complete();
796 803
797 return Token::NUMBER; 804 return Token::NUMBER;
798 } 805 }
799 806
800 807
801 uc32 JavaScriptScanner::ScanIdentifierUnicodeEscape() { 808 uc32 JavaScriptScanner::ScanIdentifierUnicodeEscape() {
802 Advance(); 809 Advance();
803 if (c0_ != 'u') return unibrow::Utf8::kBadChar; 810 if (c0_ != 'u') return unibrow::Utf8::kBadChar;
804 Advance(); 811 Advance();
805 uc32 c = ScanHexEscape('u', 4); 812 uc32 c = ScanHexNumber(4);
806 // We do not allow a unicode escape sequence to start another 813 // We do not allow a unicode escape sequence to start another
807 // unicode escape sequence. 814 // unicode escape sequence.
808 if (c == '\\') return unibrow::Utf8::kBadChar; 815 if (c == '\\') return unibrow::Utf8::kBadChar;
809 return c; 816 return c;
810 } 817 }
811 818
812 819
813 // ---------------------------------------------------------------------------- 820 // ----------------------------------------------------------------------------
814 // Keyword Matcher 821 // Keyword Matcher
815 822
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1041 }
1035 AddLiteralCharAdvance(); 1042 AddLiteralCharAdvance();
1036 } 1043 }
1037 literal.Complete(); 1044 literal.Complete();
1038 1045
1039 next_.location.end_pos = source_pos() - 1; 1046 next_.location.end_pos = source_pos() - 1;
1040 return true; 1047 return true;
1041 } 1048 }
1042 1049
1043 } } // namespace v8::internal 1050 } } // 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