Skip to content

Commit

Permalink
fix regression with an error on reuse of some built-in methods from a…
Browse files Browse the repository at this point in the history
…nother realm, close #1133
  • Loading branch information
zloirock committed Oct 3, 2022
1 parent d59e440 commit 1ad3e1a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion 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)
Expand Down
6 changes: 3 additions & 3 deletions 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);
Expand Down
11 changes: 11 additions & 0 deletions 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);
};
};
13 changes: 3 additions & 10 deletions 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);
};
17 changes: 9 additions & 8 deletions 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');
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions 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));
}
});

0 comments on commit 1ad3e1a

Please sign in to comment.