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.

is.js 884B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var isPrototype = require("../prototype/is");
  3. // In theory we could rely on Symbol.toStringTag directly,
  4. // still early native implementation (e.g. in FF) predated symbols
  5. var objectToString = Object.prototype.toString
  6. , objectTaggedString = objectToString.call(Promise.resolve());
  7. module.exports = function (value) {
  8. if (!value) return false;
  9. // Sanity check (reject objects which do not expose common Promise interface)
  10. try {
  11. if (typeof value.then !== "function") return false;
  12. if (typeof value["catch"] !== "function") return false;
  13. } catch (error) {
  14. return false;
  15. }
  16. // Ensure its native Promise object (has [[PromiseState]] slot)
  17. // Note: it's not 100% precise as string tag may be overriden
  18. // and other objects could be hacked to expose it
  19. if (objectToString.call(value) !== objectTaggedString) return false;
  20. return !isPrototype(value);
  21. };