archives

« Bugzilla Issues Index

#4432 — String.prototype.split should revert to ES5 behavior, using ToUint32 to coerce limit argument


See this gist, discussed at the meeting on 28 July 2015: https://gist.github.com/ajklein/335e0f948c500a0c25dc (copy/pasted below with poorer formatting)

ES5 (15.5.4.14.5): If limit is undefined, let lim = 2^32-1; else let lim = ToUint32(limit).

ES6 (21.1.3.17.8): If limit is undefined, let lim = 2^53-1; else let lim = ToLength(limit).

Two problems with ES6 behavior:

- Return value is an Array, so a limit greater than 232-1 would result in a "malformed" array (one with elements past the end of the array). Iteration over the return value will skip all such elements.
- Behavior changes for negative limit: ToUint32 transforms -1 to 232-1; ToLength instead transforms -1 to 0.

Proposal: Revert this spec change. Existing implementations still match ES5, and the old behavior still makes sense (even with ES6's longer String length limit). If we want a split that can return more than 2^32-1 elements, a new method should be created (or split() should return something other than an Array).


Resolution from the July meeting was to revert this change:

https://github.com/rwaldron/tc39-notes/blob/master/es7/2015-07/july-28.md#612-stringprototypesplit-its-limit-argument-and-tolength-vs-touint32