zloirock / core-js

Standard Library
MIT License
24.59k stars 1.66k forks source link

Fix `Array.from` #1331

Closed stonechoe closed 9 months ago

stonechoe commented 9 months ago

Following code behaves differently depending on whether the native version is loaded, or if the polyfill is required and loaded:

const f = require("core-js-pure/es/array/from");

const a = function () {
    throw 42;
};

const b = {};
b[Symbol.iterator] = () => undefined

f.call(a, b) // throw '42' in native, throw 'TypeError' in polyfill

The difference comes from the order of construction and type checking - construct should be done first. spec

try {
    f.call(a, b)
} catch (e) {
    e === 42 // This should be true
}