paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

ES5 Array method wrappers need full implementations #342

Open ljharb opened 9 years ago

ljharb commented 9 years ago

Originally part of #341.

var c = 0;
[].map.call({get length(){c++;return 0}}, isNaN);
c; // => 2, should be 1 

var O = {length: Math.pow(2, 32) + 1};
O[Math.pow(2, 32)] = 42;
[].forEach.call(O, console.log, console); // => nothing, should be 42, 4294967296, O

To fix both of these, instead of calling the native methods (in the scenario where the native methods behave incorrectly for negative and over-32-bit-length array-like objects), we need to reimplement all of them in their entirety. The ideal way to do this is to require in the implementations from the es5-shim, rather than duplicating all of the tests and code.