UNPKG

1.08 kBJavaScriptView Raw
1import Promise from './index';
2import promiseFinally from './finally';
3import allSettled from './allSettled';
4
5/** @suppress {undefinedVars} */
6var globalNS = (function() {
7 // the only reliable means to get the global object is
8 // `Function('return this')()`
9 // However, this causes CSP violations in Chrome apps.
10 if (typeof self !== 'undefined') {
11 return self;
12 }
13 if (typeof window !== 'undefined') {
14 return window;
15 }
16 if (typeof global !== 'undefined') {
17 return global;
18 }
19 throw new Error('unable to locate global object');
20})();
21
22// Expose the polyfill if Promise is undefined or set to a
23// non-function value. The latter can be due to a named HTMLElement
24// being exposed by browsers for legacy reasons.
25// https://github.com/taylorhakes/promise-polyfill/issues/114
26if (typeof globalNS['Promise'] !== 'function') {
27 globalNS['Promise'] = Promise;
28} else if (!globalNS.Promise.prototype['finally']) {
29 globalNS.Promise.prototype['finally'] = promiseFinally;
30} else if (!globalNS.Promise.allSettled) {
31 globalNS.Promise.allSettled = allSettled;
32}