es6-promise.min.js
5.62 KB
!function(t){"use strict";function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function e(t){return"function"==typeof t}function r(t){H=t}function o(t){R=t}function i(){return function(){process.nextTick(f)}}function s(){return function(){G(f)}}function u(){var t=0,n=new Z(f),e=document.createTextNode("");return n.observe(e,{characterData:!0}),function(){e.data=t=++t%2}}function c(){var t=new MessageChannel;return t.port1.onmessage=f,function(){t.port2.postMessage(0)}}function a(){return function(){setTimeout(f,1)}}function f(){for(var t=0;Q>t;t+=2){var n=nt[t],e=nt[t+1];n(e),nt[t]=void 0,nt[t+1]=void 0}Q=0}function l(){try{var t=require,n=t("vertx");return G=n.runOnLoop||n.runOnContext,s()}catch(e){return a()}}function h(t,n){var e=this,r=new this.constructor(p);void 0===r[ot]&&Y(r);var o=e._state;if(o){var i=arguments[o-1];R(function(){P(o,r,i,e._result)})}else T(e,r,t,n);return r}function _(t){var n=this;if(t&&"object"==typeof t&&t.constructor===n)return t;var e=new n(p);return A(e,t),e}function p(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function y(){return new TypeError("A promises callback cannot return that same promise.")}function d(t){try{return t.then}catch(n){return ct.error=n,ct}}function m(t,n,e,r){try{t.call(n,e,r)}catch(o){return o}}function w(t,n,e){R(function(t){var r=!1,o=m(e,n,function(e){r||(r=!0,n!==e?A(t,e):j(t,e))},function(n){r||(r=!0,E(t,n))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,E(t,o))},t)}function b(t,n){n._state===st?j(t,n._result):n._state===ut?E(t,n._result):T(n,void 0,function(n){A(t,n)},function(n){E(t,n)})}function g(t,n,r){n.constructor===t.constructor&&r===et&&constructor.resolve===rt?b(t,n):r===ct?E(t,ct.error):void 0===r?j(t,n):e(r)?w(t,n,r):j(t,n)}function A(t,e){t===e?E(t,v()):n(e)?g(t,e,d(e)):j(t,e)}function S(t){t._onerror&&t._onerror(t._result),M(t)}function j(t,n){t._state===it&&(t._result=n,t._state=st,0!==t._subscribers.length&&R(M,t))}function E(t,n){t._state===it&&(t._state=ut,t._result=n,R(S,t))}function T(t,n,e,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=n,o[i+st]=e,o[i+ut]=r,0===i&&t._state&&R(M,t)}function M(t){var n=t._subscribers,e=t._state;if(0!==n.length){for(var r,o,i=t._result,s=0;s<n.length;s+=3)r=n[s],o=n[s+e],r?P(e,r,o,i):o(i);t._subscribers.length=0}}function C(){this.error=null}function O(t,n){try{return t(n)}catch(e){return at.error=e,at}}function P(t,n,r,o){var i,s,u,c,a=e(r);if(a){if(i=O(r,o),i===at?(c=!0,s=i.error,i=null):u=!0,n===i)return void E(n,y())}else i=o,u=!0;n._state!==it||(a&&u?A(n,i):c?E(n,s):t===st?j(n,i):t===ut&&E(n,i))}function x(t,n){try{n(function(n){A(t,n)},function(n){E(t,n)})}catch(e){E(t,e)}}function k(){return ft++}function Y(t){t[ot]=ft++,t._state=void 0,t._result=void 0,t._subscribers=[]}function q(t){return new vt(this,t).promise}function D(t){var n=this;return new n(J(t)?function(e,r){for(var o=t.length,i=0;o>i;i++)n.resolve(t[i]).then(e,r)}:function(t,n){n(new TypeError("You must pass an array to race."))})}function F(t){var n=this,e=new n(p);return E(e,t),e}function K(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function L(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function N(t){this[ot]=k(),this._result=this._state=void 0,this._subscribers=[],p!==t&&("function"!=typeof t&&K(),this instanceof N?x(this,t):L())}function U(t,n){this._instanceConstructor=t,this.promise=new t(p),this.promise[ot]||Y(this.promise),J(n)?(this._input=n,this.length=n.length,this._remaining=n.length,this._result=new Array(this.length),0===this.length?j(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&j(this.promise,this._result))):E(this.promise,W())}function W(){return new Error("Array Methods must be provided an Array")}var z=t.Promise;if(!z||"[object Promise]"!==Object.prototype.toString.call(z.resolve())||z.cast){var B;B=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var G,H,I,J=B,Q=0,R=function(t,n){nt[Q]=t,nt[Q+1]=n,Q+=2,2===Q&&(H?H(f):I())},V="undefined"!=typeof window?window:void 0,X=V||{},Z=X.MutationObserver||X.WebKitMutationObserver,$="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),tt="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,nt=new Array(1e3);I=$?i():Z?u():tt?c():void 0===V&&"function"==typeof require?l():a();var et=h,rt=_,ot=Math.random().toString(36).substring(16),it=void 0,st=1,ut=2,ct=new C,at=new C,ft=0,lt=q,ht=D,_t=F,pt=N;N.all=lt,N.race=ht,N.resolve=rt,N.reject=_t,N._setScheduler=r,N._setAsap=o,N._asap=R,N.prototype={constructor:N,then:et,"catch":function(t){return this.then(null,t)}};var vt=U;U.prototype._enumerate=function(){for(var t=this.length,n=this._input,e=0;this._state===it&&t>e;e++)this._eachEntry(n[e],e)},U.prototype._eachEntry=function(t,n){var e=this._instanceConstructor,r=e.resolve;if(r===rt){var o=d(t);if(o===et&&t._state!==it)this._settledAt(t._state,n,t._result);else if("function"!=typeof o)this._remaining--,this._result[n]=t;else if(e===pt){var i=new e(p);g(i,t,o),this._willSettleAt(i,n)}else this._willSettleAt(new e(function(n){n(t)}),n)}else this._willSettleAt(r(t),n)},U.prototype._settledAt=function(t,n,e){var r=this.promise;r._state===it&&(this._remaining--,t===ut?E(r,e):this._result[n]=e),0===this._remaining&&j(r,this._result)},U.prototype._willSettleAt=function(t,n){var e=this;T(t,void 0,function(t){e._settledAt(st,n,t)},function(t){e._settledAt(ut,n,t)})},t.Promise=pt}}(this);