Comparing version 0.3.4 to 0.3.5
239
p.js
@@ -7,2 +7,3 @@ /*! | ||
* High-priority-tasks code-portion based on https://github.com/kriskowal/asap | ||
* Long-Stack-Support code-portion based on https://github.com/kriskowal/q | ||
*/ | ||
@@ -25,2 +26,87 @@ ;(function( factory ){ | ||
var pStartingLine = captureLine(), | ||
pFileName, | ||
currentTrace = null; | ||
function getFileNameAndLineNumber( stackLine ) { | ||
var m = | ||
/at .+ \((.+):(\d+):(?:\d+)\)$/.exec( stackLine ) || | ||
/at ([^ ]+):(\d+):(?:\d+)$/.exec( stackLine ) || | ||
/.*@(.+):(\d+)$/.exec( stackLine ); | ||
return m ? { fileName: m[1], lineNumber: Number(m[2]) } : null; | ||
} | ||
function captureLine() { | ||
var stack = new Error().stack; | ||
if ( !stack ) { | ||
return 0; | ||
} | ||
var lines = stack.split("\n"); | ||
var firstLine = lines[0].indexOf("@") > 0 ? lines[1] : lines[2]; | ||
var pos = getFileNameAndLineNumber( firstLine ); | ||
if ( !pos ) { | ||
return 0; | ||
} | ||
pFileName = pos.fileName; | ||
return pos.lineNumber; | ||
} | ||
function filterStackString( stack, ignoreFirstLines ) { | ||
var lines = stack.split("\n"); | ||
var goodLines = []; | ||
for ( var i = ignoreFirstLines|0, l = lines.length; i < l; ++i ) { | ||
var line = lines[i]; | ||
if ( line && !isNodeFrame(line) && !isInternalFrame(line) ) { | ||
goodLines.push( line ); | ||
} | ||
} | ||
return goodLines.join("\n"); | ||
} | ||
function isNodeFrame( stackLine ) { | ||
return stackLine.indexOf("(module.js:") !== -1 || | ||
stackLine.indexOf("(node.js:") !== -1; | ||
} | ||
function isInternalFrame( stackLine ) { | ||
var pos = getFileNameAndLineNumber( stackLine ); | ||
return !!pos && | ||
pos.fileName === pFileName && | ||
pos.lineNumber >= pStartingLine && | ||
pos.lineNumber <= pEndingLine; | ||
} | ||
var STACK_JUMP_SEPARATOR = "\nFrom previous event:\n"; | ||
function makeStackTraceLong( error ) { | ||
if ( | ||
error instanceof Error && | ||
error.stack && | ||
error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1 | ||
) { | ||
var stacks = [ filterStackString( error.stack, 0 ) ]; | ||
var trace = currentTrace; | ||
var limit = 512; | ||
while ( trace && --limit ) { | ||
var stack = trace.stack && filterStackString( trace.stack, 2 ); | ||
if ( stack ) { | ||
stacks.push( stack ); | ||
} | ||
trace = trace.parent; | ||
} | ||
var longStack = stacks.join(STACK_JUMP_SEPARATOR); | ||
error.stack = longStack; | ||
} | ||
} | ||
//__________________________________________________________________________ | ||
var | ||
@@ -60,5 +146,6 @@ isNodeJS = ot(typeof process) && process != null && | ||
this.task = null; | ||
this.domain = null; | ||
this.a = null; | ||
this.b = null; | ||
this.domain = null; | ||
this.trace = null; | ||
this.next = null; | ||
@@ -80,3 +167,2 @@ } | ||
head = head.next; | ||
var task = head.task; | ||
@@ -89,8 +175,10 @@ if ( nFreeTaskNodes >= 1024 ) { | ||
currentTrace = head.trace; | ||
if ( head.domain ) { | ||
runInDomain( head.domain, task, head.a, head.b, void 0 ); | ||
runInDomain( head.domain, head.task, head.a, head.b, void 0 ); | ||
head.domain = null; | ||
} else { | ||
task( head.a, head.b ); | ||
(1,head.task)( head.a, head.b ); | ||
} | ||
@@ -101,5 +189,7 @@ | ||
head.b = null; | ||
head.trace = null; | ||
} | ||
flushing = false; | ||
currentTrace = null; | ||
} | ||
@@ -109,5 +199,6 @@ | ||
head.task = null; | ||
head.domain = null; | ||
head.a = null; | ||
head.b = null; | ||
head.domain = null; | ||
head.trace = null; | ||
requestFlush(); | ||
@@ -125,3 +216,14 @@ } | ||
function queueTask( setDomain, task, a, b ) { | ||
function queueTask( task, a, b ) { | ||
var domain = isNodeJS ? process.domain : null; | ||
var trace = P.longStackSupport ? { | ||
parent: currentTrace, | ||
stack: new Error().stack | ||
} : null; | ||
queueTask_( task, a, b, domain, trace ); | ||
} | ||
function queueTask_( task, a, b, domain, trace ) { | ||
var node = tail.next; | ||
@@ -142,7 +244,5 @@ | ||
node.b = b; | ||
node.domain = domain; | ||
node.trace = trace; | ||
if ( setDomain && isNodeJS ) { | ||
node.domain = process.domain; | ||
} | ||
if ( !flushing ) { | ||
@@ -223,3 +323,3 @@ flushing = true; | ||
function asap( task ) { | ||
queueTask( true, tryCall, task, handleError ); | ||
queueTask( tryCall, task, handleError ); | ||
} | ||
@@ -259,11 +359,30 @@ | ||
function Settle( p, state, value ) { | ||
P.longStackSupport = false; | ||
function Fulfill( p, value ) { | ||
if ( p._state ) { | ||
return p; | ||
return; | ||
} | ||
p._state = state; | ||
p._state = FULFILLED; | ||
p._value = value; | ||
if ( state === REJECTED && isNodeJS ) { | ||
if ( p._pending ) { | ||
EnqueuePending( p ); | ||
} | ||
} | ||
function Reject( p, reason ) { | ||
if ( p._state ) { | ||
return; | ||
} | ||
if ( currentTrace ) { | ||
makeStackTraceLong( reason ); | ||
} | ||
p._state = REJECTED; | ||
p._value = reason; | ||
if ( isNodeJS ) { | ||
p._domain = process.domain; | ||
@@ -273,6 +392,4 @@ } | ||
if ( p._pending ) { | ||
QueueChildren( p ); | ||
EnqueuePending( p ); | ||
} | ||
return p; | ||
} | ||
@@ -282,3 +399,3 @@ | ||
if ( p._state ) { | ||
return p; | ||
return; | ||
} | ||
@@ -291,6 +408,4 @@ | ||
if ( p._pending ) { | ||
QueueChildren( p ); | ||
EnqueuePending( p ); | ||
} | ||
return p; | ||
} | ||
@@ -305,3 +420,3 @@ | ||
if ( x === p ) { | ||
Settle( p, REJECTED, new TypeError("You can't resolve a promise with itself") ); | ||
Reject( p, new TypeError("You can't resolve a promise with itself") ); | ||
@@ -316,3 +431,3 @@ } else if ( x._state ) { | ||
} else if ( x !== Object(x) ) { | ||
Settle( p, FULFILLED, x ); | ||
Fulfill( p, x ); | ||
@@ -323,3 +438,3 @@ } else if ( sync ) { | ||
} else { | ||
queueTask( true, Assimilate, p, x ); | ||
queueTask( Assimilate, p, x ); | ||
} | ||
@@ -337,3 +452,3 @@ | ||
} catch ( e1 ) { | ||
Settle( p, REJECTED, e1 ); | ||
Reject( p, e1 ); | ||
return; | ||
@@ -353,7 +468,7 @@ } | ||
} else { | ||
Settle( p, FULFILLED, x ); | ||
Fulfill( p, x ); | ||
} | ||
} | ||
function QueueChildren( p ) { | ||
function EnqueuePending( p ) { | ||
var pending = p._pending; | ||
@@ -363,3 +478,3 @@ p._pending = null; | ||
if ( pending instanceof Promise ) { | ||
queueTask( false, Then, p, pending ); | ||
queueTask_( Then, p, pending, null, pending._trace ); | ||
return; | ||
@@ -369,3 +484,3 @@ } | ||
for ( var i = 0, l = pending.length; i < l; ++i ) { | ||
queueTask( false, Then, p, pending[i] ); | ||
queueTask_( Then, p, pending[i], null, pending[i]._trace ); | ||
} | ||
@@ -414,3 +529,3 @@ } | ||
} catch ( e ) { | ||
Settle( promise, REJECTED, e ); | ||
Reject( promise, e ); | ||
return; | ||
@@ -438,3 +553,3 @@ } | ||
done = true; | ||
Settle( promise, REJECTED, reason ); | ||
Reject( promise, reason ); | ||
} | ||
@@ -452,3 +567,5 @@ } | ||
function reject( reason ) { | ||
return Settle( new Promise(), REJECTED, reason ); | ||
var promise = new Promise(); | ||
Reject( promise, reason ); | ||
return promise; | ||
} | ||
@@ -463,2 +580,3 @@ | ||
this._pending = null; | ||
this._trace = null; | ||
} | ||
@@ -469,6 +587,15 @@ | ||
if ( P.longStackSupport ) { | ||
promise._trace = { | ||
parent: currentTrace, | ||
stack: new Error().stack | ||
}; | ||
} | ||
promise._cb = typeof onFulfilled === "function" ? onFulfilled : null; | ||
promise._eb = typeof onRejected === "function" ? onRejected : null; | ||
promise._domain = isNodeJS ? process.domain : null; | ||
if ( isNodeJS ) { | ||
promise._domain = process.domain; | ||
} | ||
@@ -479,3 +606,3 @@ if ( this._state === PENDING ) { | ||
} else { | ||
queueTask( false, Then, this, promise ); | ||
queueTask_( Then, this, promise, null, promise._trace ); | ||
} | ||
@@ -512,2 +639,15 @@ | ||
function _setTimeout( cb, ms ) { | ||
if ( currentTrace ) { | ||
var trace = currentTrace; | ||
return setTimeout(function() { | ||
currentTrace = trace; | ||
cb(); | ||
currentTrace = null; | ||
}, ms); | ||
} | ||
return setTimeout( cb, ms ); | ||
} | ||
Promise.prototype.timeout = function( ms, msg ) { | ||
@@ -521,5 +661,4 @@ var p = this; | ||
} else { | ||
var timeoutId = setTimeout(function() { | ||
Settle( p2, REJECTED, | ||
new Error(msg || "Timed out after " + ms + " ms") ); | ||
var timeoutId = _setTimeout(function() { | ||
Reject( p2, new Error(msg || "Timed out after " + ms + " ms") ); | ||
}, ms); | ||
@@ -540,3 +679,3 @@ | ||
this.then(function( value ) { | ||
setTimeout(function() { | ||
_setTimeout(function() { | ||
d.resolve( value ); | ||
@@ -560,4 +699,10 @@ }, ms); | ||
function allSettled( input ) { | ||
var promise = new Promise(); | ||
if ( typeof input.length !== "number" ) { | ||
Reject( promise, new TypeError("input not array-like") ); | ||
return promise; | ||
} | ||
var waiting = 0; | ||
var promise = new Promise(); | ||
var output = new Array( input.length ); | ||
@@ -572,3 +717,3 @@ | ||
if ( --waiting === 0 ) { | ||
Settle( promise, FULFILLED, output ); | ||
Fulfill( promise, output ); | ||
} | ||
@@ -583,3 +728,3 @@ }); | ||
if ( waiting === 0 ) { | ||
Settle( promise, FULFILLED, output ); | ||
Fulfill( promise, output ); | ||
} | ||
@@ -592,4 +737,10 @@ | ||
function all( input ) { | ||
var d = defer(); | ||
if ( typeof input.length !== "number" ) { | ||
d.reject( new TypeError("input not array-like") ); | ||
return d.promise; | ||
} | ||
var waiting = 0; | ||
var d = defer(); | ||
var output = new Array( input.length ); | ||
@@ -635,3 +786,5 @@ | ||
var pEndingLine = captureLine(); | ||
return P; | ||
}); |
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e=h(typeof process)&&process!=null&&{}.toString.call(process)==="[object process]",n=typeof setImmediate==="function",t=h(typeof MutationObserver)&&MutationObserver||h(typeof WebKitMutationObserver)&&WebKitMutationObserver,i=new v,r=i,o=false,u=0,a=e?g:t?x(m):T(m),l=[],s=T(_),f,c,p=h.call,d=h.apply;r.next=i;function v(){this.task=null;this.domain=null;this.a=null;this.b=null;this.next=null}function h(e){return e==="object"||e==="function"}function _(){if(l.length){throw l.shift()}}function m(){while(i!==r){i=i.next;var e=i.task;if(u>=1024){r.next=r.next.next}else{++u}if(i.domain){b(i.domain,e,i.a,i.b,void 0);i.domain=null}else{e(i.a,i.b)}i.task=null;i.a=null;i.b=null}o=false}function y(){i.task=null;i.domain=null;i.a=null;i.b=null;a()}function b(e,n,t,i,r){if(e._disposed){return}e.enter();n(t,i,r);e.exit()}function w(n,t,l,s){var f=r.next;if(f===i){f=new v;r.next=f;f.next=i}else{--u}r=f;f.task=t;f.a=l;f.b=s;if(n&&e){f.domain=process.domain}if(!o){o=true;a()}}function g(){var e=process.domain;if(e){if(!c)c=(1,require)("domain");c.active=process.domain=null}if(o&&n){setImmediate(m)}else{process.nextTick(m)}if(e){c.active=process.domain=e}}function x(e){var n=1;var i=document.createTextNode("");var r=new t(e);r.observe(i,{characterData:true});return function(){n=-n;i.data=n}}function T(e){return function(){var n=setTimeout(i,0);var t=setInterval(i,50);function i(){clearTimeout(n);clearInterval(t);e()}}}if(e){f=function(e){y();throw e}}else{f=function(e){l.push(e);s()}}function j(e,n){try{e.call()}catch(t){n(t)}}function k(e){w(true,j,e,f)}function O(e,n){for(var t=0,i=e.length;t<i;++t){if(t in e){n(e[t],t)}}}function I(e){k(function(){if(K.onerror){K.onerror.call(null,e)}else{throw e}})}var M=0;var E=1;var A=2;function K(e){return e instanceof G?e:q(new G,e,false)}function S(n,t,i){if(n._state){return n}n._state=t;n._value=i;if(t===A&&e){n._domain=process.domain}if(n._pending){N(n)}return n}function W(e,n){if(n._state){return n}n._state=e._state;n._value=e._value;n._domain=e._domain;if(n._pending){N(n)}return n}function q(e,n,t){if(e._state){return e}if(n instanceof G){if(n===e){S(e,A,new TypeError("You can't resolve a promise with itself"))}else if(n._state){W(n,e)}else{P(e,n)}}else if(n!==Object(n)){S(e,E,n)}else if(t){D(e,n)}else{w(true,D,e,n)}return e}function D(e,n){var t,i;try{i=n.then}catch(r){S(e,A,r);return}if(typeof i==="function"){t=B(e);try{p.call(i,n,t.resolve,t.reject)}catch(o){t.reject(o)}}else{S(e,E,n)}}function N(e){var n=e._pending;e._pending=null;if(n instanceof G){w(false,Y,e,n);return}for(var t=0,i=n.length;t<i;++t){w(false,Y,e,n[t])}}function P(e,n){if(!n._pending){n._pending=e}else if(n._pending instanceof G){n._pending=[n._pending,e]}else{n._pending.push(e)}}function Y(e,n){var t=e._state===E?n._cb:n._eb;n._cb=null;n._eb=null;if(!t){W(e,n);return}var i=e._domain||n._domain;if(i){n._domain=null;b(i,z,t,n,e._value)}else{z(t,n,e._value)}}function z(e,n,t){var i;try{i=e(t)}catch(r){S(n,A,r);return}q(n,i,true)}function B(e){var n=false;return{promise:e,resolve:function(t){if(!n){n=true;q(e,t,false)}},reject:function(t){if(!n){n=true;S(e,A,t)}}}}K.defer=C;function C(){return B(new G)}K.reject=F;function F(e){return S(new G,A,e)}function G(){this._state=0;this._value=void 0;this._domain=null;this._cb=null;this._eb=null;this._pending=null}G.prototype.then=function(n,t){var i=new G;i._cb=typeof n==="function"?n:null;i._eb=typeof t==="function"?t:null;i._domain=e?process.domain:null;if(this._state===M){P(i,this)}else{w(false,Y,this,i)}return i};G.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,I)};G.prototype.fail=function(e){return this.then(null,e)};G.prototype._always=function(e){return this.then(e,e)};G.prototype.spread=function(e,n){return this.then(e&&function(t){return J(t).then(function(n){return d.call(e,void 0,n)},n)},n)};G.prototype.timeout=function(e,n){var t=this;var i=new G;if(t._state!==M){W(t,i)}else{var r=setTimeout(function(){S(i,A,new Error(n||"Timed out after "+e+" ms"))},e);t._always(function(){clearTimeout(r);W(t,i)})}return i};G.prototype.delay=function(e){var n=C();this.then(function(t){setTimeout(function(){n.resolve(t)},e)},n.reject);return n.promise};G.prototype.inspect=function(){switch(this._state){case M:return{state:"pending"};case E:return{state:"fulfilled",value:this._value};case A:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};K.allSettled=H;function H(e){var n=0;var t=new G;var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===M){++n;o._always(function(){i[r]=o.inspect();if(--n===0){S(t,E,i)}})}else{i[r]=o.inspect()}});if(n===0){S(t,E,i)}return t}K.all=J;function J(e){var n=0;var t=C();var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===E){i[r]=o._value}else{++n;o.then(function(e){i[r]=e;if(--n===0){t.resolve(i)}},t.reject)}});if(n===0){t.resolve(i)}return t.promise}K.promised=L;function L(e){function n(n){return d.apply(e,n)}return function(){return J([this,J(arguments)]).then(n)}}K.onerror=null;K.nextTick=k;return K}); | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e=i(),n,t=null;function r(e){var n=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(e)||/at ([^ ]+):(\d+):(?:\d+)$/.exec(e)||/.*@(.+):(\d+)$/.exec(e);return n?{fileName:n[1],lineNumber:Number(n[2])}:null}function i(){var e=(new Error).stack;if(!e){return 0}var t=e.split("\n");var i=t[0].indexOf("@")>0?t[1]:t[2];var a=r(i);if(!a){return 0}n=a.fileName;return a.lineNumber}function a(e,n){var t=e.split("\n");var r=[];for(var i=n|0,a=t.length;i<a;++i){var l=t[i];if(l&&!u(l)&&!o(l)){r.push(l)}}return r.join("\n")}function u(e){return e.indexOf("(module.js:")!==-1||e.indexOf("(node.js:")!==-1}function o(t){var i=r(t);return!!i&&i.fileName===n&&i.lineNumber>=e&&i.lineNumber<=on}var l="\nFrom previous event:\n";function f(e){if(e instanceof Error&&e.stack&&e.stack.indexOf(l)===-1){var n=[a(e.stack,0)];var r=t;var i=512;while(r&&--i){var u=r.stack&&a(r.stack,2);if(u){n.push(u)}r=r.parent}var o=n.join(l);e.stack=o}}var s=T(typeof process)&&process!=null&&{}.toString.call(process)==="[object process]",c=typeof setImmediate==="function",p=T(typeof MutationObserver)&&MutationObserver||T(typeof WebKitMutationObserver)&&WebKitMutationObserver,v=new j,d=v,h=false,_=0,m=s?$:p?A(N):K(N),y=[],b=K(E),w,g,k=T.call,x=T.apply;d.next=v;function j(){this.task=null;this.a=null;this.b=null;this.domain=null;this.trace=null;this.next=null}function T(e){return e==="object"||e==="function"}function E(){if(y.length){throw y.shift()}}function N(){while(v!==d){v=v.next;if(_>=1024){d.next=d.next.next}else{++_}t=v.trace;if(v.domain){S(v.domain,v.task,v.a,v.b,void 0);v.domain=null}else{(1,v.task)(v.a,v.b)}v.task=null;v.a=null;v.b=null;v.trace=null}h=false;t=null}function O(){v.task=null;v.a=null;v.b=null;v.domain=null;v.trace=null;m()}function S(e,n,t,r,i){if(e._disposed){return}e.enter();n(t,r,i);e.exit()}function I(e,n,r){var i=s?process.domain:null;var a=B.longStackSupport?{parent:t,stack:(new Error).stack}:null;M(e,n,r,i,a)}function M(e,n,t,r,i){var a=d.next;if(a===v){a=new j;d.next=a;a.next=v}else{--_}d=a;a.task=e;a.a=n;a.b=t;a.domain=r;a.trace=i;if(!h){h=true;m()}}function $(){var e=process.domain;if(e){if(!g)g=(1,require)("domain");g.active=process.domain=null}if(h&&c){setImmediate(N)}else{process.nextTick(N)}if(e){g.active=process.domain=e}}function A(e){var n=1;var t=document.createTextNode("");var r=new p(e);r.observe(t,{characterData:true});return function(){n=-n;t.data=n}}function K(e){return function(){var n=setTimeout(r,0);var t=setInterval(r,50);function r(){clearTimeout(n);clearInterval(t);e()}}}if(s){w=function(e){O();throw e}}else{w=function(e){y.push(e);b()}}function W(e,n){try{e.call()}catch(t){n(t)}}function q(e){I(W,e,w)}function D(e,n){for(var t=0,r=e.length;t<r;++t){if(t in e){n(e[t],t)}}}function F(e){q(function(){if(B.onerror){B.onerror.call(null,e)}else{throw e}})}var P=0;var Y=1;var z=2;function B(e){return e instanceof nn?e:J(new nn,e,false)}B.longStackSupport=false;function C(e,n){if(e._state){return}e._state=Y;e._value=n;if(e._pending){Q(e)}}function G(e,n){if(e._state){return}if(t){f(n)}e._state=z;e._value=n;if(s){e._domain=process.domain}if(e._pending){Q(e)}}function H(e,n){if(n._state){return}n._state=e._state;n._value=e._value;n._domain=e._domain;if(n._pending){Q(n)}}function J(e,n,t){if(e._state){return e}if(n instanceof nn){if(n===e){G(e,new TypeError("You can't resolve a promise with itself"))}else if(n._state){H(n,e)}else{R(e,n)}}else if(n!==Object(n)){C(e,n)}else if(t){L(e,n)}else{I(L,e,n)}return e}function L(e,n){var t,r;try{r=n.then}catch(i){G(e,i);return}if(typeof r==="function"){t=X(e);try{k.call(r,n,t.resolve,t.reject)}catch(a){t.reject(a)}}else{C(e,n)}}function Q(e){var n=e._pending;e._pending=null;if(n instanceof nn){M(U,e,n,null,n._trace);return}for(var t=0,r=n.length;t<r;++t){M(U,e,n[t],null,n[t]._trace)}}function R(e,n){if(!n._pending){n._pending=e}else if(n._pending instanceof nn){n._pending=[n._pending,e]}else{n._pending.push(e)}}function U(e,n){var t=e._state===Y?n._cb:n._eb;n._cb=null;n._eb=null;if(!t){H(e,n);return}var r=e._domain||n._domain;if(r){n._domain=null;S(r,V,t,n,e._value)}else{V(t,n,e._value)}}function V(e,n,t){var r;try{r=e(t)}catch(i){G(n,i);return}J(n,r,true)}function X(e){var n=false;return{promise:e,resolve:function(t){if(!n){n=true;J(e,t,false)}},reject:function(t){if(!n){n=true;G(e,t)}}}}B.defer=Z;function Z(){return X(new nn)}B.reject=en;function en(e){var n=new nn;G(n,e);return n}function nn(){this._state=0;this._value=void 0;this._domain=null;this._cb=null;this._eb=null;this._pending=null;this._trace=null}nn.prototype.then=function(e,n){var r=new nn;if(B.longStackSupport){r._trace={parent:t,stack:(new Error).stack}}r._cb=typeof e==="function"?e:null;r._eb=typeof n==="function"?n:null;if(s){r._domain=process.domain}if(this._state===P){R(r,this)}else{M(U,this,r,null,r._trace)}return r};nn.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,F)};nn.prototype.fail=function(e){return this.then(null,e)};nn.prototype._always=function(e){return this.then(e,e)};nn.prototype.spread=function(e,n){return this.then(e&&function(t){return an(t).then(function(n){return x.call(e,void 0,n)},n)},n)};function tn(e,n){if(t){var r=t;return setTimeout(function(){t=r;e();t=null},n)}return setTimeout(e,n)}nn.prototype.timeout=function(e,n){var t=this;var r=new nn;if(t._state!==P){H(t,r)}else{var i=tn(function(){G(r,new Error(n||"Timed out after "+e+" ms"))},e);t._always(function(){clearTimeout(i);H(t,r)})}return r};nn.prototype.delay=function(e){var n=Z();this.then(function(t){tn(function(){n.resolve(t)},e)},n.reject);return n.promise};nn.prototype.inspect=function(){switch(this._state){case P:return{state:"pending"};case Y:return{state:"fulfilled",value:this._value};case z:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};B.allSettled=rn;function rn(e){var n=new nn;if(typeof e.length!=="number"){G(n,new TypeError("input not array-like"));return n}var t=0;var r=new Array(e.length);D(e,function(e,i){var a=B(e);if(a._state===P){++t;a._always(function(){r[i]=a.inspect();if(--t===0){C(n,r)}})}else{r[i]=a.inspect()}});if(t===0){C(n,r)}return n}B.all=an;function an(e){var n=Z();if(typeof e.length!=="number"){n.reject(new TypeError("input not array-like"));return n.promise}var t=0;var r=new Array(e.length);D(e,function(e,i){var a=B(e);if(a._state===Y){r[i]=a._value}else{++t;a.then(function(e){r[i]=e;if(--t===0){n.resolve(r)}},n.reject)}});if(t===0){n.resolve(r)}return n.promise}B.promised=un;function un(e){function n(n){return x.apply(e,n)}return function(){return an([this,an(arguments)]).then(n)}}B.onerror=null;B.nextTick=q;var on=i();return B}); |
{ | ||
"name": "p-promise", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "A simple Promises/A+ library.", | ||
@@ -5,0 +5,0 @@ "author": "Robert Katić <robert.katic@gmail.com> (https://github.com/rkatic)", |
@@ -30,2 +30,3 @@ [![Build Status](https://travis-ci.org/rkatic/p.png?branch=master)](https://travis-ci.org/rkatic/p) | ||
- `P.onerror` | ||
- `P.longStackSupport` :new: | ||
- `P.nextTick(callback)` | ||
@@ -32,0 +33,0 @@ - `deferred.promise` |
65763
24
1247
41