Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

esnext.function.is-callable.js 1.3KB

123456789101112131415161718192021222324252627282930
  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. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  9. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  10. var classRegExp = /^\s*class\b/;
  11. var exec = uncurryThis(classRegExp.exec);
  12. var isClassConstructor = function (argument) {
  13. try {
  14. // `Function#toString` throws on some built-it function in some legacy engines
  15. // (for example, `DOMQuad` and similar in FF41-)
  16. if (!DESCRIPTORS || !exec(classRegExp, inspectSource(argument))) return false;
  17. } catch (error) { /* empty */ }
  18. var prototype = getOwnPropertyDescriptor(argument, 'prototype');
  19. return !!prototype && hasOwn(prototype, 'writable') && !prototype.writable;
  20. };
  21. // `Function.isCallable` method
  22. // https://github.com/caitp/TC39-Proposals/blob/trunk/tc39-reflect-isconstructor-iscallable.md
  23. $({ target: 'Function', stat: true, sham: true, forced: true }, {
  24. isCallable: function isCallable(argument) {
  25. return $isCallable(argument) && !isClassConstructor(argument);
  26. }
  27. });