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:

Related Posts

Here is how you install Watchtower Library on Mac: Either insert the Watchtower Library disc or if you have the Watchtower Library setup files in a folder make sure you can find it. Download Wineskin Read more…