Commit b7eb138e authored by lrn@chromium.org's avatar lrn@chromium.org

The spec (15.1.2.2 parseInt (string , radix)) says ToString should be called before ToInt32.

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

In the current implementation, the order is reversed. So this webkit test (https://bugs.webkit.org/show_bug.cgi?id=65366) fails on Chromium.

BUG=1649
TEST=parse-int-float.js

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9116 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5289e3e0
...@@ -115,13 +115,16 @@ function GlobalParseInt(string, radix) { ...@@ -115,13 +115,16 @@ function GlobalParseInt(string, radix) {
// Truncate number. // Truncate number.
return string | 0; return string | 0;
} }
string = TO_STRING_INLINE(string);
radix = radix | 0; radix = radix | 0;
} else { } else {
// The spec says ToString should be evaluated before ToInt32.
string = TO_STRING_INLINE(string);
radix = TO_INT32(radix); radix = TO_INT32(radix);
if (!(radix == 0 || (2 <= radix && radix <= 36))) if (!(radix == 0 || (2 <= radix && radix <= 36)))
return $NaN; return $NaN;
} }
string = TO_STRING_INLINE(string);
if (%_HasCachedArrayIndex(string) && if (%_HasCachedArrayIndex(string) &&
(radix == 0 || radix == 10)) { (radix == 0 || radix == 10)) {
return %_GetCachedArrayIndex(string); return %_GetCachedArrayIndex(string);
......
...@@ -100,4 +100,17 @@ assertTrue(isNaN(parseFloat(0/0))); ...@@ -100,4 +100,17 @@ assertTrue(isNaN(parseFloat(0/0)));
assertEquals(Infinity, parseFloat(1/0), "parseFloat Infinity"); assertEquals(Infinity, parseFloat(1/0), "parseFloat Infinity");
assertEquals(-Infinity, parseFloat(-1/0), "parseFloat -Infinity"); assertEquals(-Infinity, parseFloat(-1/0), "parseFloat -Infinity");
var state;
var throwingRadix = { valueOf: function() { state = "throwingRadix"; throw null; } };
var throwingString = { toString: function() { state = "throwingString"; throw null; } };
state = null;
try { parseInt('123', throwingRadix); } catch (e) {}
assertEquals(state, "throwingRadix");
state = null;
try { parseInt(throwingString, 10); } catch (e) {}
assertEquals(state, "throwingString");
state = null;
try { parseInt(throwingString, throwingRadix); } catch (e) {}
assertEquals(state, "throwingString");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment