Bug 1242043 - {Array,%TypedArray%}.prototype.{i,lastI}ndexOf should never return -0. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Sun, 24 Jan 2016 23:41:38 -0800
changeset 281996 aa58a439e77a
parent 281995 1979d17880e6
child 281997 4ce037f2107d
push id29950
push usercbook@mozilla.com
push dateThu, 28 Jan 2016 11:14:03 +0000
treeherdermozilla-central@2b73b0a4d52b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1242043
milestone47.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 1242043 - {Array,%TypedArray%}.prototype.{i,lastI}ndexOf should never return -0. r=jorendorff
js/src/builtin/Array.js
js/src/builtin/TypedArray.js
js/src/tests/ecma_6/Array/indexOf-never-returns-negative-zero.js
js/src/tests/ecma_6/Array/lastIndexOf-never-returns-negative-zero.js
js/src/tests/ecma_6/TypedArray/indexOf-never-returns-negative-zero.js
js/src/tests/ecma_6/TypedArray/lastIndexOf-never-returns-negative-zero.js
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -9,18 +9,18 @@ function ArrayIndexOf(searchElement/*, f
 
     /* Steps 2-3. */
     var len = TO_UINT32(O.length);
 
     /* Step 4. */
     if (len === 0)
         return -1;
 
-    /* Step 5. */
-    var n = arguments.length > 1 ? ToInteger(arguments[1]) : 0;
+    /* Step 5.  Add zero to convert -0 to +0, per ES6 5.2. */
+    var n = arguments.length > 1 ? ToInteger(arguments[1]) + 0 : 0;
 
     /* Step 6. */
     if (n >= len)
         return -1;
 
     var k;
     /* Step 7. */
     if (n >= 0)
@@ -65,18 +65,18 @@ function ArrayLastIndexOf(searchElement/
 
     /* Steps 2-3. */
     var len = TO_UINT32(O.length);
 
     /* Step 4. */
     if (len === 0)
         return -1;
 
-    /* Step 5. */
-    var n = arguments.length > 1 ? ToInteger(arguments[1]) : len - 1;
+    /* Step 5.  Add zero to convert -0 to +0, per ES6 5.2. */
+    var n = arguments.length > 1 ? ToInteger(arguments[1]) + 0 : len - 1;
 
     /* Steps 6-7. */
     var k;
     if (n > len - 1)
         k = len - 1;
     else if (n < 0)
         k = len + n;
     else
--- a/js/src/builtin/TypedArray.js
+++ b/js/src/builtin/TypedArray.js
@@ -409,18 +409,18 @@ function TypedArrayIndexOf(searchElement
 
     // Steps 3-5.
     var len = TypedArrayLength(O);
 
     // Step 6.
     if (len === 0)
         return -1;
 
-    // Steps 7-8.
-    var n = ToInteger(fromIndex);
+    // Steps 7-8.  Add zero to convert -0 to +0, per ES6 5.2.
+    var n = ToInteger(fromIndex) + 0;
 
     // Step 9.
     if (n >= len)
         return -1;
 
     var k;
     // Step 10.
     if (n >= 0) {
@@ -526,18 +526,18 @@ function TypedArrayLastIndexOf(searchEle
 
     // Steps 3-5.
     var len = TypedArrayLength(O);
 
     // Step 6.
     if (len === 0)
         return -1;
 
-    // Steps 7-8.
-    var n = fromIndex === undefined ? len - 1 : ToInteger(fromIndex);
+    // Steps 7-8.  Add zero to convert -0 to +0, per ES6 5.2.
+    var n = fromIndex === undefined ? len - 1 : ToInteger(fromIndex) + 0;
 
     // Steps 9-10.
     var k = n >= 0 ? std_Math_min(n, len - 1) : len + n;
 
     // Step 11.
     // Omit steps a-b, since there are no holes in typed arrays.
     for (; k >= 0; k--) {
         if (O[k] === searchElement)
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Array/indexOf-never-returns-negative-zero.js
@@ -0,0 +1,4 @@
+assertEq([17].indexOf(17, -0), +0);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Array/lastIndexOf-never-returns-negative-zero.js
@@ -0,0 +1,4 @@
+assertEq([17].lastIndexOf(17, -0), +0);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/TypedArray/indexOf-never-returns-negative-zero.js
@@ -0,0 +1,7 @@
+var ta = new Uint8Array(1);
+ta[0] = 17;
+
+assertEq(ta.indexOf(17, -0), +0);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/TypedArray/lastIndexOf-never-returns-negative-zero.js
@@ -0,0 +1,7 @@
+var ta = new Uint8Array(1);
+ta[0] = 17;
+
+assertEq(ta.lastIndexOf(17, -0), +0);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);