2 * @overview es6-promise - a tiny implementation of Promises/A+.
3 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
4 * @license Licensed under MIT license
5 * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
11 function lib$es6$promise$utils$$objectOrFunction(x) {
12 return typeof x === 'function' || (typeof x === 'object' && x !== null);
15 function lib$es6$promise$utils$$isFunction(x) {
16 return typeof x === 'function';
19 function lib$es6$promise$utils$$isMaybeThenable(x) {
20 return typeof x === 'object' && x !== null;
23 var lib$es6$promise$utils$$_isArray;
25 lib$es6$promise$utils$$_isArray = function (x) {
26 return Object.prototype.toString.call(x) === '[object Array]';
29 lib$es6$promise$utils$$_isArray = Array.isArray;
32 var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
33 var lib$es6$promise$asap$$len = 0;
34 var lib$es6$promise$asap$$vertxNext;
35 var lib$es6$promise$asap$$customSchedulerFn;
37 var lib$es6$promise$asap$$asap = function asap(callback, arg) {
38 lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
39 lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
40 lib$es6$promise$asap$$len += 2;
41 if (lib$es6$promise$asap$$len === 2) {
42 // If len is 2, that means that we need to schedule an async flush.
43 // If additional callbacks are queued before the queue is flushed, they
44 // will be processed by this flush that we are scheduling.
45 if (lib$es6$promise$asap$$customSchedulerFn) {
46 lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
48 lib$es6$promise$asap$$scheduleFlush();
53 function lib$es6$promise$asap$$setScheduler(scheduleFn) {
54 lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
57 function lib$es6$promise$asap$$setAsap(asapFn) {
58 lib$es6$promise$asap$$asap = asapFn;
61 var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
62 var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
63 var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
64 var lib$es6$promise$asap$$isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
66 // test for web worker but not in IE10
67 var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
68 typeof importScripts !== 'undefined' &&
69 typeof MessageChannel !== 'undefined';
72 function lib$es6$promise$asap$$useNextTick() {
73 // node version 0.10.x displays a deprecation warning when nextTick is used recursively
74 // see https://github.com/cujojs/when/issues/410 for details
76 process.nextTick(lib$es6$promise$asap$$flush);
81 function lib$es6$promise$asap$$useVertxTimer() {
83 lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
87 function lib$es6$promise$asap$$useMutationObserver() {
89 var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
90 var node = document.createTextNode('');
91 observer.observe(node, { characterData: true });
94 node.data = (iterations = ++iterations % 2);
99 function lib$es6$promise$asap$$useMessageChannel() {
100 var channel = new MessageChannel();
101 channel.port1.onmessage = lib$es6$promise$asap$$flush;
103 channel.port2.postMessage(0);
107 function lib$es6$promise$asap$$useSetTimeout() {
109 setTimeout(lib$es6$promise$asap$$flush, 1);
113 var lib$es6$promise$asap$$queue = new Array(1000);
114 function lib$es6$promise$asap$$flush() {
115 for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
116 var callback = lib$es6$promise$asap$$queue[i];
117 var arg = lib$es6$promise$asap$$queue[i+1];
121 lib$es6$promise$asap$$queue[i] = undefined;
122 lib$es6$promise$asap$$queue[i+1] = undefined;
125 lib$es6$promise$asap$$len = 0;
128 function lib$es6$promise$asap$$attemptVertx() {
131 var vertx = r('vertx');
132 lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
133 return lib$es6$promise$asap$$useVertxTimer();
135 return lib$es6$promise$asap$$useSetTimeout();
139 var lib$es6$promise$asap$$scheduleFlush;
140 // Decide what async method to use to triggering processing of queued callbacks:
141 if (lib$es6$promise$asap$$isNode) {
142 lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
143 } else if (lib$es6$promise$asap$$BrowserMutationObserver) {
144 lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
145 } else if (lib$es6$promise$asap$$isWorker) {
146 lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
147 } else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
148 lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx();
150 lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
152 function lib$es6$promise$then$$then(onFulfillment, onRejection) {
155 var child = new this.constructor(lib$es6$promise$$internal$$noop);
157 if (child[lib$es6$promise$$internal$$PROMISE_ID] === undefined) {
158 lib$es6$promise$$internal$$makePromise(child);
161 var state = parent._state;
164 var callback = arguments[state - 1];
165 lib$es6$promise$asap$$asap(function(){
166 lib$es6$promise$$internal$$invokeCallback(state, child, callback, parent._result);
169 lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
174 var lib$es6$promise$then$$default = lib$es6$promise$then$$then;
175 function lib$es6$promise$promise$resolve$$resolve(object) {
176 /*jshint validthis:true */
177 var Constructor = this;
179 if (object && typeof object === 'object' && object.constructor === Constructor) {
183 var promise = new Constructor(lib$es6$promise$$internal$$noop);
184 lib$es6$promise$$internal$$resolve(promise, object);
187 var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
188 var lib$es6$promise$$internal$$PROMISE_ID = Math.random().toString(36).substring(16);
190 function lib$es6$promise$$internal$$noop() {}
192 var lib$es6$promise$$internal$$PENDING = void 0;
193 var lib$es6$promise$$internal$$FULFILLED = 1;
194 var lib$es6$promise$$internal$$REJECTED = 2;
196 var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
198 function lib$es6$promise$$internal$$selfFulfillment() {
199 return new TypeError("You cannot resolve a promise with itself");
202 function lib$es6$promise$$internal$$cannotReturnOwn() {
203 return new TypeError('A promises callback cannot return that same promise.');
206 function lib$es6$promise$$internal$$getThen(promise) {
210 lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
211 return lib$es6$promise$$internal$$GET_THEN_ERROR;
215 function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
217 then.call(value, fulfillmentHandler, rejectionHandler);
223 function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
224 lib$es6$promise$asap$$asap(function(promise) {
226 var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
227 if (sealed) { return; }
229 if (thenable !== value) {
230 lib$es6$promise$$internal$$resolve(promise, value);
232 lib$es6$promise$$internal$$fulfill(promise, value);
234 }, function(reason) {
235 if (sealed) { return; }
238 lib$es6$promise$$internal$$reject(promise, reason);
239 }, 'Settle: ' + (promise._label || ' unknown promise'));
241 if (!sealed && error) {
243 lib$es6$promise$$internal$$reject(promise, error);
248 function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
249 if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
250 lib$es6$promise$$internal$$fulfill(promise, thenable._result);
251 } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
252 lib$es6$promise$$internal$$reject(promise, thenable._result);
254 lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
255 lib$es6$promise$$internal$$resolve(promise, value);
256 }, function(reason) {
257 lib$es6$promise$$internal$$reject(promise, reason);
262 function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable, then) {
263 if (maybeThenable.constructor === promise.constructor &&
264 then === lib$es6$promise$then$$default &&
265 constructor.resolve === lib$es6$promise$promise$resolve$$default) {
266 lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
268 if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
269 lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
270 } else if (then === undefined) {
271 lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
272 } else if (lib$es6$promise$utils$$isFunction(then)) {
273 lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
275 lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
280 function lib$es6$promise$$internal$$resolve(promise, value) {
281 if (promise === value) {
282 lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFulfillment());
283 } else if (lib$es6$promise$utils$$objectOrFunction(value)) {
284 lib$es6$promise$$internal$$handleMaybeThenable(promise, value, lib$es6$promise$$internal$$getThen(value));
286 lib$es6$promise$$internal$$fulfill(promise, value);
290 function lib$es6$promise$$internal$$publishRejection(promise) {
291 if (promise._onerror) {
292 promise._onerror(promise._result);
295 lib$es6$promise$$internal$$publish(promise);
298 function lib$es6$promise$$internal$$fulfill(promise, value) {
299 if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
301 promise._result = value;
302 promise._state = lib$es6$promise$$internal$$FULFILLED;
304 if (promise._subscribers.length !== 0) {
305 lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
309 function lib$es6$promise$$internal$$reject(promise, reason) {
310 if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
311 promise._state = lib$es6$promise$$internal$$REJECTED;
312 promise._result = reason;
314 lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
317 function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
318 var subscribers = parent._subscribers;
319 var length = subscribers.length;
321 parent._onerror = null;
323 subscribers[length] = child;
324 subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
325 subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
327 if (length === 0 && parent._state) {
328 lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
332 function lib$es6$promise$$internal$$publish(promise) {
333 var subscribers = promise._subscribers;
334 var settled = promise._state;
336 if (subscribers.length === 0) { return; }
338 var child, callback, detail = promise._result;
340 for (var i = 0; i < subscribers.length; i += 3) {
341 child = subscribers[i];
342 callback = subscribers[i + settled];
345 lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
351 promise._subscribers.length = 0;
354 function lib$es6$promise$$internal$$ErrorObject() {
358 var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
360 function lib$es6$promise$$internal$$tryCatch(callback, detail) {
362 return callback(detail);
364 lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
365 return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
369 function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
370 var hasCallback = lib$es6$promise$utils$$isFunction(callback),
371 value, error, succeeded, failed;
374 value = lib$es6$promise$$internal$$tryCatch(callback, detail);
376 if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
384 if (promise === value) {
385 lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
394 if (promise._state !== lib$es6$promise$$internal$$PENDING) {
396 } else if (hasCallback && succeeded) {
397 lib$es6$promise$$internal$$resolve(promise, value);
399 lib$es6$promise$$internal$$reject(promise, error);
400 } else if (settled === lib$es6$promise$$internal$$FULFILLED) {
401 lib$es6$promise$$internal$$fulfill(promise, value);
402 } else if (settled === lib$es6$promise$$internal$$REJECTED) {
403 lib$es6$promise$$internal$$reject(promise, value);
407 function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
409 resolver(function resolvePromise(value){
410 lib$es6$promise$$internal$$resolve(promise, value);
411 }, function rejectPromise(reason) {
412 lib$es6$promise$$internal$$reject(promise, reason);
415 lib$es6$promise$$internal$$reject(promise, e);
419 var lib$es6$promise$$internal$$id = 0;
420 function lib$es6$promise$$internal$$nextId() {
421 return lib$es6$promise$$internal$$id++;
424 function lib$es6$promise$$internal$$makePromise(promise) {
425 promise[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$id++;
426 promise._state = undefined;
427 promise._result = undefined;
428 promise._subscribers = [];
431 function lib$es6$promise$promise$all$$all(entries) {
432 return new lib$es6$promise$enumerator$$default(this, entries).promise;
434 var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
435 function lib$es6$promise$promise$race$$race(entries) {
436 /*jshint validthis:true */
437 var Constructor = this;
439 if (!lib$es6$promise$utils$$isArray(entries)) {
440 return new Constructor(function(resolve, reject) {
441 reject(new TypeError('You must pass an array to race.'));
444 return new Constructor(function(resolve, reject) {
445 var length = entries.length;
446 for (var i = 0; i < length; i++) {
447 Constructor.resolve(entries[i]).then(resolve, reject);
452 var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
453 function lib$es6$promise$promise$reject$$reject(reason) {
454 /*jshint validthis:true */
455 var Constructor = this;
456 var promise = new Constructor(lib$es6$promise$$internal$$noop);
457 lib$es6$promise$$internal$$reject(promise, reason);
460 var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
463 function lib$es6$promise$promise$$needsResolver() {
464 throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
467 function lib$es6$promise$promise$$needsNew() {
468 throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
471 var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
473 Promise objects represent the eventual result of an asynchronous operation. The
474 primary way of interacting with a promise is through its `then` method, which
475 registers callbacks to receive either a promise's eventual value or the reason
476 why the promise cannot be fulfilled.
481 - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
482 - `thenable` is an object or function that defines a `then` method.
483 - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
484 - `exception` is a value that is thrown using the throw statement.
485 - `reason` is a value that indicates why a promise was rejected.
486 - `settled` the final resting state of a promise, fulfilled or rejected.
488 A promise can be in one of three states: pending, fulfilled, or rejected.
490 Promises that are fulfilled have a fulfillment value and are in the fulfilled
491 state. Promises that are rejected have a rejection reason and are in the
492 rejected state. A fulfillment value is never a thenable.
494 Promises can also be said to *resolve* a value. If this value is also a
495 promise, then the original promise's settled state will match the value's
496 settled state. So a promise that *resolves* a promise that rejects will
497 itself reject, and a promise that *resolves* a promise that fulfills will
505 var promise = new Promise(function(resolve, reject) {
513 promise.then(function(value) {
515 }, function(reason) {
523 Promises shine when abstracting away asynchronous interactions such as
527 function getJSON(url) {
528 return new Promise(function(resolve, reject){
529 var xhr = new XMLHttpRequest();
531 xhr.open('GET', url);
532 xhr.onreadystatechange = handler;
533 xhr.responseType = 'json';
534 xhr.setRequestHeader('Accept', 'application/json');
538 if (this.readyState === this.DONE) {
539 if (this.status === 200) {
540 resolve(this.response);
542 reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
549 getJSON('/posts.json').then(function(json) {
551 }, function(reason) {
556 Unlike callbacks, promises are great composable primitives.
562 ]).then(function(values){
563 values[0] // => postsJSON
564 values[1] // => commentsJSON
571 @param {function} resolver
575 function lib$es6$promise$promise$$Promise(resolver) {
576 this[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$nextId();
577 this._result = this._state = undefined;
578 this._subscribers = [];
580 if (lib$es6$promise$$internal$$noop !== resolver) {
581 typeof resolver !== 'function' && lib$es6$promise$promise$$needsResolver();
582 this instanceof lib$es6$promise$promise$$Promise ? lib$es6$promise$$internal$$initializePromise(this, resolver) : lib$es6$promise$promise$$needsNew();
586 lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
587 lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
588 lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
589 lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
590 lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
591 lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
592 lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
594 lib$es6$promise$promise$$Promise.prototype = {
595 constructor: lib$es6$promise$promise$$Promise,
598 The primary way of interacting with a promise is through its `then` method,
599 which registers callbacks to receive either a promise's eventual value or the
600 reason why the promise cannot be fulfilled.
603 findUser().then(function(user){
606 // user is unavailable, and you are given the reason why
613 The return value of `then` is itself a promise. This second, 'downstream'
614 promise is resolved with the return value of the first promise's fulfillment
615 or rejection handler, or rejected if the handler throws an exception.
618 findUser().then(function (user) {
620 }, function (reason) {
621 return 'default name';
622 }).then(function (userName) {
623 // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
624 // will be `'default name'`
627 findUser().then(function (user) {
628 throw new Error('Found user, but still unhappy');
629 }, function (reason) {
630 throw new Error('`findUser` rejected and we're unhappy');
631 }).then(function (value) {
633 }, function (reason) {
634 // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
635 // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
638 If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
641 findUser().then(function (user) {
642 throw new PedagogicalException('Upstream error');
643 }).then(function (value) {
645 }).then(function (value) {
647 }, function (reason) {
648 // The `PedgagocialException` is propagated all the way down to here
655 Sometimes the value you want to propagate to a downstream promise can only be
656 retrieved asynchronously. This can be achieved by returning a promise in the
657 fulfillment or rejection handler. The downstream promise will then be pending
658 until the returned promise is settled. This is called *assimilation*.
661 findUser().then(function (user) {
662 return findCommentsByAuthor(user);
663 }).then(function (comments) {
664 // The user's comments are now available
668 If the assimliated promise rejects, then the downstream promise will also reject.
671 findUser().then(function (user) {
672 return findCommentsByAuthor(user);
673 }).then(function (comments) {
674 // If `findCommentsByAuthor` fulfills, we'll have the value here
675 }, function (reason) {
676 // If `findCommentsByAuthor` rejects, we'll have the reason here
689 result = findResult();
699 findResult(function(result, err){
711 findResult().then(function(result){
727 author = findAuthor();
728 books = findBooksByAuthor(author);
739 function foundBooks(books) {
743 function failure(reason) {
747 findAuthor(function(author, err){
753 findBoooksByAuthor(author, function(books, err) {
776 then(findBooksByAuthor).
777 then(function(books){
779 }).catch(function(reason){
780 // something went wrong
785 @param {Function} onFulfilled
786 @param {Function} onRejected
790 then: lib$es6$promise$then$$default,
793 `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
794 as the catch block of a try/catch statement.
797 function findAuthor(){
798 throw new Error('couldn't find that author');
805 // something went wrong
808 // async with promises
809 findAuthor().catch(function(reason){
810 // something went wrong
815 @param {Function} onRejection
819 'catch': function(onRejection) {
820 return this.then(null, onRejection);
823 var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
824 function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
825 this._instanceConstructor = Constructor;
826 this.promise = new Constructor(lib$es6$promise$$internal$$noop);
828 if (!this.promise[lib$es6$promise$$internal$$PROMISE_ID]) {
829 lib$es6$promise$$internal$$makePromise(this.promise);
832 if (lib$es6$promise$utils$$isArray(input)) {
834 this.length = input.length;
835 this._remaining = input.length;
837 this._result = new Array(this.length);
839 if (this.length === 0) {
840 lib$es6$promise$$internal$$fulfill(this.promise, this._result);
842 this.length = this.length || 0;
844 if (this._remaining === 0) {
845 lib$es6$promise$$internal$$fulfill(this.promise, this._result);
849 lib$es6$promise$$internal$$reject(this.promise, lib$es6$promise$enumerator$$validationError());
853 function lib$es6$promise$enumerator$$validationError() {
854 return new Error('Array Methods must be provided an Array');
857 lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
858 var length = this.length;
859 var input = this._input;
861 for (var i = 0; this._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
862 this._eachEntry(input[i], i);
866 lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
867 var c = this._instanceConstructor;
868 var resolve = c.resolve;
870 if (resolve === lib$es6$promise$promise$resolve$$default) {
871 var then = lib$es6$promise$$internal$$getThen(entry);
873 if (then === lib$es6$promise$then$$default &&
874 entry._state !== lib$es6$promise$$internal$$PENDING) {
875 this._settledAt(entry._state, i, entry._result);
876 } else if (typeof then !== 'function') {
878 this._result[i] = entry;
879 } else if (c === lib$es6$promise$promise$$default) {
880 var promise = new c(lib$es6$promise$$internal$$noop);
881 lib$es6$promise$$internal$$handleMaybeThenable(promise, entry, then);
882 this._willSettleAt(promise, i);
884 this._willSettleAt(new c(function(resolve) { resolve(entry); }), i);
887 this._willSettleAt(resolve(entry), i);
891 lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
892 var promise = this.promise;
894 if (promise._state === lib$es6$promise$$internal$$PENDING) {
897 if (state === lib$es6$promise$$internal$$REJECTED) {
898 lib$es6$promise$$internal$$reject(promise, value);
900 this._result[i] = value;
904 if (this._remaining === 0) {
905 lib$es6$promise$$internal$$fulfill(promise, this._result);
909 lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
910 var enumerator = this;
912 lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
913 enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
914 }, function(reason) {
915 enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
918 function lib$es6$promise$polyfill$$polyfill() {
921 if (typeof global !== 'undefined') {
923 } else if (typeof self !== 'undefined') {
927 local = Function('return this')();
929 throw new Error('polyfill failed because global object is unavailable in this environment');
933 var P = local.Promise;
935 if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
939 local.Promise = lib$es6$promise$promise$$default;
941 var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
943 var lib$es6$promise$umd$$ES6Promise = {
944 'Promise': lib$es6$promise$promise$$default,
945 'polyfill': lib$es6$promise$polyfill$$default
948 /* global define:true module:true window: true */
949 if (typeof define === 'function' && define['amd']) {
950 define(function() { return lib$es6$promise$umd$$ES6Promise; });
951 } else if (typeof module !== 'undefined' && module['exports']) {
952 module['exports'] = lib$es6$promise$umd$$ES6Promise;
953 } else if (typeof this !== 'undefined') {
954 this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
957 lib$es6$promise$polyfill$$default();