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

Unified Diff: src/scanner.cc

Issue 706263002: Implement ES6 unicode escapes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index ddcd937584d50fc45fa921a25e2a5d21fcf5697e..a48fe8e98e426dbb3a453a9e042a602596dcefbe 100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -71,6 +71,22 @@ uc32 Scanner::ScanHexNumber(int expected_length) {
}
+uc32 Scanner::ScanUnlimitedLengthHexNumber(int max_value) {
+ uc32 x = 0;
+ int d = HexValue(c0_);
+ if (d < 0) {
+ return -1;
+ }
+ while (d >= 0) {
+ x = x * 16 + d;
+ if (x > max_value) return -1;
+ Advance();
+ d = HexValue(c0_);
+ }
+ return x;
+}
+
+
// Ensure that tokens can be stored in a byte.
STATIC_ASSERT(Token::NUM_TOKENS <= 0x100);
@@ -673,6 +689,7 @@ void Scanner::SeekForward(int pos) {
bool Scanner::ScanEscape() {
uc32 c = c0_;
+ uc32 c2 = -1;
Advance();
// Skip escaped newlines.
@@ -694,7 +711,7 @@ bool Scanner::ScanEscape() {
case 'r' : c = '\r'; break;
case 't' : c = '\t'; break;
case 'u' : {
- c = ScanHexNumber(4);
+ c = ScanUnicodeEscape();
if (c < 0) return false;
break;
}
@@ -718,6 +735,9 @@ bool Scanner::ScanEscape() {
// above cases should be illegal, but they are commonly handled as
// non-escaped characters by JS VMs.
AddLiteralChar(c);
+ if (c2 >= 0) {
+ AddLiteralChar(c2);
+ }
return true;
}
@@ -887,6 +907,25 @@ uc32 Scanner::ScanIdentifierUnicodeEscape() {
Advance();
if (c0_ != 'u') return -1;
Advance();
+ return ScanUnicodeEscape();
+}
+
+
+uc32 Scanner::ScanUnicodeEscape() {
+ // Accept both \uxxxx and \u{xxxxxx}. In the latter case, the number of hex
+ // digits between { } is arbitrary. \ and u have already been read.
+ if (c0_ == '{') {
+ Advance();
+ uc32 cp = ScanUnlimitedLengthHexNumber(0x10ffff);
+ if (cp < 0) {
+ return -1;
+ }
+ if (c0_ != '}') {
+ return -1;
+ }
+ Advance();
+ return cp;
+ }
return ScanHexNumber(4);
}
« no previous file with comments | « src/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698