System.register(["__unresolved_0", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6", "__unresolved_7", "__unresolved_8", "__unresolved_9", "__unresolved_10", "__unresolved_11", "__unresolved_12", "__unresolved_13", "__unresolved_14", "__unresolved_15", "__unresolved_16", "__unresolved_17", "__unresolved_18", "__unresolved_19", "__unresolved_20", "__unresolved_21", "__unresolved_22", "__unresolved_23", "__unresolved_24", "__unresolved_25", "__unresolved_26", "__unresolved_27", "__unresolved_28", "__unresolved_29", "__unresolved_30", "__unresolved_31", "__unresolved_32"], function (_export, _context) {
  "use strict";

  var _req, _req2, _req3, _req4, _req5, _req6, _req7, _req8, _req9, _req10, _req11, _req12, _req13, _req14, _req15, _req16, _req17, _req18, _req19, _req20, _req21, _req22, _req23, _req24, _req25, _req26, _req27, _req28, _req29, _req30, _req31, _req32, _loader, _cjsExports, __cjsMetaURL;

  _export("default", void 0);

  return {
    setters: [function (_unresolved_) {
      _req = _unresolved_.__cjsMetaURL;
    }, function (_unresolved_2) {
      _req2 = _unresolved_2.__cjsMetaURL;
    }, function (_unresolved_3) {
      _req3 = _unresolved_3.__cjsMetaURL;
    }, function (_unresolved_4) {
      _req4 = _unresolved_4.__cjsMetaURL;
    }, function (_unresolved_5) {
      _req5 = _unresolved_5.__cjsMetaURL;
    }, function (_unresolved_6) {
      _req6 = _unresolved_6.__cjsMetaURL;
    }, function (_unresolved_7) {
      _req7 = _unresolved_7.__cjsMetaURL;
    }, function (_unresolved_8) {
      _req8 = _unresolved_8.__cjsMetaURL;
    }, function (_unresolved_9) {
      _req9 = _unresolved_9.__cjsMetaURL;
    }, function (_unresolved_10) {
      _req10 = _unresolved_10.__cjsMetaURL;
    }, function (_unresolved_11) {
      _req11 = _unresolved_11.__cjsMetaURL;
    }, function (_unresolved_12) {
      _req12 = _unresolved_12.__cjsMetaURL;
    }, function (_unresolved_13) {
      _req13 = _unresolved_13.__cjsMetaURL;
    }, function (_unresolved_14) {
      _req14 = _unresolved_14.__cjsMetaURL;
    }, function (_unresolved_15) {
      _req15 = _unresolved_15.__cjsMetaURL;
    }, function (_unresolved_16) {
      _req16 = _unresolved_16.__cjsMetaURL;
    }, function (_unresolved_17) {
      _req17 = _unresolved_17.__cjsMetaURL;
    }, function (_unresolved_18) {
      _req18 = _unresolved_18.__cjsMetaURL;
    }, function (_unresolved_19) {
      _req19 = _unresolved_19.__cjsMetaURL;
    }, function (_unresolved_20) {
      _req20 = _unresolved_20.__cjsMetaURL;
    }, function (_unresolved_21) {
      _req21 = _unresolved_21.__cjsMetaURL;
    }, function (_unresolved_22) {
      _req22 = _unresolved_22.__cjsMetaURL;
    }, function (_unresolved_23) {
      _req23 = _unresolved_23.__cjsMetaURL;
    }, function (_unresolved_24) {
      _req24 = _unresolved_24.__cjsMetaURL;
    }, function (_unresolved_25) {
      _req25 = _unresolved_25.__cjsMetaURL;
    }, function (_unresolved_26) {
      _req26 = _unresolved_26.__cjsMetaURL;
    }, function (_unresolved_27) {
      _req27 = _unresolved_27.__cjsMetaURL;
    }, function (_unresolved_28) {
      _req28 = _unresolved_28.__cjsMetaURL;
    }, function (_unresolved_29) {
      _req29 = _unresolved_29.__cjsMetaURL;
    }, function (_unresolved_30) {
      _req30 = _unresolved_30.__cjsMetaURL;
    }, function (_unresolved_31) {
      _req31 = _unresolved_31.__cjsMetaURL;
    }, function (_unresolved_32) {
      _req32 = _unresolved_32.__cjsMetaURL;
    }, function (_unresolved_33) {
      _loader = _unresolved_33.default;
    }],
    execute: function () {
      _loader.define(_context.meta.url, function (exports, _require, module, __filename, __dirname) {
        let require = _loader.createRequireWithReqMap({
          "../internals/export": _req,
          "../internals/is-pure": _req2,
          "../internals/global": _req3,
          "../internals/get-built-in": _req4,
          "../internals/function-call": _req5,
          "../internals/native-promise-constructor": _req6,
          "../internals/redefine": _req7,
          "../internals/redefine-all": _req8,
          "../internals/object-set-prototype-of": _req9,
          "../internals/set-to-string-tag": _req10,
          "../internals/set-species": _req11,
          "../internals/a-callable": _req12,
          "../internals/is-callable": _req13,
          "../internals/is-object": _req14,
          "../internals/an-instance": _req15,
          "../internals/inspect-source": _req16,
          "../internals/iterate": _req17,
          "../internals/check-correctness-of-iteration": _req18,
          "../internals/species-constructor": _req19,
          "../internals/task": _req20,
          "../internals/microtask": _req21,
          "../internals/promise-resolve": _req22,
          "../internals/host-report-errors": _req23,
          "../internals/new-promise-capability": _req24,
          "../internals/perform": _req25,
          "../internals/queue": _req26,
          "../internals/internal-state": _req27,
          "../internals/is-forced": _req28,
          "../internals/well-known-symbol": _req29,
          "../internals/engine-is-browser": _req30,
          "../internals/engine-is-node": _req31,
          "../internals/engine-v8-version": _req32
        }, _require);

        (function () {
          var $ = require('../internals/export');

          var IS_PURE = require('../internals/is-pure');

          var global = require('../internals/global');

          var getBuiltIn = require('../internals/get-built-in');

          var call = require('../internals/function-call');

          var NativePromise = require('../internals/native-promise-constructor');

          var redefine = require('../internals/redefine');

          var redefineAll = require('../internals/redefine-all');

          var setPrototypeOf = require('../internals/object-set-prototype-of');

          var setToStringTag = require('../internals/set-to-string-tag');

          var setSpecies = require('../internals/set-species');

          var aCallable = require('../internals/a-callable');

          var isCallable = require('../internals/is-callable');

          var isObject = require('../internals/is-object');

          var anInstance = require('../internals/an-instance');

          var inspectSource = require('../internals/inspect-source');

          var iterate = require('../internals/iterate');

          var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');

          var speciesConstructor = require('../internals/species-constructor');

          var task = require('../internals/task').set;

          var microtask = require('../internals/microtask');

          var promiseResolve = require('../internals/promise-resolve');

          var hostReportErrors = require('../internals/host-report-errors');

          var newPromiseCapabilityModule = require('../internals/new-promise-capability');

          var perform = require('../internals/perform');

          var Queue = require('../internals/queue');

          var InternalStateModule = require('../internals/internal-state');

          var isForced = require('../internals/is-forced');

          var wellKnownSymbol = require('../internals/well-known-symbol');

          var IS_BROWSER = require('../internals/engine-is-browser');

          var IS_NODE = require('../internals/engine-is-node');

          var V8_VERSION = require('../internals/engine-v8-version');

          var SPECIES = wellKnownSymbol('species');
          var PROMISE = 'Promise';
          var getInternalState = InternalStateModule.getterFor(PROMISE);
          var setInternalState = InternalStateModule.set;
          var getInternalPromiseState = InternalStateModule.getterFor(PROMISE);
          var NativePromisePrototype = NativePromise && NativePromise.prototype;
          var PromiseConstructor = NativePromise;
          var PromisePrototype = NativePromisePrototype;
          var TypeError = global.TypeError;
          var document = global.document;
          var process = global.process;
          var newPromiseCapability = newPromiseCapabilityModule.f;
          var newGenericPromiseCapability = newPromiseCapability;
          var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
          var NATIVE_REJECTION_EVENT = isCallable(global.PromiseRejectionEvent);
          var UNHANDLED_REJECTION = 'unhandledrejection';
          var REJECTION_HANDLED = 'rejectionhandled';
          var PENDING = 0;
          var FULFILLED = 1;
          var REJECTED = 2;
          var HANDLED = 1;
          var UNHANDLED = 2;
          var SUBCLASSING = false;
          var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
          var FORCED = isForced(PROMISE, function () {
            var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(PromiseConstructor);
            var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(PromiseConstructor); // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
            // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
            // We can't detect it synchronously, so just check versions

            if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true; // We need Promise#finally in the pure version for preventing prototype pollution

            if (IS_PURE && !PromisePrototype['finally']) return true; // We can't use @@species feature detection in V8 since it causes
            // deoptimization and performance degradation
            // https://github.com/zloirock/core-js/issues/679

            if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false; // Detect correctness of subclassing with @@species support

            var promise = new PromiseConstructor(function (resolve) {
              resolve(1);
            });

            var FakePromise = function (exec) {
              exec(function () {
                /* empty */
              }, function () {
                /* empty */
              });
            };

            var constructor = promise.constructor = {};
            constructor[SPECIES] = FakePromise;
            SUBCLASSING = promise.then(function () {
              /* empty */
            }) instanceof FakePromise;
            if (!SUBCLASSING) return true; // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test

            return !GLOBAL_CORE_JS_PROMISE && IS_BROWSER && !NATIVE_REJECTION_EVENT;
          });
          var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) {
            PromiseConstructor.all(iterable)['catch'](function () {
              /* empty */
            });
          }); // helpers

          var isThenable = function (it) {
            var then;
            return isObject(it) && isCallable(then = it.then) ? then : false;
          };

          var callReaction = function (reaction, state) {
            var value = state.value;
            var ok = state.state == FULFILLED;
            var handler = ok ? reaction.ok : reaction.fail;
            var resolve = reaction.resolve;
            var reject = reaction.reject;
            var domain = reaction.domain;
            var result, then, exited;

            try {
              if (handler) {
                if (!ok) {
                  if (state.rejection === UNHANDLED) onHandleUnhandled(state);
                  state.rejection = HANDLED;
                }

                if (handler === true) result = value;else {
                  if (domain) domain.enter();
                  result = handler(value); // can throw

                  if (domain) {
                    domain.exit();
                    exited = true;
                  }
                }

                if (result === reaction.promise) {
                  reject(TypeError('Promise-chain cycle'));
                } else if (then = isThenable(result)) {
                  call(then, result, resolve, reject);
                } else resolve(result);
              } else reject(value);
            } catch (error) {
              if (domain && !exited) domain.exit();
              reject(error);
            }
          };

          var notify = function (state, isReject) {
            if (state.notified) return;
            state.notified = true;
            microtask(function () {
              var reactions = state.reactions;
              var reaction;

              while (reaction = reactions.get()) {
                callReaction(reaction, state);
              }

              state.notified = false;
              if (isReject && !state.rejection) onUnhandled(state);
            });
          };

          var dispatchEvent = function (name, promise, reason) {
            var event, handler;

            if (DISPATCH_EVENT) {
              event = document.createEvent('Event');
              event.promise = promise;
              event.reason = reason;
              event.initEvent(name, false, true);
              global.dispatchEvent(event);
            } else event = {
              promise: promise,
              reason: reason
            };

            if (!NATIVE_REJECTION_EVENT && (handler = global['on' + name])) handler(event);else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
          };

          var onUnhandled = function (state) {
            call(task, global, function () {
              var promise = state.facade;
              var value = state.value;
              var IS_UNHANDLED = isUnhandled(state);
              var result;

              if (IS_UNHANDLED) {
                result = perform(function () {
                  if (IS_NODE) {
                    process.emit('unhandledRejection', value, promise);
                  } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
                }); // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should

                state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED;
                if (result.error) throw result.value;
              }
            });
          };

          var isUnhandled = function (state) {
            return state.rejection !== HANDLED && !state.parent;
          };

          var onHandleUnhandled = function (state) {
            call(task, global, function () {
              var promise = state.facade;

              if (IS_NODE) {
                process.emit('rejectionHandled', promise);
              } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
            });
          };

          var bind = function (fn, state, unwrap) {
            return function (value) {
              fn(state, value, unwrap);
            };
          };

          var internalReject = function (state, value, unwrap) {
            if (state.done) return;
            state.done = true;
            if (unwrap) state = unwrap;
            state.value = value;
            state.state = REJECTED;
            notify(state, true);
          };

          var internalResolve = function (state, value, unwrap) {
            if (state.done) return;
            state.done = true;
            if (unwrap) state = unwrap;

            try {
              if (state.facade === value) throw TypeError("Promise can't be resolved itself");
              var then = isThenable(value);

              if (then) {
                microtask(function () {
                  var wrapper = {
                    done: false
                  };

                  try {
                    call(then, value, bind(internalResolve, wrapper, state), bind(internalReject, wrapper, state));
                  } catch (error) {
                    internalReject(wrapper, error, state);
                  }
                });
              } else {
                state.value = value;
                state.state = FULFILLED;
                notify(state, false);
              }
            } catch (error) {
              internalReject({
                done: false
              }, error, state);
            }
          }; // constructor polyfill


          if (FORCED) {
            // 25.4.3.1 Promise(executor)
            PromiseConstructor = function Promise(executor) {
              anInstance(this, PromisePrototype);
              aCallable(executor);
              call(Internal, this);
              var state = getInternalState(this);

              try {
                executor(bind(internalResolve, state), bind(internalReject, state));
              } catch (error) {
                internalReject(state, error);
              }
            };

            PromisePrototype = PromiseConstructor.prototype; // eslint-disable-next-line no-unused-vars -- required for `.length`

            Internal = function Promise(executor) {
              setInternalState(this, {
                type: PROMISE,
                done: false,
                notified: false,
                parent: false,
                reactions: new Queue(),
                rejection: false,
                state: PENDING,
                value: undefined
              });
            };

            Internal.prototype = redefineAll(PromisePrototype, {
              // `Promise.prototype.then` method
              // https://tc39.es/ecma262/#sec-promise.prototype.then
              // eslint-disable-next-line unicorn/no-thenable -- safe
              then: function then(onFulfilled, onRejected) {
                var state = getInternalPromiseState(this);
                var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor));
                state.parent = true;
                reaction.ok = isCallable(onFulfilled) ? onFulfilled : true;
                reaction.fail = isCallable(onRejected) && onRejected;
                reaction.domain = IS_NODE ? process.domain : undefined;
                if (state.state == PENDING) state.reactions.add(reaction);else microtask(function () {
                  callReaction(reaction, state);
                });
                return reaction.promise;
              },
              // `Promise.prototype.catch` method
              // https://tc39.es/ecma262/#sec-promise.prototype.catch
              'catch': function (onRejected) {
                return this.then(undefined, onRejected);
              }
            });

            OwnPromiseCapability = function () {
              var promise = new Internal();
              var state = getInternalState(promise);
              this.promise = promise;
              this.resolve = bind(internalResolve, state);
              this.reject = bind(internalReject, state);
            };

            newPromiseCapabilityModule.f = newPromiseCapability = function (C) {
              return C === PromiseConstructor || C === PromiseWrapper ? new OwnPromiseCapability(C) : newGenericPromiseCapability(C);
            };

            if (!IS_PURE && isCallable(NativePromise) && NativePromisePrototype !== Object.prototype) {
              nativeThen = NativePromisePrototype.then;

              if (!SUBCLASSING) {
                // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs
                redefine(NativePromisePrototype, 'then', function then(onFulfilled, onRejected) {
                  var that = this;
                  return new PromiseConstructor(function (resolve, reject) {
                    call(nativeThen, that, resolve, reject);
                  }).then(onFulfilled, onRejected); // https://github.com/zloirock/core-js/issues/640
                }, {
                  unsafe: true
                }); // makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then`

                redefine(NativePromisePrototype, 'catch', PromisePrototype['catch'], {
                  unsafe: true
                });
              } // make `.constructor === Promise` work for native promise-based APIs


              try {
                delete NativePromisePrototype.constructor;
              } catch (error) {
                /* empty */
              } // make `instanceof Promise` work for native promise-based APIs


              if (setPrototypeOf) {
                setPrototypeOf(NativePromisePrototype, PromisePrototype);
              }
            }
          }

          $({
            global: true,
            wrap: true,
            forced: FORCED
          }, {
            Promise: PromiseConstructor
          });
          setToStringTag(PromiseConstructor, PROMISE, false, true);
          setSpecies(PROMISE);
          PromiseWrapper = getBuiltIn(PROMISE); // statics

          $({
            target: PROMISE,
            stat: true,
            forced: FORCED
          }, {
            // `Promise.reject` method
            // https://tc39.es/ecma262/#sec-promise.reject
            reject: function reject(r) {
              var capability = newPromiseCapability(this);
              call(capability.reject, undefined, r);
              return capability.promise;
            }
          });
          $({
            target: PROMISE,
            stat: true,
            forced: IS_PURE || FORCED
          }, {
            // `Promise.resolve` method
            // https://tc39.es/ecma262/#sec-promise.resolve
            resolve: function resolve(x) {
              return promiseResolve(IS_PURE && this === PromiseWrapper ? PromiseConstructor : this, x);
            }
          });
          $({
            target: PROMISE,
            stat: true,
            forced: INCORRECT_ITERATION
          }, {
            // `Promise.all` method
            // https://tc39.es/ecma262/#sec-promise.all
            all: function all(iterable) {
              var C = this;
              var capability = newPromiseCapability(C);
              var resolve = capability.resolve;
              var reject = capability.reject;
              var result = perform(function () {
                var $promiseResolve = aCallable(C.resolve);
                var values = [];
                var counter = 0;
                var remaining = 1;
                iterate(iterable, function (promise) {
                  var index = counter++;
                  var alreadyCalled = false;
                  remaining++;
                  call($promiseResolve, C, promise).then(function (value) {
                    if (alreadyCalled) return;
                    alreadyCalled = true;
                    values[index] = value;
                    --remaining || resolve(values);
                  }, reject);
                });
                --remaining || resolve(values);
              });
              if (result.error) reject(result.value);
              return capability.promise;
            },
            // `Promise.race` method
            // https://tc39.es/ecma262/#sec-promise.race
            race: function race(iterable) {
              var C = this;
              var capability = newPromiseCapability(C);
              var reject = capability.reject;
              var result = perform(function () {
                var $promiseResolve = aCallable(C.resolve);
                iterate(iterable, function (promise) {
                  call($promiseResolve, C, promise).then(capability.resolve, reject);
                });
              });
              if (result.error) reject(result.value);
              return capability.promise;
            }
          });
        })();

        _export("default", _cjsExports = module.exports);
      });

      _export("__cjsMetaURL", __cjsMetaURL = _context.meta.url);
    }
  };
});
//# sourceMappingURL=es.promise.js.map