zloirock / core-js

Standard Library
MIT License
24.03k stars 1.62k forks source link

Spec Mismatch in `Array.of` #1322

Closed stonechoe closed 4 months ago

stonechoe commented 4 months ago

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

let of = require("core-js-pure/es/array/of");

let handler = {
  has: () => {
    throw 42;
  },
};

let x = function () {
  return new Proxy({}, handler);
};

of.call(x, 0)

It throws with the polyfill, while it doesn't with the native implementation. Although it is unusual to implement proxy to throw an exception, but even without throwing, it can still introduce silent bugs due to side effects.

zloirock commented 4 months ago

From #1324:

You are right, it's a performance optimization. Without this optimization, some methods worked unacceptably slow. However, now most methods where it's used are available in most engines, and Proxy is enough popular. I will think make it sense to accept it or not.