ecma262
ecma262 copied to clipboard
Editorial: Revert unintentional normative change for String.prototype.substr
"a".substr(0, Infinity) should return "a", but #2007 incorrectly changed the result to be "".
If we change substr's algorithm to be more similar to String.prototype.substring and String.prototype.slice, we can easily fix this issue:
min(intStart, size)guarantees thatintStartis now in[0, size].- Clamping
intLengthguarantees it's also in[0, size].
With these two changes, intEnd = min(intStart + intLength, size) is now in range [intStart, size], so we no longer have to check for intStart ≥ intEnd, but instead can directly perform the substring operation.