Counterintuitive native array methods behavior (.length > 2^32)

Michał Wadas michalwadas at gmail.com
Mon Jul 13 11:18:35 UTC 2015


Steps to reproduce:

let p = {
0: 'a',
1: 'b',
2: 'c',
length: Math.pow(2,32)+1
};
Array.prototype.forEach.call(p, (el)=>console.log(el)); // logs only 'a'

The cause of this behaviour is obvious for anyone that reads
specification - every native Array.prototype methods perform abstract
operation `ToUint32(this.length).

Anyway - this behaviour obviously counters intuition. I think it would
be totally OK to allow native methods to throw when .length > 2^32,


More information about the es-discuss mailing list