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.

IsPromise.js 490B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var callBound = require('../helpers/callBound');
  3. var $PromiseThen = callBound('Promise.prototype.then', true);
  4. var Type = require('./Type');
  5. // https://www.ecma-international.org/ecma-262/6.0/#sec-ispromise
  6. module.exports = function IsPromise(x) {
  7. if (Type(x) !== 'Object') {
  8. return false;
  9. }
  10. if (!$PromiseThen) { // Promises are not supported
  11. return false;
  12. }
  13. try {
  14. $PromiseThen(x); // throws if not a promise
  15. } catch (e) {
  16. return false;
  17. }
  18. return true;
  19. };