1 |
|
2 | import Promise from './promise';
|
3 |
|
4 | export default function polyfill() {
|
5 | let local;
|
6 |
|
7 | if (typeof global !== 'undefined') {
|
8 | local = global;
|
9 | } else if (typeof self !== 'undefined') {
|
10 | local = self;
|
11 | } else {
|
12 | try {
|
13 | local = Function('return this')();
|
14 | } catch (e) {
|
15 | throw new Error('polyfill failed because global object is unavailable in this environment');
|
16 | }
|
17 | }
|
18 |
|
19 | let P = local.Promise;
|
20 |
|
21 | if (P) {
|
22 | var promiseToString = null;
|
23 | try {
|
24 | promiseToString = Object.prototype.toString.call(P.resolve());
|
25 | } catch(e) {
|
26 |
|
27 | }
|
28 |
|
29 | if (promiseToString === '[object Promise]' && !P.cast){
|
30 | return;
|
31 | }
|
32 | }
|
33 |
|
34 | local.Promise = Promise;
|
35 | }
|