Revision: 9116
Author:   [email protected]
Date:     Fri Sep  2 04:38:40 2011
Log: 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
http://code.google.com/p/v8/source/detail?r=9116

Modified:
 /branches/bleeding_edge/src/v8natives.js
 /branches/bleeding_edge/test/mjsunit/parse-int-float.js

=======================================
--- /branches/bleeding_edge/src/v8natives.js    Thu Sep  1 04:09:11 2011
+++ /branches/bleeding_edge/src/v8natives.js    Fri Sep  2 04:38:40 2011
@@ -115,13 +115,16 @@
       // Truncate number.
       return string | 0;
     }
+    string = TO_STRING_INLINE(string);
     radix = radix | 0;
   } else {
+    // The spec says ToString should be evaluated before ToInt32.
+    string = TO_STRING_INLINE(string);
     radix = TO_INT32(radix);
     if (!(radix == 0 || (2 <= radix && radix <= 36)))
       return $NaN;
   }
-  string = TO_STRING_INLINE(string);
+
   if (%_HasCachedArrayIndex(string) &&
       (radix == 0 || radix == 10)) {
     return %_GetCachedArrayIndex(string);
=======================================
--- /branches/bleeding_edge/test/mjsunit/parse-int-float.js Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/mjsunit/parse-int-float.js Fri Sep 2 04:38:40 2011
@@ -100,4 +100,17 @@
 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");

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to