Reviewers: Vitaly,

Message:
Please take a look. I have added a test that should fail on TOT.

Description:
Fix charCodeAt custom call generator.

If the string is non-flat and the index is a non-round number (e.g. 1.1)
then Runtime_StringCharCodeAt will fail (because in can only handle a round
index).


Please review this at http://codereview.chromium.org/2478003/show

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/ia32/codegen-ia32.cc
  M     test/mjsunit/string-charcodeat.js


Index: test/mjsunit/string-charcodeat.js
===================================================================
--- test/mjsunit/string-charcodeat.js   (revision 4785)
+++ test/mjsunit/string-charcodeat.js   (working copy)
@@ -154,6 +154,12 @@
 TestStringType(NotAString16, true);


+for (var i = 0; i != 10; i++) {
+  assertEquals(101, Cons16().charCodeAt(1.1));
+  assertEquals('e', Cons16().charAt(1.1));
+}
+
+
 function StupidThing() {
   // Doesn't return a string from toString!
   this.toString = function() { return 42; }
Index: src/ia32/codegen-ia32.cc
===================================================================
--- src/ia32/codegen-ia32.cc    (revision 4785)
+++ src/ia32/codegen-ia32.cc    (working copy)
@@ -12567,8 +12567,8 @@
   __ j(not_zero, &index_not_smi_);

   // Put smi-tagged index into scratch register.
-  __ mov(scratch_, index_);
   __ bind(&got_smi_index_);
+  __ mov(scratch_, index_);

   // Check for index out of range.
   __ cmp(scratch_, FieldOperand(object_, String::kLengthOffset));
@@ -12637,7 +12637,6 @@
   __ CheckMap(index_, Factory::heap_number_map(), index_not_number_, true);
   call_helper.BeforeCall(masm);
   __ push(object_);
-  __ push(index_);
   __ push(index_);  // Consumed by runtime conversion function.
   if (index_flags_ == STRING_INDEX_IS_NUMBER) {
     __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
@@ -12646,12 +12645,11 @@
     // NumberToSmi discards numbers that are not exact integers.
     __ CallRuntime(Runtime::kNumberToSmi, 1);
   }
-  if (!scratch_.is(eax)) {
-    // Save the conversion result before the pop instructions below
-    // have a chance to overwrite it.
-    __ mov(scratch_, eax);
+  if (!index_.is(eax)) {
+ // Overwrite index_ with the conversion result so that it can be passed to
+    // Runtime_StringCharCodeAt (which does not accept non-round numbers).
+    __ mov(index_, eax);
   }
-  __ pop(index_);
   __ pop(object_);
   // Reload the instance type.
   __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
@@ -12659,7 +12657,7 @@
   call_helper.AfterCall(masm);
   // If index is still not a smi, it must be out of range.
   ASSERT(kSmiTag == 0);
-  __ test(scratch_, Immediate(kSmiTagMask));
+  __ test(index_, Immediate(kSmiTagMask));
   __ j(not_zero, index_out_of_range_);
   // Otherwise, return to the fast path.
   __ jmp(&got_smi_index_);


--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev

Reply via email to