3 /* global self, window, module, global, require */
4 module.exports = function () {
8 var globalObject = void 0;
10 function isFunction(x) {
11 return typeof x === "function";
14 // Seek the global object
15 if (global !== undefined) {
16 globalObject = global;
17 } else if (window !== undefined && window.document) {
18 globalObject = window;
23 // Test for any native promise implementation, and if that
24 // implementation appears to conform to the specificaton.
25 // This code mostly nicked from the es6-promise module polyfill
26 // and then fooled with.
27 var hasPromiseSupport = function () {
29 // No promise object at all, and it's a non-starter
30 if (!globalObject.hasOwnProperty("Promise")) {
34 // There is a Promise object. Does it conform to the spec?
35 var P = globalObject.Promise;
37 // Some of these methods are missing from
38 // Firefox/Chrome experimental implementations
39 if (!P.hasOwnProperty("resolve") || !P.hasOwnProperty("reject")) {
43 if (!P.hasOwnProperty("all") || !P.hasOwnProperty("race")) {
47 // Older version of the spec had a resolver object
48 // as the arg rather than a function
53 var p = new globalObject.Promise(function (r) {
58 return isFunction(resolve);
65 // Export the native Promise implementation if it
66 // looks like it matches the spec
67 if (hasPromiseSupport) {
68 return globalObject.Promise;
71 // Otherwise, return the es6-promise polyfill by @jaffathecake.
72 return require("es6-promise").Promise;