1 var uncurryThis = require('../internals/function-uncurry-this');
2 var fails = require('../internals/fails');
3 var isCallable = require('../internals/is-callable');
4 var classof = require('../internals/classof');
5 var getBuiltIn = require('../internals/get-built-in');
6 var inspectSource = require('../internals/inspect-source');
8 var noop = function () { /* empty */ };
10 var construct = getBuiltIn('Reflect', 'construct');
11 var constructorRegExp = /^\s*(?:class|function)\b/;
12 var exec = uncurryThis(constructorRegExp.exec);
13 var INCORRECT_TO_STRING = !constructorRegExp.exec(noop);
15 var isConstructorModern = function (argument) {
16 if (!isCallable(argument)) return false;
18 construct(noop, empty, argument);
25 var isConstructorLegacy = function (argument) {
26 if (!isCallable(argument)) return false;
27 switch (classof(argument)) {
29 case 'GeneratorFunction':
30 case 'AsyncGeneratorFunction': return false;
31 // we can't check .prototype since constructors produced by .bind haven't it
32 } return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource(argument));
35 // `IsConstructor` abstract operation
36 // https://tc39.es/ecma262/#sec-isconstructor
37 module.exports = !construct || fails(function () {
39 return isConstructorModern(isConstructorModern.call)
40 || !isConstructorModern(Object)
41 || !isConstructorModern(function () { called = true; })
43 }) ? isConstructorLegacy : isConstructorModern;