archives

« Bugzilla Issues Index

#4545 — 22.1.3.11, 22.1.3.14: Inconsistent return value for -0 in Array.prototype.indexOf and Array.prototype.lastIndexOf


22.1.3.11 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
22.1.3.14 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )

From https://github.com/tc39/test262/issues/435

`[true].indexOf(true, -0)` is spec'ed to return `-0`, whereas `[true].lastIndexOf(true, -0)` is spec'ed to return `+0`. Both methods should return the same result index when called with `-0`.



22.1.3.11 Array.prototype.indexOf when called with fromIndex = -0:
- step 6: ToInteger(-0) returns -0
- step 9: -0 >= 0 is true, so k is set to -0.
- step 11.c.iv: k = -0 is returned


22.1.3.14 Array.prototype.lastIndexOf when called with fromIndex = -0:
- step 6: ToInteger(-0) returns -0
- step 8: -0 >= 0 is true, k = min(-0, len - 1) with len=1 sets k to +0 per 5.2 Algorithm Conventions (implicit conversion from -0 to +0 when calling min(...))
- step 10.c.iv: k = +0 is returned


Fixed in ES2016 Draft (15ad1386)