summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/polyfill.js
blob: 83ddf0662b9802b1f48bcfa783a5a6acdd0f5201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*global self*/
import Promise from './promise';

export default function polyfill() {
  let local;

  if (typeof global !== 'undefined') {
      local = global;
  } else if (typeof self !== 'undefined') {
      local = self;
  } else {
      try {
          local = Function('return this')();
      } catch (e) {
          throw new Error('polyfill failed because global object is unavailable in this environment');
      }
  }

  let P = local.Promise;

  if (P) {
    var promiseToString = null;
    try {
        promiseToString = Object.prototype.toString.call(P.resolve());
    } catch(e) {
        // silently ignored
    }

    if (promiseToString === '[object Promise]' && !P.cast){
        return;
    }
  }

  local.Promise = Promise;
}