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

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

Issue 6248013: Strict mode octal literals. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 11 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/strict-mode.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Advance(); 91 Advance();
92 } 92 }
93 93
94 return x; 94 return x;
95 } 95 }
96 96
97 97
98 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of 98 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of
99 // ECMA-262. Other JS VMs support them. 99 // ECMA-262. Other JS VMs support them.
100 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { 100 uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
101 octal_loc_.beg_pos = source_pos() - 1; // Already advanced
Lasse Reichstein 2011/01/21 11:20:20 It seems like overkill to store both beg and end p
Martin Maly 2011/01/21 23:32:57 Done.
101 uc32 x = c - '0'; 102 uc32 x = c - '0';
102 for (int i = 0; i < length; i++) { 103 for (int i = 0; i < length; i++) {
103 int d = c0_ - '0'; 104 int d = c0_ - '0';
104 if (d < 0 || d > 7) break; 105 if (d < 0 || d > 7) break;
105 int nx = x * 8 + d; 106 int nx = x * 8 + d;
106 if (nx >= 256) break; 107 if (nx >= 256) break;
107 x = nx; 108 x = nx;
108 Advance(); 109 Advance();
109 } 110 }
111 octal_loc_.end_pos = source_pos();
110 return x; 112 return x;
111 } 113 }
112 114
113 115
114 // ---------------------------------------------------------------------------- 116 // ----------------------------------------------------------------------------
115 // JavaScriptScanner 117 // JavaScriptScanner
116 118
117 JavaScriptScanner::JavaScriptScanner() : Scanner() {} 119 JavaScriptScanner::JavaScriptScanner() : Scanner() {}
118 120
119 121
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // we must have at least one hex digit after 'x'/'X' 592 // we must have at least one hex digit after 'x'/'X'
591 return Token::ILLEGAL; 593 return Token::ILLEGAL;
592 } 594 }
593 while (IsHexDigit(c0_)) { 595 while (IsHexDigit(c0_)) {
594 AddLiteralCharAdvance(); 596 AddLiteralCharAdvance();
595 } 597 }
596 } else if ('0' <= c0_ && c0_ <= '7') { 598 } else if ('0' <= c0_ && c0_ <= '7') {
597 // (possible) octal number 599 // (possible) octal number
598 kind = OCTAL; 600 kind = OCTAL;
599 while (true) { 601 while (true) {
602 // TODO(mmaly): Do we want to keep the auto-upgrade to decimal?
Lasse Reichstein 2011/01/21 11:20:20 Alas, yes. Unless it turns out that Safari has cha
Martin Maly 2011/01/21 23:32:57 Done.
600 if (c0_ == '8' || c0_ == '9') { 603 if (c0_ == '8' || c0_ == '9') {
601 kind = DECIMAL; 604 kind = DECIMAL;
602 break; 605 break;
603 } 606 }
604 if (c0_ < '0' || '7' < c0_) break; 607 if (c0_ < '0' || '7' < c0_) {
608 // Octal literal finished.
609 octal_loc_.beg_pos = next_.location.beg_pos;
610 octal_loc_.end_pos = source_pos();
611 break;
612 }
605 AddLiteralCharAdvance(); 613 AddLiteralCharAdvance();
606 } 614 }
607 } 615 }
608 } 616 }
609 617
610 // Parse decimal digits and allow trailing fractional part. 618 // Parse decimal digits and allow trailing fractional part.
611 if (kind == DECIMAL) { 619 if (kind == DECIMAL) {
612 ScanDecimalDigits(); // optional 620 ScanDecimalDigits(); // optional
613 if (c0_ == '.') { 621 if (c0_ == '.') {
614 AddLiteralCharAdvance(); 622 AddLiteralCharAdvance();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 732
725 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5, 733 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5,
726 // the scanner should pass uninterpreted bodies to the RegExp 734 // the scanner should pass uninterpreted bodies to the RegExp
727 // constructor. 735 // constructor.
728 LiteralScope literal(this); 736 LiteralScope literal(this);
729 if (seen_equal) 737 if (seen_equal)
730 AddLiteralChar('='); 738 AddLiteralChar('=');
731 739
732 while (c0_ != '/' || in_character_class) { 740 while (c0_ != '/' || in_character_class) {
733 if (ScannerConstants::kIsLineTerminator.get(c0_) || c0_ < 0) return false; 741 if (ScannerConstants::kIsLineTerminator.get(c0_) || c0_ < 0) return false;
734 if (c0_ == '\\') { // Escape sequence. 742 if (c0_ == '\\') { // Escape sequence.
Lasse Reichstein 2011/01/21 11:20:20 We should also add checking of RegExp literals. Th
MarkM 2011/01/21 17:44:49 ES5.1 Chapter 16 Errors states: An implementati
Martin Maly 2011/01/21 23:32:57 I saw the octal parsing code. I propose to do this
Lasse Reichstein 2011/01/24 07:59:37 Even so, we currently don't catch the syntax error
735 AddLiteralCharAdvance(); 743 AddLiteralCharAdvance();
736 if (ScannerConstants::kIsLineTerminator.get(c0_) || c0_ < 0) return false; 744 if (ScannerConstants::kIsLineTerminator.get(c0_) || c0_ < 0) return false;
737 AddLiteralCharAdvance(); 745 AddLiteralCharAdvance();
738 // If the escape allows more characters, i.e., \x??, \u????, or \c?, 746 // If the escape allows more characters, i.e., \x??, \u????, or \c?,
739 // only "safe" characters are allowed (letters, digits, underscore), 747 // only "safe" characters are allowed (letters, digits, underscore),
740 // otherwise the escape isn't valid and the invalid character has 748 // otherwise the escape isn't valid and the invalid character has
741 // its normal meaning. I.e., we can just continue scanning without 749 // its normal meaning. I.e., we can just continue scanning without
742 // worrying whether the following characters are part of the escape 750 // worrying whether the following characters are part of the escape
743 // or not, since any '/', '\\' or '[' is guaranteed to not be part 751 // or not, since any '/', '\\' or '[' is guaranteed to not be part
744 // of the escape sequence. 752 // of the escape sequence.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; 909 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return;
902 break; 910 break;
903 case UNMATCHABLE: 911 case UNMATCHABLE:
904 break; 912 break;
905 } 913 }
906 // On fallthrough, it's a failure. 914 // On fallthrough, it's a failure.
907 state_ = UNMATCHABLE; 915 state_ = UNMATCHABLE;
908 } 916 }
909 917
910 } } // namespace v8::internal 918 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner-base.h ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698