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

Unified Diff: src/scanner-base.cc

Issue 7669017: Revert 8942 "Make scanner not accept invalid unicode escapes in identifiers" (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner-base.h ('k') | test/mjsunit/regress/regress-1620.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner-base.cc
===================================================================
--- src/scanner-base.cc (revision 8946)
+++ src/scanner-base.cc (working copy)
@@ -41,12 +41,12 @@
: unicode_cache_(unicode_cache) { }
- uc32 Scanner::ScanHexNumber(int expected_length) {
- ASSERT(expected_length <= 4); // prevent overflow
+uc32 Scanner::ScanHexEscape(uc32 c, int length) {
+ ASSERT(length <= 4); // prevent overflow
uc32 digits[4];
uc32 x = 0;
- for (int i = 0; i < expected_length; i++) {
+ for (int i = 0; i < length; i++) {
digits[i] = c0_;
int d = HexValue(c0_);
if (d < 0) {
@@ -54,11 +54,12 @@
// should be illegal, but other JS VMs just return the
// non-escaped version of the original character.
- // Push back digits that we have advanced past.
+ // Push back digits read, except the last one (in c0_).
for (int j = i-1; j >= 0; j--) {
PushBack(digits[j]);
}
- return unibrow::Utf8::kBadChar;
+ // Notice: No handling of error - treat it as "\u"->"u".
+ return c;
}
x = x * 16 + d;
Advance();
@@ -638,17 +639,9 @@
case 'n' : c = '\n'; break;
case 'r' : c = '\r'; break;
case 't' : c = '\t'; break;
- case 'u' : {
- c = ScanHexNumber(4);
- if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'u';
- break;
- }
+ case 'u' : c = ScanHexEscape(c, 4); break;
case 'v' : c = '\v'; break;
- case 'x' : {
- c = ScanHexNumber(2);
- if (c == static_cast<uc32>(unibrow::Utf8::kBadChar)) c = 'x';
- break;
- }
+ case 'x' : c = ScanHexEscape(c, 2); break;
case '0' : // fall through
case '1' : // fall through
case '2' : // fall through
@@ -810,7 +803,7 @@
Advance();
if (c0_ != 'u') return unibrow::Utf8::kBadChar;
Advance();
- uc32 c = ScanHexNumber(4);
+ uc32 c = ScanHexEscape('u', 4);
// We do not allow a unicode escape sequence to start another
// unicode escape sequence.
if (c == '\\') return unibrow::Utf8::kBadChar;
« no previous file with comments | « src/scanner-base.h ('k') | test/mjsunit/regress/regress-1620.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698