es6-promise.js 9.05 KB
// github: https://github.com/stefanpenner/es6-promise
// update: https://wzrd.in/standalone/es6-promise@latest

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.es6Promise=t()}}(function(){var t;return function t(e,n,r){function o(u,s){if(!n[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var a=n[u]={exports:{}};e[u][0].call(a.exports,function(t){var n=e[u][1][t];return o(n?n:t)},a,a.exports,t,e,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(t,e,n){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(t){if(l===setTimeout)return setTimeout(t,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(t,0);try{return l(t,0)}catch(e){try{return l.call(null,t,0)}catch(e){return l.call(this,t,0)}}}function u(t){if(h===clearTimeout)return clearTimeout(t);if((h===o||!h)&&clearTimeout)return h=clearTimeout,clearTimeout(t);try{return h(t)}catch(e){try{return h.call(null,t)}catch(e){return h.call(this,t)}}}function s(){y&&p&&(y=!1,p.length?v=p.concat(v):_=-1,v.length&&c())}function c(){if(!y){var t=i(s);y=!0;for(var e=v.length;e;){for(p=v,v=[];++_<e;)p&&p[_].run();_=-1,e=v.length}p=null,y=!1,u(t)}}function f(t,e){this.fun=t,this.array=e}function a(){}var l,h,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:r}catch(t){l=r}try{h="function"==typeof clearTimeout?clearTimeout:o}catch(t){h=o}}();var p,v=[],y=!1,_=-1;d.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];v.push(new f(t,e)),1!==v.length||y||i(c)},f.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=a,d.addListener=a,d.once=a,d.off=a,d.removeListener=a,d.removeAllListeners=a,d.emit=a,d.binding=function(t){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(t){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},{}],2:[function(e,n,r){(function(o,i){!function(e,o){"object"==typeof r&&"undefined"!=typeof n?n.exports=o():"function"==typeof t&&t.amd?t(o):e.ES6Promise=o()}(this,function(){"use strict";function t(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}function n(t){return"function"==typeof t}function r(t){J=t}function u(t){Q=t}function s(){return function(){return o.nextTick(h)}}function c(){return"undefined"!=typeof I?function(){I(h)}:l()}function f(){var t=0,e=new X(h),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function a(){var t=new MessageChannel;return t.port1.onmessage=h,function(){return t.port2.postMessage(0)}}function l(){var t=setTimeout;return function(){return t(h,1)}}function h(){for(var t=0;t<H;t+=2){var e=tt[t],n=tt[t+1];e(n),tt[t]=void 0,tt[t+1]=void 0}H=0}function d(){try{var t=e,n=t("vertx");return I=n.runOnLoop||n.runOnContext,c()}catch(t){return l()}}function p(t,e){var n=this,r=new this.constructor(y);void 0===r[nt]&&D(r);var o=n._state;if(o){var i=arguments[o-1];Q(function(){return k(o,r,i,n._result)})}else M(n,r,t,e);return r}function v(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(y);return E(n,t),n}function y(){}function _(){return new TypeError("You cannot resolve a promise with itself")}function m(){return new TypeError("A promises callback cannot return that same promise.")}function w(t){try{return t.then}catch(t){return ut.error=t,ut}}function b(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function g(t,e,n){Q(function(t){var r=!1,o=b(n,e,function(n){r||(r=!0,e!==n?E(t,n):j(t,n))},function(e){r||(r=!0,S(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,S(t,o))},t)}function T(t,e){e._state===ot?j(t,e._result):e._state===it?S(t,e._result):M(e,void 0,function(e){return E(t,e)},function(e){return S(t,e)})}function A(t,e,r){e.constructor===t.constructor&&r===p&&e.constructor.resolve===v?T(t,e):r===ut?(S(t,ut.error),ut.error=null):void 0===r?j(t,e):n(r)?g(t,e,r):j(t,e)}function E(e,n){e===n?S(e,_()):t(n)?A(e,n,w(n)):j(e,n)}function x(t){t._onerror&&t._onerror(t._result),O(t)}function j(t,e){t._state===rt&&(t._result=e,t._state=ot,0!==t._subscribers.length&&Q(O,t))}function S(t,e){t._state===rt&&(t._state=it,t._result=e,Q(x,t))}function M(t,e,n,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=e,o[i+ot]=n,o[i+it]=r,0===i&&t._state&&Q(O,t)}function O(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,o=void 0,i=t._result,u=0;u<e.length;u+=3)r=e[u],o=e[u+n],r?k(n,r,o,i):o(i);t._subscribers.length=0}}function P(){this.error=null}function C(t,e){try{return t(e)}catch(t){return st.error=t,st}}function k(t,e,r,o){var i=n(r),u=void 0,s=void 0,c=void 0,f=void 0;if(i){if(u=C(r,o),u===st?(f=!0,s=u.error,u.error=null):c=!0,e===u)return void S(e,m())}else u=o,c=!0;e._state!==rt||(i&&c?E(e,u):f?S(e,s):t===ot?j(e,u):t===it&&S(e,u))}function L(t,e){try{e(function(e){E(t,e)},function(e){S(t,e)})}catch(e){S(t,e)}}function q(){return ct++}function D(t){t[nt]=ct++,t._state=void 0,t._result=void 0,t._subscribers=[]}function F(){return new Error("Array Methods must be provided an Array")}function F(){return new Error("Array Methods must be provided an Array")}function N(t){return new ft(this,t).promise}function U(t){var e=this;return new e(G(t)?function(n,r){for(var o=t.length,i=0;i<o;i++)e.resolve(t[i]).then(n,r)}:function(t,e){return e(new TypeError("You must pass an array to race."))})}function Y(t){var e=this,n=new e(y);return S(n,t),n}function K(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function W(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function z(){var t=void 0;if("undefined"!=typeof i)t=i;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=at}var B=void 0;B=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var G=B,H=0,I=void 0,J=void 0,Q=function(t,e){tt[H]=t,tt[H+1]=e,H+=2,2===H&&(J?J(h):et())},R="undefined"!=typeof window?window:void 0,V=R||{},X=V.MutationObserver||V.WebKitMutationObserver,Z="undefined"==typeof self&&"undefined"!=typeof o&&"[object process]"==={}.toString.call(o),$="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,tt=new Array(1e3),et=void 0;et=Z?s():X?f():$?a():void 0===R&&"function"==typeof e?d():l();var nt=Math.random().toString(36).substring(16),rt=void 0,ot=1,it=2,ut=new P,st=new P,ct=0,ft=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(y),this.promise[nt]||D(this.promise),G(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?j(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&j(this.promise,this._result))):S(this.promise,F())}return t.prototype._enumerate=function(t){for(var e=0;this._state===rt&&e<t.length;e++)this._eachEntry(t[e],e)},t.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===v){var o=w(t);if(o===p&&t._state!==rt)this._settledAt(t._state,e,t._result);else if("function"!=typeof o)this._remaining--,this._result[e]=t;else if(n===at){var i=new n(y);A(i,t,o),this._willSettleAt(i,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(r(t),e)},t.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===rt&&(this._remaining--,t===it?S(r,n):this._result[e]=n),0===this._remaining&&j(r,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;M(t,void 0,function(t){return n._settledAt(ot,e,t)},function(t){return n._settledAt(it,e,t)})},t}(),at=function(){function t(e){this[nt]=q(),this._result=this._state=void 0,this._subscribers=[],y!==e&&("function"!=typeof e&&K(),this instanceof t?L(this,e):W())}return t.prototype.catch=function(t){return this.then(null,t)},t.prototype.finally=function(t){var e=this,n=e.constructor;return e.then(function(e){return n.resolve(t()).then(function(){return e})},function(e){return n.resolve(t()).then(function(){throw e})})},t}();return at.prototype.then=p,at.all=N,at.race=U,at.resolve=v,at.reject=Y,at._setScheduler=r,at._setAsap=u,at._asap=Q,at.polyfill=z,at.Promise=at,at})}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:1}]},{},[2])(2)});