[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 4 | var $isCallable = require('../internals/is-callable');
|
---|
| 5 | var inspectSource = require('../internals/inspect-source');
|
---|
| 6 | var hasOwn = require('../internals/has-own-property');
|
---|
| 7 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
| 8 |
|
---|
| 9 | // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
---|
| 10 | var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
---|
| 11 | var classRegExp = /^\s*class\b/;
|
---|
| 12 | var exec = uncurryThis(classRegExp.exec);
|
---|
| 13 |
|
---|
| 14 | var isClassConstructor = function (argument) {
|
---|
| 15 | try {
|
---|
| 16 | // `Function#toString` throws on some built-it function in some legacy engines
|
---|
| 17 | // (for example, `DOMQuad` and similar in FF41-)
|
---|
| 18 | if (!DESCRIPTORS || !exec(classRegExp, inspectSource(argument))) return false;
|
---|
| 19 | } catch (error) { /* empty */ }
|
---|
| 20 | var prototype = getOwnPropertyDescriptor(argument, 'prototype');
|
---|
| 21 | return !!prototype && hasOwn(prototype, 'writable') && !prototype.writable;
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | // `Function.isCallable` method
|
---|
| 25 | // https://github.com/caitp/TC39-Proposals/blob/trunk/tc39-reflect-isconstructor-iscallable.md
|
---|
| 26 | $({ target: 'Function', stat: true, sham: true, forced: true }, {
|
---|
| 27 | isCallable: function isCallable(argument) {
|
---|
| 28 | return $isCallable(argument) && !isClassConstructor(argument);
|
---|
| 29 | }
|
---|
| 30 | });
|
---|