diff options
Diffstat (limited to 'node_modules/is-callable/index.js')
-rw-r--r-- | node_modules/is-callable/index.js | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/node_modules/is-callable/index.js b/node_modules/is-callable/index.js index d9820b51f..a2d4adc10 100644 --- a/node_modules/is-callable/index.js +++ b/node_modules/is-callable/index.js @@ -1,6 +1,23 @@ 'use strict'; var fnToStr = Function.prototype.toString; +var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply; +var badArrayLike; +var isCallableMarker; +if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') { + try { + badArrayLike = Object.defineProperty({}, 'length', { + get: function () { + throw isCallableMarker; + } + }); + isCallableMarker = {}; + } catch (_) { + reflectApply = null; + } +} else { + reflectApply = null; +} var constructorRegex = /^\s*class\b/; var isES6ClassFn = function isES6ClassFunction(value) { @@ -26,12 +43,24 @@ var fnClass = '[object Function]'; var genClass = '[object GeneratorFunction]'; var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; -module.exports = function isCallable(value) { - if (!value) { return false; } - if (typeof value !== 'function' && typeof value !== 'object') { return false; } - if (typeof value === 'function' && !value.prototype) { return true; } - if (hasToStringTag) { return tryFunctionObject(value); } - if (isES6ClassFn(value)) { return false; } - var strClass = toStr.call(value); - return strClass === fnClass || strClass === genClass; -}; +module.exports = reflectApply + ? function isCallable(value) { + if (!value) { return false; } + if (typeof value !== 'function' && typeof value !== 'object') { return false; } + if (typeof value === 'function' && !value.prototype) { return true; } + try { + reflectApply(value, null, badArrayLike); + } catch (e) { + if (e !== isCallableMarker) { return false; } + } + return !isES6ClassFn(value); + } + : function isCallable(value) { + if (!value) { return false; } + if (typeof value !== 'function' && typeof value !== 'object') { return false; } + if (typeof value === 'function' && !value.prototype) { return true; } + if (hasToStringTag) { return tryFunctionObject(value); } + if (isES6ClassFn(value)) { return false; } + var strClass = toStr.call(value); + return strClass === fnClass || strClass === genClass; + }; |