| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var bind = require('function-bind'); |
| 4 | var GetIntrinsic = require('get-intrinsic'); |
| 5 | |
| 6 | var $apply = GetIntrinsic('%Function.prototype.apply%'); |
| 7 | var $call = GetIntrinsic('%Function.prototype.call%'); |
| 8 | var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); |
| 9 | |
| 10 | var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); |
| 11 | |
| 12 | if ($defineProperty) { |
| 13 | try { |
| 14 | $defineProperty({}, 'a', { value: 1 }); |
| 15 | } catch (e) { |
| 16 | // IE 8 has a broken defineProperty |
| 17 | $defineProperty = null; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | module.exports = function callBind() { |
| 22 | return $reflectApply(bind, $call, arguments); |
| 23 | }; |
| 24 | |
| 25 | var applyBind = function applyBind() { |
| 26 | return $reflectApply(bind, $apply, arguments); |
| 27 | }; |
| 28 | |
| 29 | if ($defineProperty) { |
| 30 | $defineProperty(module.exports, 'apply', { value: applyBind }); |
| 31 | } else { |
| 32 | module.exports.apply = applyBind; |
| 33 | } |