is-plain-function.js 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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)),
  11. false,
  12. "Function with non-function prototype"
  13. );
  14. }
  15. var arrowfn;
  16. try {
  17. arrowfn = eval("(() => {})");
  18. } catch (e) {}
  19. if (arrowfn) {
  20. a(t(arrowfn), true, "Arrow function");
  21. }
  22. var classFn;
  23. try {
  24. classFn = eval("(class {})");
  25. } catch (e) {}
  26. if (classFn) {
  27. a(t(classFn), false, "Class");
  28. }
  29. var commentedClassFn;
  30. try {
  31. // Follows issue reported to ljhard/is-callable project:
  32. // https://github.com/ljharb/is-callable/issues/4
  33. commentedClassFn = eval("(class/*kkk*/\n//blah\n Bar\n//blah\n {})");
  34. } catch (e) {}
  35. if (commentedClassFn) {
  36. a(t(commentedClassFn, false, "Class"), false, "Class with comments");
  37. }
  38. };