Bug 1242043 - {Array,%TypedArray%}.prototype.{i,lastI}ndexOf should never return -0. r=jorendorff

This commit is contained in:
Jeff Walden 2016-01-24 23:41:38 -08:00
parent 24d3f30ce1
commit c5a00d7798
6 changed files with 30 additions and 8 deletions

View File

@ -14,8 +14,8 @@ function ArrayIndexOf(searchElement/*, fromIndex*/) {
if (len === 0) if (len === 0)
return -1; return -1;
/* Step 5. */ /* Step 5. Add zero to convert -0 to +0, per ES6 5.2. */
var n = arguments.length > 1 ? ToInteger(arguments[1]) : 0; var n = arguments.length > 1 ? ToInteger(arguments[1]) + 0 : 0;
/* Step 6. */ /* Step 6. */
if (n >= len) if (n >= len)
@ -70,8 +70,8 @@ function ArrayLastIndexOf(searchElement/*, fromIndex*/) {
if (len === 0) if (len === 0)
return -1; return -1;
/* Step 5. */ /* Step 5. Add zero to convert -0 to +0, per ES6 5.2. */
var n = arguments.length > 1 ? ToInteger(arguments[1]) : len - 1; var n = arguments.length > 1 ? ToInteger(arguments[1]) + 0 : len - 1;
/* Steps 6-7. */ /* Steps 6-7. */
var k; var k;

View File

@ -414,8 +414,8 @@ function TypedArrayIndexOf(searchElement, fromIndex = 0) {
if (len === 0) if (len === 0)
return -1; return -1;
// Steps 7-8. // Steps 7-8. Add zero to convert -0 to +0, per ES6 5.2.
var n = ToInteger(fromIndex); var n = ToInteger(fromIndex) + 0;
// Step 9. // Step 9.
if (n >= len) if (n >= len)
@ -531,8 +531,8 @@ function TypedArrayLastIndexOf(searchElement, fromIndex = undefined) {
if (len === 0) if (len === 0)
return -1; return -1;
// Steps 7-8. // Steps 7-8. Add zero to convert -0 to +0, per ES6 5.2.
var n = fromIndex === undefined ? len - 1 : ToInteger(fromIndex); var n = fromIndex === undefined ? len - 1 : ToInteger(fromIndex) + 0;
// Steps 9-10. // Steps 9-10.
var k = n >= 0 ? std_Math_min(n, len - 1) : len + n; var k = n >= 0 ? std_Math_min(n, len - 1) : len + n;

View File

@ -0,0 +1,4 @@
assertEq([17].indexOf(17, -0), +0);
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -0,0 +1,4 @@
assertEq([17].lastIndexOf(17, -0), +0);
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -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);

View File

@ -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);