Bug 788701 - Decrease the length of the text to match when there is a start position. r=jorendorff
authorBenjamin Peterson <benjamin@python.org>
Thu, 13 Sep 2012 14:34:33 -0400
changeset 106988 701e901721bf46391cc59019b022fe75439ea44a
parent 106987 eb6caf30255cfc749d9d4287301ad9d0fb743dae
child 106989 0ec10e895d42536076c6d3825f9c101559249cfe
push id14804
push userbenjamin@python.org
push dateThu, 13 Sep 2012 18:34:49 +0000
treeherdermozilla-inbound@701e901721bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs788701
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 788701 - Decrease the length of the text to match when there is a start position. r=jorendorff
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);