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 107009 701e901721bf
parent 107008 eb6caf30255c
child 107010 0ec10e895d42
push id23462
push userryanvm@gmail.com
push date2012-09-14 01:53 +0000
treeherdermozilla-central@d21d47aa9513 [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);