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

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: Lasse's feedback 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (!kIsIdentifierPart.get(buffer->GetNext())) { 57 if (!kIsIdentifierPart.get(buffer->GetNext())) {
58 return false; 58 return false;
59 } 59 }
60 } 60 }
61 return true; 61 return true;
62 } 62 }
63 63
64 // ---------------------------------------------------------------------------- 64 // ----------------------------------------------------------------------------
65 // Scanner 65 // Scanner
66 66
67 Scanner::Scanner() { } 67 Scanner::Scanner()
68 : octal_pos_(-1) { }
Lasse Reichstein 2011/01/24 07:59:37 Make -1 a constant in the Scanner class. Scanner::
Martin Maly 2011/01/24 17:21:24 Done.
68 69
69 70
70 uc32 Scanner::ScanHexEscape(uc32 c, int length) { 71 uc32 Scanner::ScanHexEscape(uc32 c, int length) {
71 ASSERT(length <= 4); // prevent overflow 72 ASSERT(length <= 4); // prevent overflow
72 73
73 uc32 digits[4]; 74 uc32 digits[4];
74 uc32 x = 0; 75 uc32 x = 0;
75 for (int i = 0; i < length; i++) { 76 for (int i = 0; i < length; i++) {
76 digits[i] = c0_; 77 digits[i] = c0_;
77 int d = HexValue(c0_); 78 int d = HexValue(c0_);
(...skipping 13 matching lines...) Expand all
91 Advance(); 92 Advance();
92 } 93 }
93 94
94 return x; 95 return x;
95 } 96 }
96 97
97 98
98 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of 99 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of
99 // ECMA-262. Other JS VMs support them. 100 // ECMA-262. Other JS VMs support them.
100 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { 101 uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
102 octal_pos_ = source_pos() - 1; // Already advanced
101 uc32 x = c - '0'; 103 uc32 x = c - '0';
102 for (int i = 0; i < length; i++) { 104 for (int i = 0; i < length; i++) {
103 int d = c0_ - '0'; 105 int d = c0_ - '0';
104 if (d < 0 || d > 7) break; 106 if (d < 0 || d > 7) break;
105 int nx = x * 8 + d; 107 int nx = x * 8 + d;
106 if (nx >= 256) break; 108 if (nx >= 256) break;
107 x = nx; 109 x = nx;
108 Advance(); 110 Advance();
109 } 111 }
110 return x; 112 return x;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
600 if (c0_ == '8' || c0_ == '9') { 602 if (c0_ == '8' || c0_ == '9') {
601 kind = DECIMAL; 603 kind = DECIMAL;
602 break; 604 break;
603 } 605 }
604 if (c0_ < '0' || '7' < c0_) break; 606 if (c0_ < '0' || '7' < c0_) {
607 // Octal literal finished.
608 octal_pos_ = next_.location.beg_pos;
609 break;
610 }
605 AddLiteralCharAdvance(); 611 AddLiteralCharAdvance();
606 } 612 }
607 } 613 }
608 } 614 }
609 615
610 // Parse decimal digits and allow trailing fractional part. 616 // Parse decimal digits and allow trailing fractional part.
611 if (kind == DECIMAL) { 617 if (kind == DECIMAL) {
612 ScanDecimalDigits(); // optional 618 ScanDecimalDigits(); // optional
613 if (c0_ == '.') { 619 if (c0_ == '.') {
614 AddLiteralCharAdvance(); 620 AddLiteralCharAdvance();
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; 907 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return;
902 break; 908 break;
903 case UNMATCHABLE: 909 case UNMATCHABLE:
904 break; 910 break;
905 } 911 }
906 // On fallthrough, it's a failure. 912 // On fallthrough, it's a failure.
907 state_ = UNMATCHABLE; 913 state_ = UNMATCHABLE;
908 } 914 }
909 915
910 } } // namespace v8::internal 916 } } // 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