Bug 788701 - Decrease the length of the text to match when there is a start position. r=jorendorff, a=lsblakk
authorBenjamin Peterson <benjamin@python.org>
Fri, 14 Sep 2012 18:43:06 -0400
changeset 106851 9fe83b0caa13
parent 106850 f22cb258b111
child 106852 a6440cd0e612
push id2088
push userbenjamin@python.org
push date2012-09-14 22:43 +0000
treeherdermozilla-aurora@9fe83b0caa13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff, lsblakk
bugs788701
milestone17.0a2
Bug 788701 - Decrease the length of the text to match when there is a start position. r=jorendorff, a=lsblakk
js/src/jit-test/tests/basic/string-contains.js
js/src/jsstr.cpp
--- a/js/src/jit-test/tests/basic/string-contains.js
+++ b/js/src/jit-test/tests/basic/string-contains.js
@@ -35,8 +35,12 @@ myobj = {toString : (function () {
 contains : String.prototype.contains};
 var idx = {valueOf : (function () {
     assertEq(gotStr, true);
     gotPos = true;
     return 42;
 })};
 myobj.contains("elephant", idx);
 assertEq(gotPos, true);
+assertEq("xyzzy".contains("zy\0", 2), false);
+var dots = Array(10000).join('.');
+assertEq(dots.contains("\x01", 10000), false);
+assertEq(dots.contains("\0", 10000), false);
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1155,17 +1155,19 @@ str_contains(JSContext *cx, unsigned arg
 
     if (args.hasDefined(1)) {
         // Step 4
         double posDouble;
         if (!ToInteger(cx, args[1], &posDouble))
             return false;
 
         // Step 6
-        text += uint32_t(Min(double(textlen), Max(0.0, posDouble)));
+        uint32_t delta = uint32_t(Min(double(textlen), Max(0.0, posDouble)));
+        text += delta;
+        textlen -= delta;
     }
 
     // Step 7
     uint32_t patlen = patstr->length();
     const jschar *pat = patstr->chars();
 
     // Step 8
     args.rval().setBoolean(StringMatch(text, textlen, pat, patlen) >= 0);