Fix off-by-one in hex-parsing.

Review URL: http://codereview.chromium.org/5129002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5855 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
lrn@chromium.org 2010-11-18 13:50:21 +00:00
parent 2d4aa6295b
commit ecf0d85a8e
2 changed files with 39 additions and 1 deletions

View File

@ -48,7 +48,7 @@ inline int HexValue(uc32 c) {
c -= '0';
if (static_cast<unsigned>(c) <= 9) return c;
c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36.
if (static_cast<unsigned>(c) <= 6) return c + 10;
if (static_cast<unsigned>(c) <= 5) return c + 10;
return -1;
}

View File

@ -34,6 +34,43 @@ assertEquals("abc", eval("'abc'"));
assertEquals(8, eval("6;'abc';8"));
// Characters just outside the ranges of hex-escapes.
// "/" comes just before "0".
assertEquals("x1/", "\x1/");
assertEquals("u111/", "\u111/");
assertEquals("\\x1/", RegExp("\\x1/").source);
assertEquals("\\u111/", RegExp("\\u111/").source);
// ":" comes just after "9".
assertEquals("x1:", "\x1:");
assertEquals("u111:", "\u111:");
assertEquals("\\x1:", /\x1:/.source);
assertEquals("\\u111:", /\u111:/.source);
// "`" comes just before "a".
assertEquals("x1`", "\x1`");
assertEquals("u111`", "\u111`");
assertEquals("\\x1`", /\x1`/.source);
assertEquals("\\u111`", /\u111`/.source);
// "g" comes just before "f".
assertEquals("x1g", "\x1g");
assertEquals("u111g", "\u111g");
assertEquals("\\x1g", /\x1g/.source);
assertEquals("\\u111g", /\u111g/.source);
// "@" comes just before "A".
assertEquals("x1@", "\x1@");
assertEquals("u111@", "\u111@");
assertEquals("\\x1@", /\x1@/.source);
assertEquals("\\u111@", /\u111@/.source);
// "G" comes just after "F".
assertEquals("x1G", "\x1G");
assertEquals("u111G", "\u111G");
assertEquals("\\x1G", /\x1G/.source);
assertEquals("\\u111G", /\u111G/.source);
// Test some materialized array literals.
assertEquals([1,2,3,4], eval('[1,2,3,4]'));
assertEquals([[1,2],3,4], eval('[[1,2],3,4]'));
@ -50,3 +87,4 @@ assertEquals([2,4,6,8], eval(s));
assertEquals(17, eval('[1,2,3,4]; 17'));
assertEquals(19, eval('var a=1, b=2; [a,b,3,4]; 19'));
assertEquals(23, eval('var a=1, b=2; c=23; [a,b,3,4]; c'));