OLD | NEW |
---|---|
(Empty) | |
1 /*! | |
2 * @overview es6-promise - a tiny implementation of Promises/A+. | |
3 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contri butors (Conversion to ES6 API by Jake Archibald) | |
jrobbins
2015/04/16 18:09:27
I was going to say that this needs to be under thi
nodir
2015/04/16 18:15:11
Acknowledged.
| |
4 * @license Licensed under MIT license | |
5 * See https://raw.githubusercontent.com/jakearchibald/es6-promise/ma ster/LICENSE | |
6 * @version 2.0.0 | |
7 */ | |
8 | |
9 (function(){function r(a,b){n[l]=a;n[l+1]=b;l+=2;2===l&&A()}function s(a){return "function"===typeof a}function F(){return function(){process.nextTick(t)}}functi on G(){var a=0,b=new B(t),c=document.createTextNode("");b.observe(c,{characterDa ta:!0});return function(){c.data=a=++a%2}}function H(){var a=new MessageChannel; a.port1.onmessage=t;return function(){a.port2.postMessage(0)}}function I(){retur n function(){setTimeout(t,1)}}function t(){for(var a=0;a<l;a+=2)(0,n[a])(n[a+1]) ,n[a]=void 0,n[a+1]=void 0; | |
10 l=0}function p(){}function J(a,b,c,d){try{a.call(b,c,d)}catch(e){return e}}funct ion K(a,b,c){r(function(a){var e=!1,f=J(c,b,function(c){e||(e=!0,b!==c?q(a,c):m( a,c))},function(b){e||(e=!0,g(a,b))});!e&&f&&(e=!0,g(a,f))},a)}function L(a,b){1 ===b.a?m(a,b.b):2===a.a?g(a,b.b):u(b,void 0,function(b){q(a,b)},function(b){g(a, b)})}function q(a,b){if(a===b)g(a,new TypeError("You cannot resolve a promise wi th itself"));else if("function"===typeof b||"object"===typeof b&&null!==b)if(b.c onstructor===a.constructor)L(a, | |
11 b);else{var c;try{c=b.then}catch(d){v.error=d,c=v}c===v?g(a,v.error):void 0===c? m(a,b):s(c)?K(a,b,c):m(a,b)}else m(a,b)}function M(a){a.f&&a.f(a.b);x(a)}functio n m(a,b){void 0===a.a&&(a.b=b,a.a=1,0!==a.e.length&&r(x,a))}function g(a,b){void 0===a.a&&(a.a=2,a.b=b,r(M,a))}function u(a,b,c,d){var e=a.e,f=e.length;a.f=null ;e[f]=b;e[f+1]=c;e[f+2]=d;0===f&&a.a&&r(x,a)}function x(a){var b=a.e,c=a.a;if(0! ==b.length){for(var d,e,f=a.b,g=0;g<b.length;g+=3)d=b[g],e=b[g+c],d?C(c,d,e,f):e (f);a.e.length=0}}function D(){this.error= | |
12 null}function C(a,b,c,d){var e=s(c),f,k,h,l;if(e){try{f=c(d)}catch(n){y.error=n, f=y}f===y?(l=!0,k=f.error,f=null):h=!0;if(b===f){g(b,new TypeError("A promises c allback cannot return that same promise."));return}}else f=d,h=!0;void 0===b.a&& (e&&h?q(b,f):l?g(b,k):1===a?m(b,f):2===a&&g(b,f))}function N(a,b){try{b(function (b){q(a,b)},function(b){g(a,b)})}catch(c){g(a,c)}}function k(a,b,c,d){this.n=a;t his.c=new a(p,d);this.i=c;this.o(b)?(this.m=b,this.d=this.length=b.length,this.l (),0===this.length?m(this.c, | |
13 this.b):(this.length=this.length||0,this.k(),0===this.d&&m(this.c,this.b))):g(th is.c,this.p())}function h(a){O++;this.b=this.a=void 0;this.e=[];if(p!==a){if(!s( a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof h))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");N(this,a)}}var E=Array.isArray?Array.isArray:f unction(a){return"[object Array]"=== | |
14 Object.prototype.toString.call(a)},l=0,w="undefined"!==typeof window?window:{},B =w.MutationObserver||w.WebKitMutationObserver,w="undefined"!==typeof Uint8Clampe dArray&&"undefined"!==typeof importScripts&&"undefined"!==typeof MessageChannel, n=Array(1E3),A;A="undefined"!==typeof process&&"[object process]"==={}.toString. call(process)?F():B?G():w?H():I();var v=new D,y=new D;k.prototype.o=function(a){ return E(a)};k.prototype.p=function(){return Error("Array Methods must be provid ed an Array")};k.prototype.l= | |
15 function(){this.b=Array(this.length)};k.prototype.k=function(){for(var a=this.le ngth,b=this.c,c=this.m,d=0;void 0===b.a&&d<a;d++)this.j(c[d],d)};k.prototype.j=f unction(a,b){var c=this.n;"object"===typeof a&&null!==a?a.constructor===c&&void 0!==a.a?(a.f=null,this.g(a.a,b,a.b)):this.q(c.resolve(a),b):(this.d--,this.b[b]= this.h(a))};k.prototype.g=function(a,b,c){var d=this.c;void 0===d.a&&(this.d--,t his.i&&2===a?g(d,c):this.b[b]=this.h(c));0===this.d&&m(d,this.b)};k.prototype.h= function(a){return a}; | |
16 k.prototype.q=function(a,b){var c=this;u(a,void 0,function(a){c.g(1,b,a)},functi on(a){c.g(2,b,a)})};var O=0;h.all=function(a,b){return(new k(this,a,!0,b)).c};h. race=function(a,b){function c(a){q(e,a)}function d(a){g(e,a)}var e=new this(p,b) ;if(!E(a))return (g(e,new TypeError("You must pass an array to race.")), e);for( var f=a.length,h=0;void 0===e.a&&h<f;h++)u(this.resolve(a[h]),void 0,c,d);return e};h.resolve=function(a,b){if(a&&"object"===typeof a&&a.constructor===this)retu rn a;var c=new this(p,b); | |
17 q(c,a);return c};h.reject=function(a,b){var c=new this(p,b);g(c,a);return c};h.p rototype={constructor:h,then:function(a,b){var c=this.a;if(1===c&&!a||2===c&&!b) return this;var d=new this.constructor(p),e=this.b;if(c){var f=arguments[c-1];r( function(){C(c,d,f,e)})}else u(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}};var z={Promise:h,polyfill:function(){var a;a="undefined"!==t ypeof global?global:"undefined"!==typeof window&&window.document?window:self;"Pr omise"in a&&"resolve"in | |
18 a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function (){var b;new a.Promise(function(a){b=a});return s(b)}()||(a.Promise=h)}};"functi on"===typeof define&&define.amd?define(function(){return z}):"undefined"!==typeo f module&&module.exports?module.exports=z:"undefined"!==typeof this&&(this.ES6Pr omise=z)}).call(this); | |
OLD | NEW |