is-plain-function.js 968 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var setPrototypeOf = require("../../object/set-prototype-of");
  3. module.exports = function (t, a) {
  4. a(t(function () {}), true, "Function");
  5. a(t({}), false, "Object");
  6. a(t(), false, "Undefined");
  7. a(t(null), false, "Null");
  8. if (setPrototypeOf) {
  9. a(
  10. t(Object.setPrototypeOf(function () {}, Object.prototype)), false,
  11. "Function with non-function prototype"
  12. );
  13. }
  14. var arrowfn;
  15. try { arrowfn = eval("(() => {})"); }
  16. catch (e) {}
  17. if (arrowfn) {
  18. a(t(arrowfn), true, "Arrow function");
  19. }
  20. var classFn;
  21. try { classFn = eval("(class {})"); }
  22. catch (e) {}
  23. if (classFn) {
  24. a(t(classFn), false, "Class");
  25. }
  26. var commentedClassFn;
  27. try {
  28. // Follows issue reported to ljhard/is-callable project:
  29. // https://github.com/ljharb/is-callable/issues/4
  30. commentedClassFn = eval("(class/*kkk*/\n//blah\n Bar\n//blah\n {})");
  31. } catch (e) {}
  32. if (commentedClassFn) {
  33. a(t(commentedClassFn, false, "Class"), false, "Class with comments");
  34. }
  35. };