archives

« Bugzilla Issues Index

#4368 — Minor cleanups for Array.prototype.indexOf


While doing Array.prototype.includes review with implementers, the initial spec (which copied Array.prototype.indexOf) came under fire for a few redundant steps. We should make those fixes to Array.prototype.indexOf as well. Namely:

> 8. If n ≥ len, return −1.

This step is redundant.

> 10.a. Let k be len - abs(n).

This could be more clearly written as len + n, since n < 0 is the precondition in step 10.


Also:

> 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0.

This could be written more simply (in terms of easier to translate to implementations) as

> 6. Let n be ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0).

which is what is done in String.prototype.includes and several other places in the spec.


deferring for ES7 consideration.

Internal spec. consistency is important.

also, it isn't obvious to me that "len + n" with a remote guard on the sign of n is clearer than a redundant abs in "len - abs(n)"