Chrome – Array.prototype.slice(…) Difference

At first I thought this was an infinite loop bug issue. After that, I thought it was just simply a bug. Now, after a co-worker (Geoff) pointed me to the JavaScript specs, I see that Chrome implemented this correctly and others didn’t. In most browsers the following code would result in an empty array, but in Chrome (at least in v34.0.1847.116) you will get an array of length 4294967295:

[].slice.call({length:-1})

Immediately you would think this is a bug but interestingly if you do the following you will get an array of length 1:

[].slice.call({length:-4294967295})

After looking at the specs you can see that the length is converted to a 32-bit integer: