diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be211c7b3ea..6b0014afa188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Changelog ##### Unreleased -- Nothing +- Fixed regression with an error on reuse of some built-in methods from another realm, [#1133](https://github.com/zloirock/core-js/issues/1133) ##### [3.25.4 - 2022.10.03](https://github.com/zloirock/core-js/releases/tag/v3.25.4) - Added a workaround of a Nashorn bug with `Function.prototype.{ call, apply, bind }` on string methods, [#1128](https://github.com/zloirock/core-js/issues/1128) diff --git a/packages/core-js/internals/classof-raw.js b/packages/core-js/internals/classof-raw.js index 9f25a89ac718..da1e701ea2f4 100644 --- a/packages/core-js/internals/classof-raw.js +++ b/packages/core-js/internals/classof-raw.js @@ -1,7 +1,7 @@ -var uncurryThis = require('../internals/function-uncurry-this'); +var uncurryThisRaw = require('../internals/function-uncurry-this-raw'); -var toString = uncurryThis({}.toString); -var stringSlice = uncurryThis(''.slice); +var toString = uncurryThisRaw({}.toString); +var stringSlice = uncurryThisRaw(''.slice); module.exports = function (it) { return stringSlice(toString(it), 8, -1); diff --git a/packages/core-js/internals/function-uncurry-this-raw.js b/packages/core-js/internals/function-uncurry-this-raw.js new file mode 100644 index 000000000000..2c25626fdbd3 --- /dev/null +++ b/packages/core-js/internals/function-uncurry-this-raw.js @@ -0,0 +1,11 @@ +var NATIVE_BIND = require('../internals/function-bind-native'); + +var FunctionPrototype = Function.prototype; +var call = FunctionPrototype.call; +var uncurryThisWithBind = NATIVE_BIND && FunctionPrototype.bind.bind(call, call); + +module.exports = function (fn) { + return NATIVE_BIND ? uncurryThisWithBind(fn) : function () { + return call.apply(fn, arguments); + }; +}; diff --git a/packages/core-js/internals/function-uncurry-this.js b/packages/core-js/internals/function-uncurry-this.js index 174ce8192a0c..654430e22d7c 100644 --- a/packages/core-js/internals/function-uncurry-this.js +++ b/packages/core-js/internals/function-uncurry-this.js @@ -1,16 +1,9 @@ -var NATIVE_BIND = require('../internals/function-bind-native'); - -var $Function = Function; -var FunctionPrototype = $Function.prototype; -var bind = FunctionPrototype.bind; -var call = FunctionPrototype.call; -var uncurryThis = NATIVE_BIND && bind.bind(call, call); +var classofRaw = require('../internals/classof-raw'); +var uncurryThisRaw = require('../internals/function-uncurry-this-raw'); module.exports = function (fn) { // Nashorn bug: // https://github.com/zloirock/core-js/issues/1128 // https://github.com/zloirock/core-js/issues/1130 - return fn instanceof $Function ? NATIVE_BIND ? uncurryThis(fn) : function () { - return call.apply(fn, arguments); - } : undefined; + if (classofRaw(fn) === 'Function') return uncurryThisRaw(fn); }; diff --git a/packages/core-js/internals/internal-state.js b/packages/core-js/internals/internal-state.js index 255f96f84c6f..9880ce87f8df 100644 --- a/packages/core-js/internals/internal-state.js +++ b/packages/core-js/internals/internal-state.js @@ -1,6 +1,5 @@ var NATIVE_WEAK_MAP = require('../internals/weak-map-basic-detection'); var global = require('../internals/global'); -var uncurryThis = require('../internals/function-uncurry-this'); var isObject = require('../internals/is-object'); var createNonEnumerableProperty = require('../internals/create-non-enumerable-property'); var hasOwn = require('../internals/has-own-property'); @@ -28,20 +27,22 @@ var getterFor = function (TYPE) { if (NATIVE_WEAK_MAP || shared.state) { var store = shared.state || (shared.state = new WeakMap()); - var wmget = uncurryThis(store.get); - var wmhas = uncurryThis(store.has); - var wmset = uncurryThis(store.set); + /* eslint-disable no-self-assign -- prototype methods protection */ + store.get = store.get; + store.has = store.has; + store.set = store.set; + /* eslint-enable no-self-assign -- prototype methods protection */ set = function (it, metadata) { - if (wmhas(store, it)) throw TypeError(OBJECT_ALREADY_INITIALIZED); + if (store.has(it)) throw TypeError(OBJECT_ALREADY_INITIALIZED); metadata.facade = it; - wmset(store, it, metadata); + store.set(it, metadata); return metadata; }; get = function (it) { - return wmget(store, it) || {}; + return store.get(it) || {}; }; has = function (it) { - return wmhas(store, it); + return store.has(it); }; } else { var STATE = sharedKey('state'); diff --git a/packages/core-js/modules/esnext.function.un-this.js b/packages/core-js/modules/esnext.function.un-this.js index bc09339f0f55..49e24911594c 100644 --- a/packages/core-js/modules/esnext.function.un-this.js +++ b/packages/core-js/modules/esnext.function.un-this.js @@ -1,11 +1,11 @@ var $ = require('../internals/export'); -var uncurryThis = require('../internals/function-uncurry-this'); +var uncurryThisRaw = require('../internals/function-uncurry-this-raw'); var aCallable = require('../internals/a-callable'); // `Function.prototype.unThis` method // https://github.com/js-choi/proposal-function-un-this $({ target: 'Function', proto: true, forced: true }, { unThis: function unThis() { - return uncurryThis(aCallable(this)); + return uncurryThisRaw(aCallable(this)); } });