Revision: 4791
Author: [email protected]
Date: Thu Jun  3 04:31:19 2010
Log: Fix double to integer conversions in runtime string indexing.

Review URL: http://codereview.chromium.org/2577001
http://code.google.com/p/v8/source/detail?r=4791

Modified:
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/mjsunit/string-charat.js

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Thu Jun  3 02:32:07 2010
+++ /branches/bleeding_edge/src/runtime.cc      Thu Jun  3 04:31:19 2010
@@ -1665,7 +1665,7 @@
   } else {
     ASSERT(index->IsHeapNumber());
     double value = HeapNumber::cast(index)->value();
-    i = static_cast<uint32_t>(value);
+    i = static_cast<uint32_t>(DoubleToInteger(value));
   }

   // Flatten the string.  If someone wants to get a char at an index
=======================================
--- /branches/bleeding_edge/test/mjsunit/string-charat.js Thu Jun 3 02:32:07 2010 +++ /branches/bleeding_edge/test/mjsunit/string-charat.js Thu Jun 3 04:31:19 2010
@@ -48,6 +48,7 @@
   assertEquals("", s().charAt(-1/0));
   assertEquals("t", s().charAt(0));
   assertEquals("t", s().charAt(-0.0));
+  assertEquals("t", s().charAt(-0.1));
   assertEquals("t", s().charAt(0.4));
   assertEquals("e", s().charAt(slowIndex1));
   assertEquals("s", s().charAt(slowIndex2));
@@ -63,6 +64,7 @@
   assertEquals(101, s().charCodeAt(true));
   assertEquals(116, s().charCodeAt(0));
   assertEquals(116, s().charCodeAt(-0.0));
+  assertEquals(116, s().charCodeAt(-0.1));
   assertEquals(116, s().charCodeAt(0.4));
   assertEquals(101, s().charCodeAt(slowIndex1));
   assertEquals(115, s().charCodeAt(slowIndex2));

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

Reply via email to