Chromium Code Reviews| Index: src/parsing/scanner.cc | 
| diff --git a/src/parsing/scanner.cc b/src/parsing/scanner.cc | 
| index a197829b35b69a6ecbe7d9b7521554eeb8c8c8c1..e1019594f5292404ecf52327cc1fd30c0c3f2601 100644 | 
| --- a/src/parsing/scanner.cc | 
| +++ b/src/parsing/scanner.cc | 
| @@ -62,15 +62,19 @@ void Scanner::Initialize(Utf16CharacterStream* source) { | 
| Scan(); | 
| } | 
| - | 
| -template <bool capture_raw> | 
| +template <bool capture_raw, bool unicode> | 
| uc32 Scanner::ScanHexNumber(int expected_length) { | 
| DCHECK(expected_length <= 4); // prevent overflow | 
| + int begin = source_pos() - 2; | 
| uc32 x = 0; | 
| for (int i = 0; i < expected_length; i++) { | 
| int d = HexValue(c0_); | 
| if (d < 0) { | 
| + ReportScannerError(Location(begin, begin + expected_length + 2), | 
| + unicode | 
| + ? MessageTemplate::kInvalidUnicodeEscapeSequence | 
| + : MessageTemplate::kInvalidHexEscapeSequence); | 
| return -1; | 
| } | 
| x = x * 16 + d; | 
| @@ -80,20 +84,21 @@ uc32 Scanner::ScanHexNumber(int expected_length) { | 
| return x; | 
| } | 
| - | 
| template <bool capture_raw> | 
| -uc32 Scanner::ScanUnlimitedLengthHexNumber(int max_value) { | 
| +uc32 Scanner::ScanUnlimitedLengthHexNumber(int max_value, int beg_pos) { | 
| uc32 x = 0; | 
| int d = HexValue(c0_); | 
| - if (d < 0) { | 
| 
 
adamk
2016/03/21 19:44:31
I think you still need this early return...
 
caitp (gmail)
2016/03/21 19:51:23
you're correct, `\u{}` parses successfully with th
 
 | 
| - return -1; | 
| - } | 
| while (d >= 0) { | 
| x = x * 16 + d; | 
| - if (x > max_value) return -1; | 
| + if (x > max_value) { | 
| + ReportScannerError(Location(beg_pos, source_pos() + 1), | 
| + MessageTemplate::kUndefinedUnicodeCodePoint); | 
| + return -1; | 
| + } | 
| Advance<capture_raw>(); | 
| d = HexValue(c0_); | 
| } | 
| + | 
| return x; | 
| } | 
| @@ -856,7 +861,9 @@ Token::Value Scanner::ScanString() { | 
| uc32 c = c0_; | 
| Advance(); | 
| if (c == '\\') { | 
| - if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL; | 
| + if (c0_ < 0 || !ScanEscape<false, false>()) { | 
| + return Token::ILLEGAL; | 
| + } | 
| } else { | 
| AddLiteralChar(c); | 
| } | 
| @@ -888,7 +895,6 @@ Token::Value Scanner::ScanTemplateSpan() { | 
| StartRawLiteral(); | 
| const bool capture_raw = true; | 
| const bool in_template_literal = true; | 
| - | 
| while (true) { | 
| uc32 c = c0_; | 
| Advance<capture_raw>(); | 
| @@ -1108,18 +1114,22 @@ 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_ == '{') { | 
| + int begin = source_pos() - 2; | 
| Advance<capture_raw>(); | 
| - uc32 cp = ScanUnlimitedLengthHexNumber<capture_raw>(0x10ffff); | 
| + uc32 cp = ScanUnlimitedLengthHexNumber<capture_raw>(0x10ffff, begin); | 
| if (cp < 0) { | 
| 
 
adamk
2016/03/21 19:44:31
...and then report an error here, right?
 
caitp (gmail)
2016/03/21 19:51:23
Done.
 
 | 
| return -1; | 
| } | 
| if (c0_ != '}') { | 
| + ReportScannerError(source_pos(), | 
| + MessageTemplate::kInvalidUnicodeEscapeSequence); | 
| return -1; | 
| } | 
| Advance<capture_raw>(); | 
| return cp; | 
| } | 
| - return ScanHexNumber<capture_raw>(4); | 
| + const bool unicode = true; | 
| + return ScanHexNumber<capture_raw, unicode>(4); | 
| } |