Chromium Code Reviews| Index: src/scanner.cc |
| diff --git a/src/scanner.cc b/src/scanner.cc |
| index ddcd937584d50fc45fa921a25e2a5d21fcf5697e..97aced924d47ba3f188875ec79e7d24fae0bbe7a 100644 |
| --- a/src/scanner.cc |
| +++ b/src/scanner.cc |
| @@ -38,7 +38,8 @@ Scanner::Scanner(UnicodeCache* unicode_cache) |
| harmony_scoping_(false), |
| harmony_modules_(false), |
| harmony_numeric_literals_(false), |
| - harmony_classes_(false) { } |
| + harmony_classes_(false), |
| + harmony_unicode_(false) {} |
| void Scanner::Initialize(Utf16CharacterStream* source) { |
| @@ -71,6 +72,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; |
|
caitp (gmail)
2014/11/13 15:09:18
I don't think this should block landing this, but
rossberg
2014/11/14 09:59:08
Alternatively, we should enable the scanner to giv
|
| + Advance(); |
| + d = HexValue(c0_); |
| + } |
| + return x; |
| +} |
| + |
| + |
| // Ensure that tokens can be stored in a byte. |
| STATIC_ASSERT(Token::NUM_TOKENS <= 0x100); |
| @@ -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; |
| } |
| @@ -887,6 +904,26 @@ uc32 Scanner::ScanIdentifierUnicodeEscape() { |
| Advance(); |
| if (c0_ != 'u') return -1; |
| Advance(); |
| + return ScanUnicodeEscape(); |
| +} |
| + |
| + |
| +uc32 Scanner::ScanUnicodeEscape() { |
| + // Accept both \uxxxx and \u{xxxxxx} (if harmony unicode escapes are |
| + // allowed). In the latter case, the number of hex digits between { } is |
| + // arbitrary. \ and u have already been read. |
| + if (c0_ == '{' && HarmonyUnicode()) { |
| + Advance(); |
| + uc32 cp = ScanUnlimitedLengthHexNumber(0x10ffff); |
| + if (cp < 0) { |
| + return -1; |
| + } |
| + if (c0_ != '}') { |
| + return -1; |
| + } |
| + Advance(); |
| + return cp; |
| + } |
| return ScanHexNumber(4); |
| } |