2023-12-03 16:59:28 +04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var bind = require('function-bind');
|
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
2024-01-06 20:33:49 +04:00
|
|
|
var setFunctionLength = require('set-function-length');
|
2023-12-03 16:59:28 +04:00
|
|
|
|
2024-01-06 20:33:49 +04:00
|
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
2023-12-03 16:59:28 +04:00
|
|
|
var $apply = GetIntrinsic('%Function.prototype.apply%');
|
|
|
|
var $call = GetIntrinsic('%Function.prototype.call%');
|
|
|
|
var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
|
|
|
|
|
|
|
|
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
|
|
|
var $max = GetIntrinsic('%Math.max%');
|
|
|
|
|
|
|
|
if ($defineProperty) {
|
|
|
|
try {
|
|
|
|
$defineProperty({}, 'a', { value: 1 });
|
|
|
|
} catch (e) {
|
|
|
|
// IE 8 has a broken defineProperty
|
|
|
|
$defineProperty = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function callBind(originalFunction) {
|
2024-01-06 20:33:49 +04:00
|
|
|
if (typeof originalFunction !== 'function') {
|
|
|
|
throw new $TypeError('a function is required');
|
2023-12-21 21:08:22 +04:00
|
|
|
}
|
2024-01-06 20:33:49 +04:00
|
|
|
var func = $reflectApply(bind, $call, arguments);
|
|
|
|
return setFunctionLength(
|
|
|
|
func,
|
|
|
|
1 + $max(0, originalFunction.length - (arguments.length - 1)),
|
|
|
|
true
|
|
|
|
);
|
2023-12-03 16:59:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
var applyBind = function applyBind() {
|
|
|
|
return $reflectApply(bind, $apply, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($defineProperty) {
|
|
|
|
$defineProperty(module.exports, 'apply', { value: applyBind });
|
|
|
|
} else {
|
|
|
|
module.exports.apply = applyBind;
|
|
|
|
}
|