Comparing version 0.10.1-0 to 0.10.2-0
@@ -37,2 +37,33 @@ /** | ||
function formatNonError( obj ) { | ||
var str; | ||
if (typeof obj === "function") { | ||
str = "[function " + | ||
(obj.name || "anonymous") + | ||
"]"; | ||
} | ||
else { | ||
str = obj.toString(); | ||
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; | ||
if( ruselessToString.test( str ) ) { | ||
try { | ||
var newStr = JSON.stringify(obj); | ||
str = newStr; | ||
} | ||
catch( e ) { | ||
} | ||
} | ||
} | ||
return ("(<" + snip( str ) + ">, no stack trace)"); | ||
} | ||
function snip( str ) { | ||
var maxChars = 41; | ||
if( str.length < maxChars ) { | ||
return str; | ||
} | ||
return str.substr(0, maxChars - 3) + "..."; | ||
} | ||
function CapturedTrace( ignoreUntil, isTopLevel ) { | ||
@@ -54,4 +85,10 @@ if( !areNamesMangled ) { | ||
if( typeof console === "object" ) { | ||
var stack = reason.stack; | ||
var message = "Possibly unhandled " + formatStack( stack, reason ); | ||
var message; | ||
if (typeof reason === "object" || typeof reason === "function") { | ||
var stack = reason.stack; | ||
message = "Possibly unhandled " + formatStack( stack, reason ); | ||
} | ||
else { | ||
message = "Possibly unhandled " + String(reason); | ||
} | ||
if( typeof console.error === "function" || | ||
@@ -108,25 +145,2 @@ typeof console.error === "object" ) { | ||
var captureStackTrace = (function stackDetection() { | ||
function snip( str ) { | ||
var maxChars = 41; | ||
if( str.length < maxChars ) { | ||
return str; | ||
} | ||
return str.substr(0, maxChars - 3) + "..."; | ||
} | ||
function formatNonError( obj ) { | ||
var str = obj.toString(); | ||
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; | ||
if( ruselessToString.test( str ) ) { | ||
try { | ||
var newStr = JSON.stringify(obj); | ||
str = newStr; | ||
} | ||
catch( e ) { | ||
} | ||
} | ||
return ("(<" + snip( str ) + ">, no stack trace)"); | ||
} | ||
if( typeof Error.stackTraceLimit === "number" && | ||
@@ -133,0 +147,0 @@ typeof Error.captureStackTrace === "function" ) { |
@@ -32,141 +32,68 @@ /** | ||
function Thenable() { | ||
this.errorObj = errorObj; | ||
this.__id__ = 0; | ||
this.treshold = 1000; | ||
this.thenableCache = new Array( this.treshold ); | ||
this.promiseCache = new Array( this.treshold ); | ||
this._compactQueued = false; | ||
} | ||
Thenable.prototype.couldBe = function Thenable$couldBe( ret ) { | ||
if( isPrimitive( ret ) ) { | ||
return false; | ||
function getThen(obj) { | ||
try { | ||
return obj.then; | ||
} | ||
var id = ret.__id_$thenable__; | ||
if( typeof id === "number" && | ||
this.thenableCache[id] !== void 0 ) { | ||
return true; | ||
catch(e) { | ||
errorObj.e = e; | ||
return errorObj; | ||
} | ||
return ("then" in ret); | ||
}; | ||
} | ||
Thenable.prototype.is = function Thenable$is( ret, ref ) { | ||
var id = ret.__id_$thenable__; | ||
if( typeof id === "number" && | ||
this.thenableCache[id] !== void 0 ) { | ||
ref.ref = this.thenableCache[id]; | ||
ref.promise = this.promiseCache[id]; | ||
return true; | ||
function isThenable(obj, ref) { | ||
if (isPrimitive(obj)) { | ||
return false; | ||
} | ||
return this._thenableSlowCase( ret, ref ); | ||
}; | ||
var then = getThen(obj); | ||
Thenable.prototype.addCache = | ||
function Thenable$_addCache( thenable, promise ) { | ||
var id = this.__id__; | ||
this.__id__ = id + 1; | ||
var descriptor = this._descriptor( id ); | ||
Object.defineProperty( thenable, "__id_$thenable__", descriptor ); | ||
this.thenableCache[id] = thenable; | ||
this.promiseCache[id] = promise; | ||
if( this.thenableCache.length > this.treshold && | ||
!this._compactQueued) { | ||
this._compactQueued = true; | ||
async.invokeLater( this._compactCache, this, void 0 ); | ||
if (then === errorObj) { | ||
ref.ref = errorObj; | ||
return false; | ||
} | ||
}; | ||
Thenable.prototype.deleteCache = function Thenable$deleteCache( thenable ) { | ||
var id = thenable.__id_$thenable__; | ||
if( id === -1 ) { | ||
return; | ||
if (typeof then === "function") { | ||
ref.ref = then; | ||
return true; | ||
} | ||
this.thenableCache[id] = void 0; | ||
this.promiseCache[id] = void 0; | ||
thenable.__id_$thenable__ = -1; }; | ||
return false; | ||
} | ||
var descriptor = { | ||
value: 0, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
}; | ||
Thenable.prototype._descriptor = function Thenable$_descriptor( id ) { | ||
descriptor.value = id; | ||
return descriptor; | ||
}; | ||
var ref = {ref: null}; | ||
function Promise$_Cast( obj, caller ) { | ||
if( isObject( obj ) ) { | ||
if( obj instanceof Promise ) { | ||
return obj; | ||
} | ||
Thenable.prototype._compactCache = function Thenable$_compactCache() { | ||
var arr = this.thenableCache; | ||
var promiseArr = this.promiseCache; | ||
var skips = 0; | ||
var j = 0; | ||
for( var i = 0, len = arr.length; i < len; ++i ) { | ||
var item = arr[ i ]; | ||
if( item === void 0 ) { | ||
skips++; | ||
if( isThenable( obj, ref ) ) { | ||
caller = typeof caller === "function" ? caller : Promise$_Cast; | ||
var then = ref.ref; | ||
ref.ref = null; | ||
return doThenable( obj, then, caller ); | ||
} | ||
else { | ||
promiseArr[ j ] = promiseArr[ i ]; | ||
item.__id_$thenable__ = j; | ||
arr[ j++ ] = item; | ||
else if (ref.ref === errorObj) { | ||
ref.ref = null; | ||
return Promise.reject(errorObj.e); | ||
} | ||
ref.ref = null; | ||
} | ||
var newId = arr.length - skips; | ||
if( newId === this.__id__ ) { | ||
this.treshold *= 2; | ||
} | ||
else for( var i = newId, len = arr.length; i < len; ++i ) { | ||
promiseArr[ j ] = arr[ i ] = void 0; | ||
} | ||
return obj; | ||
} | ||
this.__id__ = newId; | ||
this._compactQueued = false; | ||
}; | ||
Promise._cast = Promise$_Cast; | ||
Promise._isThenable = isThenable; | ||
Thenable.prototype._thenableSlowCase = | ||
function Thenable$_thenableSlowCase( ret, ref ) { | ||
try { | ||
var then = ret.then; | ||
if( typeof then === "function" ) { | ||
ref.ref = then; | ||
return true; | ||
} | ||
return false; | ||
} | ||
catch(e) { | ||
this.errorObj.e = e; | ||
ref.ref = this.errorObj; | ||
return true; | ||
} | ||
}; | ||
function doThenable( x, then, caller ) { | ||
var resolver = Promise.defer( caller ); | ||
var thenable = new Thenable( errorObj ); | ||
Promise._couldBeThenable = function( val ) { | ||
return thenable.couldBe( val ); | ||
}; | ||
function doThenable( obj, ref, caller ) { | ||
if( ref.promise != null ) { | ||
return ref.promise; | ||
} | ||
var resolver = Promise.pending( caller ); | ||
var result = ref.ref; | ||
if( result === errorObj ) { | ||
resolver.reject( result.e ); | ||
return resolver.promise; | ||
} | ||
thenable.addCache( obj, resolver.promise ); | ||
var called = false; | ||
var ret = tryCatch2( result, obj, function t( a ) { | ||
var ret = tryCatch2( then, x, function t( a ) { | ||
if( called ) return; | ||
called = true; | ||
async.invoke( thenable.deleteCache, thenable, obj ); | ||
var b = Promise$_Cast( a ); | ||
if( b === a ) { | ||
resolver.fulfill( a ); | ||
resolver.resolve( a ); | ||
} | ||
else { | ||
if( a === obj ) { | ||
if( a === x ) { | ||
resolver.promise._resolveFulfill( a ); | ||
@@ -176,3 +103,3 @@ } | ||
b._then( | ||
resolver.fulfill, | ||
resolver.resolve, | ||
resolver.reject, | ||
@@ -189,3 +116,2 @@ void 0, | ||
called = true; | ||
async.invoke( thenable.deleteCache, thenable, obj ); | ||
resolver.reject( a ); | ||
@@ -195,3 +121,2 @@ }); | ||
resolver.reject( ret.e ); | ||
async.invoke( thenable.deleteCache, thenable, obj ); | ||
} | ||
@@ -201,125 +126,80 @@ return resolver.promise; | ||
function Promise$_Cast( obj, caller ) { | ||
if( isObject( obj ) ) { | ||
if( obj instanceof Promise ) { | ||
return obj; | ||
Promise.prototype._resolveThenable = | ||
function Promise$_resolveThenable(x, then) { | ||
var localP = this; | ||
var key = {}; | ||
var called = false; | ||
var t = function t( v ) { | ||
if( called && this !== key ) return; | ||
called = true; | ||
var fn = localP._fulfill; | ||
var b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
async.invoke( fn, localP, v ); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
return; | ||
} | ||
var ref = { ref: null, promise: null }; | ||
if( thenable.is( obj, ref ) ) { | ||
caller = typeof caller === "function" ? caller : Promise$_Cast; | ||
return doThenable( obj, ref, caller ); | ||
} | ||
} | ||
return obj; | ||
} | ||
Promise.prototype._resolveThenable = | ||
function Promise$_resolveThenable( x, ref ) { | ||
if( ref.promise != null ) { | ||
this._assumeStateOf( ref.promise, true ); | ||
return; | ||
} | ||
if( ref.ref === errorObj ) { | ||
this._attachExtraTrace( ref.ref.e ); | ||
async.invoke( this._reject, this, ref.ref.e ); | ||
} | ||
else { | ||
thenable.addCache( x, this ); | ||
var then = ref.ref; | ||
var localX = x; | ||
var localP = this; | ||
var key = {}; | ||
var called = false; | ||
var t = function t( v ) { | ||
if( called && this !== key ) return; | ||
called = true; | ||
var fn = localP._fulfill; | ||
var b = Promise$_Cast( v ); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
async.invoke( fn, localP, v ); | ||
async.invoke( thenable.deleteCache, thenable, localX ); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
( b instanceof Promise && b !== v ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
async.invoke( fn, localP, v ); | ||
}; | ||
var r = function r( v ) { | ||
if( called && this !== key ) return; | ||
var fn = localP._reject; | ||
called = true; | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b !== v ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
var b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
async.invoke( fn, localP, v ); | ||
} | ||
async.invoke( fn, localP, v ); | ||
async.invoke( thenable.deleteCache, | ||
thenable, localX ); | ||
}; | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
return; | ||
} | ||
var r = function r( v ) { | ||
if( called && this !== key ) return; | ||
var fn = localP._reject; | ||
called = true; | ||
var b = Promise$_Cast( v ); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
async.invoke( fn, localP, v ); | ||
async.invoke( thenable.deleteCache, thenable, localX ); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
async.invoke( fn, localP, v ); | ||
}; | ||
var threw = tryCatch2( then, x, t, r); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
async.invoke( fn, localP, v ); | ||
async.invoke( thenable.deleteCache, | ||
thenable, localX ); | ||
}; | ||
var threw = tryCatch2( then, x, t, r); | ||
if( threw === errorObj && | ||
!called ) { | ||
this._attachExtraTrace( threw.e ); | ||
async.invoke( this._reject, this, threw.e ); | ||
async.invoke( thenable.deleteCache, thenable, x ); | ||
} | ||
if( threw === errorObj && | ||
!called ) { | ||
this._attachExtraTrace( threw.e ); | ||
async.invoke( this._reject, this, threw.e ); | ||
} | ||
}; | ||
Promise.prototype._tryThenable = function Promise$_tryThenable( x ) { | ||
var ref; | ||
if( !thenable.is( x, ref = {ref: null, promise: null} ) ) { | ||
return false; | ||
} | ||
this._resolveThenable( x, ref ); | ||
return true; | ||
}; | ||
Promise._cast = Promise$_Cast; | ||
}; | ||
}; |
@@ -328,3 +328,2 @@ /** | ||
Promise.onPossiblyUnhandledRejection = | ||
@@ -396,9 +395,2 @@ function Promise$OnPossiblyUnhandledRejection( fn ) { | ||
if( this._isDelegated() ) { | ||
this._unsetDelegated(); | ||
var x = this._resolvedValue; | ||
if( !this._tryThenable( x ) ) { | ||
async.invoke( this._fulfill, this, x ); | ||
} | ||
} | ||
return ret; | ||
@@ -437,6 +429,2 @@ }; | ||
Promise.prototype._setDelegated = function Promise$_setDelegated() { | ||
this._bitField = this._bitField | -1073741824; | ||
}; | ||
Promise.prototype._setIsFinal = function Promise$_setIsFinal() { | ||
@@ -450,10 +438,2 @@ this._bitField = this._bitField | 33554432; | ||
Promise.prototype._isDelegated = function Promise$_isDelegated() { | ||
return ( this._bitField & -1073741824 ) === -1073741824; | ||
}; | ||
Promise.prototype._unsetDelegated = function Promise$_unsetDelegated() { | ||
this._bitField = this._bitField & ( ~-1073741824 ); | ||
}; | ||
Promise.prototype._setCancellable = function Promise$_setCancellable() { | ||
@@ -584,2 +564,3 @@ this._bitField = this._bitField | 67108864; | ||
var ignore = CatchFilter.prototype.doFilter; | ||
var ref = {ref: null}; | ||
Promise.prototype._resolvePromise = function Promise$_resolvePromise( | ||
@@ -658,14 +639,21 @@ onFulfilledOrRejected, receiver, value, promise | ||
} | ||
else if( Promise._couldBeThenable( x ) ) { | ||
else if( Promise._isThenable( x, ref ) ) { | ||
var then = ref.ref; | ||
ref.ref = null; | ||
promise._resolveThenable(x, then); | ||
return; | ||
} | ||
if( promise._length() === 0 ) { | ||
promise._resolvedValue = x; | ||
promise._setDelegated(); | ||
return; | ||
} | ||
else if( promise._tryThenable( x ) ) { | ||
return; | ||
} | ||
if (ref.ref === errorObj) { | ||
ref.ref = null; | ||
var e = errorObj.e; | ||
promise._attachExtraTrace(e); | ||
async.invoke(promise._reject, promise, e); | ||
} | ||
async.invoke( promise._fulfill, promise, x ); | ||
else { | ||
ref.ref = null; | ||
async.invoke( promise._fulfill, promise, x ); | ||
} | ||
} | ||
@@ -672,0 +660,0 @@ }; |
@@ -37,2 +37,33 @@ /** | ||
function formatNonError( obj ) { | ||
var str; | ||
if (typeof obj === "function") { | ||
str = "[function " + | ||
(obj.name || "anonymous") + | ||
"]"; | ||
} | ||
else { | ||
str = obj.toString(); | ||
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; | ||
if( ruselessToString.test( str ) ) { | ||
try { | ||
var newStr = JSON.stringify(obj); | ||
str = newStr; | ||
} | ||
catch( e ) { | ||
} | ||
} | ||
} | ||
return ("(<" + snip( str ) + ">, no stack trace)"); | ||
} | ||
function snip( str ) { | ||
var maxChars = 41; | ||
if( str.length < maxChars ) { | ||
return str; | ||
} | ||
return str.substr(0, maxChars - 3) + "..."; | ||
} | ||
function CapturedTrace( ignoreUntil, isTopLevel ) { | ||
@@ -54,4 +85,10 @@ if( !areNamesMangled ) { | ||
if( typeof console === "object" ) { | ||
var stack = reason.stack; | ||
var message = "Possibly unhandled " + formatStack( stack, reason ); | ||
var message; | ||
if (typeof reason === "object" || typeof reason === "function") { | ||
var stack = reason.stack; | ||
message = "Possibly unhandled " + formatStack( stack, reason ); | ||
} | ||
else { | ||
message = "Possibly unhandled " + String(reason); | ||
} | ||
if( typeof console.error === "function" || | ||
@@ -108,25 +145,2 @@ typeof console.error === "object" ) { | ||
var captureStackTrace = (function stackDetection() { | ||
function snip( str ) { | ||
var maxChars = 41; | ||
if( str.length < maxChars ) { | ||
return str; | ||
} | ||
return str.substr(0, maxChars - 3) + "..."; | ||
} | ||
function formatNonError( obj ) { | ||
var str = obj.toString(); | ||
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; | ||
if( ruselessToString.test( str ) ) { | ||
try { | ||
var newStr = JSON.stringify(obj); | ||
str = newStr; | ||
} | ||
catch( e ) { | ||
} | ||
} | ||
return ("(<" + snip( str ) + ">, no stack trace)"); | ||
} | ||
if( typeof Error.stackTraceLimit === "number" && | ||
@@ -133,0 +147,0 @@ typeof Error.captureStackTrace === "function" ) { |
@@ -32,141 +32,68 @@ /** | ||
function Thenable() { | ||
this.errorObj = errorObj; | ||
this.__id__ = 0; | ||
this.treshold = 1000; | ||
this.thenableCache = new Array( this.treshold ); | ||
this.promiseCache = new Array( this.treshold ); | ||
this._compactQueued = false; | ||
} | ||
Thenable.prototype.couldBe = function Thenable$couldBe( ret ) { | ||
if( isPrimitive( ret ) ) { | ||
return false; | ||
function getThen(obj) { | ||
try { | ||
return obj.then; | ||
} | ||
var id = ret.__id_$thenable__; | ||
if( typeof id === "number" && | ||
this.thenableCache[id] !== void 0 ) { | ||
return true; | ||
catch(e) { | ||
errorObj.e = e; | ||
return errorObj; | ||
} | ||
return ("then" in ret); | ||
}; | ||
} | ||
Thenable.prototype.is = function Thenable$is( ret, ref ) { | ||
var id = ret.__id_$thenable__; | ||
if( typeof id === "number" && | ||
this.thenableCache[id] !== void 0 ) { | ||
ref.ref = this.thenableCache[id]; | ||
ref.promise = this.promiseCache[id]; | ||
return true; | ||
function isThenable(obj, ref) { | ||
if (isPrimitive(obj)) { | ||
return false; | ||
} | ||
return this._thenableSlowCase( ret, ref ); | ||
}; | ||
var then = getThen(obj); | ||
Thenable.prototype.addCache = | ||
function Thenable$_addCache( thenable, promise ) { | ||
var id = this.__id__; | ||
this.__id__ = id + 1; | ||
var descriptor = this._descriptor( id ); | ||
Object.defineProperty( thenable, "__id_$thenable__", descriptor ); | ||
this.thenableCache[id] = thenable; | ||
this.promiseCache[id] = promise; | ||
if( this.thenableCache.length > this.treshold && | ||
!this._compactQueued) { | ||
this._compactQueued = true; | ||
async.invokeLater( this._compactCache, this, void 0 ); | ||
if (then === errorObj) { | ||
ref.ref = errorObj; | ||
return false; | ||
} | ||
}; | ||
Thenable.prototype.deleteCache = function Thenable$deleteCache( thenable ) { | ||
var id = thenable.__id_$thenable__; | ||
if( id === -1 ) { | ||
return; | ||
if (typeof then === "function") { | ||
ref.ref = then; | ||
return true; | ||
} | ||
this.thenableCache[id] = void 0; | ||
this.promiseCache[id] = void 0; | ||
thenable.__id_$thenable__ = -1; }; | ||
return false; | ||
} | ||
var descriptor = { | ||
value: 0, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
}; | ||
Thenable.prototype._descriptor = function Thenable$_descriptor( id ) { | ||
descriptor.value = id; | ||
return descriptor; | ||
}; | ||
var ref = {ref: null}; | ||
function Promise$_Cast( obj, caller ) { | ||
if( isObject( obj ) ) { | ||
if( obj instanceof Promise ) { | ||
return obj; | ||
} | ||
Thenable.prototype._compactCache = function Thenable$_compactCache() { | ||
var arr = this.thenableCache; | ||
var promiseArr = this.promiseCache; | ||
var skips = 0; | ||
var j = 0; | ||
for( var i = 0, len = arr.length; i < len; ++i ) { | ||
var item = arr[ i ]; | ||
if( item === void 0 ) { | ||
skips++; | ||
if( isThenable( obj, ref ) ) { | ||
caller = typeof caller === "function" ? caller : Promise$_Cast; | ||
var then = ref.ref; | ||
ref.ref = null; | ||
return doThenable( obj, then, caller ); | ||
} | ||
else { | ||
promiseArr[ j ] = promiseArr[ i ]; | ||
item.__id_$thenable__ = j; | ||
arr[ j++ ] = item; | ||
else if (ref.ref === errorObj) { | ||
ref.ref = null; | ||
return Promise.reject(errorObj.e); | ||
} | ||
ref.ref = null; | ||
} | ||
var newId = arr.length - skips; | ||
if( newId === this.__id__ ) { | ||
this.treshold *= 2; | ||
} | ||
else for( var i = newId, len = arr.length; i < len; ++i ) { | ||
promiseArr[ j ] = arr[ i ] = void 0; | ||
} | ||
return obj; | ||
} | ||
this.__id__ = newId; | ||
this._compactQueued = false; | ||
}; | ||
Promise._cast = Promise$_Cast; | ||
Promise._isThenable = isThenable; | ||
Thenable.prototype._thenableSlowCase = | ||
function Thenable$_thenableSlowCase( ret, ref ) { | ||
try { | ||
var then = ret.then; | ||
if( typeof then === "function" ) { | ||
ref.ref = then; | ||
return true; | ||
} | ||
return false; | ||
} | ||
catch(e) { | ||
this.errorObj.e = e; | ||
ref.ref = this.errorObj; | ||
return true; | ||
} | ||
}; | ||
function doThenable( x, then, caller ) { | ||
var resolver = Promise.defer( caller ); | ||
var thenable = new Thenable( errorObj ); | ||
Promise._couldBeThenable = function( val ) { | ||
return thenable.couldBe( val ); | ||
}; | ||
function doThenable( obj, ref, caller ) { | ||
if( ref.promise != null ) { | ||
return ref.promise; | ||
} | ||
var resolver = Promise.pending( caller ); | ||
var result = ref.ref; | ||
if( result === errorObj ) { | ||
resolver.reject( result.e ); | ||
return resolver.promise; | ||
} | ||
thenable.addCache( obj, resolver.promise ); | ||
var called = false; | ||
var ret = tryCatch2( result, obj, function t( a ) { | ||
var ret = tryCatch2( then, x, function t( a ) { | ||
if( called ) return; | ||
called = true; | ||
thenable.deleteCache(obj); | ||
var b = Promise$_Cast( a ); | ||
if( b === a ) { | ||
resolver.fulfill( a ); | ||
resolver.resolve( a ); | ||
} | ||
else { | ||
if( a === obj ) { | ||
if( a === x ) { | ||
resolver.promise._resolveFulfill( a ); | ||
@@ -176,3 +103,3 @@ } | ||
b._then( | ||
resolver.fulfill, | ||
resolver.resolve, | ||
resolver.reject, | ||
@@ -189,3 +116,2 @@ void 0, | ||
called = true; | ||
thenable.deleteCache(obj); | ||
resolver.reject( a ); | ||
@@ -195,3 +121,2 @@ }); | ||
resolver.reject( ret.e ); | ||
thenable.deleteCache(obj); | ||
} | ||
@@ -201,123 +126,80 @@ return resolver.promise; | ||
function Promise$_Cast( obj, caller ) { | ||
if( isObject( obj ) ) { | ||
if( obj instanceof Promise ) { | ||
return obj; | ||
Promise.prototype._resolveThenable = | ||
function Promise$_resolveThenable(x, then) { | ||
var localP = this; | ||
var key = {}; | ||
var called = false; | ||
var t = function t( v ) { | ||
if( called && this !== key ) return; | ||
called = true; | ||
var fn = localP._fulfill; | ||
var b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
fn.call(localP, v); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
return; | ||
} | ||
var ref = { ref: null, promise: null }; | ||
if( thenable.is( obj, ref ) ) { | ||
caller = typeof caller === "function" ? caller : Promise$_Cast; | ||
return doThenable( obj, ref, caller ); | ||
} | ||
} | ||
return obj; | ||
} | ||
Promise.prototype._resolveThenable = | ||
function Promise$_resolveThenable( x, ref ) { | ||
if( ref.promise != null ) { | ||
this._assumeStateOf( ref.promise, true ); | ||
return; | ||
} | ||
if( ref.ref === errorObj ) { | ||
this._attachExtraTrace( ref.ref.e ); | ||
this._reject(ref.ref.e); | ||
} | ||
else { | ||
thenable.addCache( x, this ); | ||
var then = ref.ref; | ||
var localX = x; | ||
var localP = this; | ||
var key = {}; | ||
var called = false; | ||
var t = function t( v ) { | ||
if( called && this !== key ) return; | ||
called = true; | ||
var fn = localP._fulfill; | ||
var b = Promise$_Cast( v ); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
fn.call(localP, v); | ||
thenable.deleteCache(localX); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
( b instanceof Promise && b !== v ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
fn.call(localP, v); | ||
}; | ||
var r = function r( v ) { | ||
if( called && this !== key ) return; | ||
var fn = localP._reject; | ||
called = true; | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b !== v ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
var b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
fn.call(localP, v); | ||
} | ||
fn.call(localP, v); | ||
thenable.deleteCache(localX); | ||
}; | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
return; | ||
} | ||
var r = function r( v ) { | ||
if( called && this !== key ) return; | ||
var fn = localP._reject; | ||
called = true; | ||
var b = Promise$_Cast( v ); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
if( v === x ) { | ||
fn.call(localP, v); | ||
thenable.deleteCache(localX); | ||
} | ||
else { | ||
b._then( t, r, void 0, key, void 0, t); | ||
} | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
fn.call(localP, v); | ||
}; | ||
var threw = tryCatch2( then, x, t, r); | ||
if( b instanceof Promise ) { | ||
var fn = b.isFulfilled() | ||
? localP._fulfill : localP._reject; | ||
v = v._resolvedValue; | ||
b = Promise$_Cast( v ); | ||
if( b !== v || | ||
( b instanceof Promise && b.isPending() ) ) { | ||
b._then( t, r, void 0, key, void 0, t); | ||
return; | ||
} | ||
} | ||
fn.call(localP, v); | ||
thenable.deleteCache(localX); | ||
}; | ||
var threw = tryCatch2( then, x, t, r); | ||
if( threw === errorObj && | ||
!called ) { | ||
this._attachExtraTrace( threw.e ); | ||
this._reject(threw.e); | ||
thenable.deleteCache(x); | ||
} | ||
if( threw === errorObj && | ||
!called ) { | ||
this._attachExtraTrace( threw.e ); | ||
this._reject(threw.e); | ||
} | ||
}; | ||
Promise.prototype._tryThenable = function Promise$_tryThenable( x ) { | ||
var ref; | ||
if( !thenable.is( x, ref = {ref: null, promise: null} ) ) { | ||
return false; | ||
} | ||
this._resolveThenable( x, ref ); | ||
return true; | ||
}; | ||
Promise._cast = Promise$_Cast; | ||
}; | ||
}; |
@@ -328,3 +328,2 @@ /** | ||
Promise.onPossiblyUnhandledRejection = | ||
@@ -396,9 +395,2 @@ function Promise$OnPossiblyUnhandledRejection( fn ) { | ||
if( this._isDelegated() ) { | ||
this._unsetDelegated(); | ||
var x = this._resolvedValue; | ||
if( !this._tryThenable( x ) ) { | ||
this._fulfill(x); | ||
} | ||
} | ||
return ret; | ||
@@ -437,6 +429,2 @@ }; | ||
Promise.prototype._setDelegated = function Promise$_setDelegated() { | ||
this._bitField = this._bitField | -1073741824; | ||
}; | ||
Promise.prototype._setIsFinal = function Promise$_setIsFinal() { | ||
@@ -450,10 +438,2 @@ this._bitField = this._bitField | 33554432; | ||
Promise.prototype._isDelegated = function Promise$_isDelegated() { | ||
return ( this._bitField & -1073741824 ) === -1073741824; | ||
}; | ||
Promise.prototype._unsetDelegated = function Promise$_unsetDelegated() { | ||
this._bitField = this._bitField & ( ~-1073741824 ); | ||
}; | ||
Promise.prototype._setCancellable = function Promise$_setCancellable() { | ||
@@ -584,2 +564,3 @@ this._bitField = this._bitField | 67108864; | ||
var ignore = CatchFilter.prototype.doFilter; | ||
var ref = {ref: null}; | ||
Promise.prototype._resolvePromise = function Promise$_resolvePromise( | ||
@@ -654,14 +635,21 @@ onFulfilledOrRejected, receiver, value, promise | ||
} | ||
else if( Promise._couldBeThenable( x ) ) { | ||
else if( Promise._isThenable( x, ref ) ) { | ||
var then = ref.ref; | ||
ref.ref = null; | ||
promise._resolveThenable(x, then); | ||
return; | ||
} | ||
if( promise._length() === 0 ) { | ||
promise._resolvedValue = x; | ||
promise._setDelegated(); | ||
return; | ||
} | ||
else if( promise._tryThenable( x ) ) { | ||
return; | ||
} | ||
if (ref.ref === errorObj) { | ||
ref.ref = null; | ||
var e = errorObj.e; | ||
promise._attachExtraTrace(e); | ||
promise._reject(e); | ||
} | ||
promise._fulfill(x); | ||
else { | ||
ref.ref = null; | ||
promise._fulfill(x); | ||
} | ||
} | ||
@@ -668,0 +656,0 @@ }; |
{ | ||
"name": "bluebird", | ||
"description": "Full featured Promises/A+ implementation with exceptionally good performance", | ||
"version": "0.10.1-0", | ||
"version": "0.10.2-0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "promise", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
447210
9184