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