Revision: 8992
Author:   [email protected]
Date:     Mon Aug 22 06:55:25 2011
Log:      Inserted a missing string encoding check in lastIndexOf.

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

Modified:
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/string.js
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Tue Aug 16 07:24:12 2011
+++ /branches/bleeding_edge/src/runtime.cc      Mon Aug 22 06:55:25 2011
@@ -3159,29 +3159,33 @@
   if (!sub->IsFlat()) FlattenString(sub);
   if (!pat->IsFlat()) FlattenString(pat);

+  int position = -1;
   AssertNoAllocation no_heap_allocation;  // ensure vectors stay valid
-
-  int position = -1;
-
-  if (pat->IsAsciiRepresentation()) {
-    Vector<const char> pat_vector = pat->ToAsciiVector();
-    if (sub->IsAsciiRepresentation()) {
-      position = StringMatchBackwards(sub->ToAsciiVector(),
+ // Extract flattened substrings of cons strings before determining asciiness.
+  String* seq_sub = *sub;
+ if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first();
+  String* seq_pat = *pat;
+ if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first();
+
+  if (seq_pat->IsAsciiRepresentation()) {
+    Vector<const char> pat_vector = seq_pat->ToAsciiVector();
+    if (seq_sub->IsAsciiRepresentation()) {
+      position = StringMatchBackwards(seq_sub->ToAsciiVector(),
                                       pat_vector,
                                       start_index);
     } else {
-      position = StringMatchBackwards(sub->ToUC16Vector(),
+      position = StringMatchBackwards(seq_sub->ToUC16Vector(),
                                       pat_vector,
                                       start_index);
     }
   } else {
-    Vector<const uc16> pat_vector = pat->ToUC16Vector();
-    if (sub->IsAsciiRepresentation()) {
-      position = StringMatchBackwards(sub->ToAsciiVector(),
+    Vector<const uc16> pat_vector = seq_pat->ToUC16Vector();
+    if (seq_sub->IsAsciiRepresentation()) {
+      position = StringMatchBackwards(seq_sub->ToAsciiVector(),
                                       pat_vector,
                                       start_index);
     } else {
-      position = StringMatchBackwards(sub->ToUC16Vector(),
+      position = StringMatchBackwards(seq_sub->ToUC16Vector(),
                                       pat_vector,
                                       start_index);
     }
=======================================
--- /branches/bleeding_edge/src/string.js       Mon Aug 22 02:51:56 2011
+++ /branches/bleeding_edge/src/string.js       Mon Aug 22 06:55:25 2011
@@ -149,7 +149,7 @@
         position = 0;
       }
       if (position + patLength < subLength) {
-        index = position
+        index = position;
       }
     }
   }
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Wed Aug 17 09:15:30 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Mon Aug 22 06:55:25 2011
@@ -13693,6 +13693,9 @@
       "str2;";
   Local<Value> result = CompileRun(init_code);

+  Local<Value> indexof = CompileRun("str2.indexOf('els')");
+  Local<Value> lastindexof = CompileRun("str2.lastIndexOf('dab')");
+
   CHECK(result->IsString());
i::Handle<i::String> string = v8::Utils::OpenHandle(String::Cast(*result));
   int length = string->length();
@@ -13758,6 +13761,10 @@

   ExpectString("str2.charAt(2);", "e");

+  ExpectObject("str2.indexOf('els');", indexof);
+
+  ExpectObject("str2.lastIndexOf('dab');", lastindexof);
+
   reresult = CompileRun("str2.charCodeAt(2);");
   CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value());
 }

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

Reply via email to