Closed 6XGate closed 10 years ago
I would recommend creating a separate CallRejectHandler and CallResolveHandler.
result
be handler.[[Call]](undefined, (value))
result
is an abrupt completion, call Reject(derivedPromise, result.[[value]])
Resolve(derivedPromise, result.[[value]])
.result
be handler.[[Call]](undefined, (reason))
result
is an abrupt completion, call Reject(derivedPromise, result.[[value]])
Reject(derivedPromise, reason)
.This is expected. You caught the rejection and handled it, so p[1] and p[2] shouldn't be in the rejected state. If you want to propagate the rejection, either:
var p = [];
p.push(new Promise(function(resolve, reject) { reject() }))
p.push(p[0].then(function() { console.log('fulfilled') }, function(r) { console.log('rejected'); throw r; }))
p.push(p[1].then(function() { console.log('fulfilled') }, function(r) { console.log('rejected'); throw r; }))
or
var p = [];
p.push(new Promise(function(resolve, reject) { reject() }))
p.push(p[0].then(function() { console.log('fulfilled') }))
p.push(p[1].then(function() { console.log('fulfilled') }))
In both of these cases p[0], p[1], and p[2] are all in the rejected state. In your example, p[1] goes into the fulfilled state because the code handles the rejection from p[0] and then implicitly returns undefined
.
Indeed. Proof-reading appreciated though; thanks for looking into it!
It seems that when a Promise is fulfilled or rejected, the CallHandle will call the proper fulfill or reject handler on the derived Promise, but it doesn't seem to be aware of which handler it is calling and will always set the derived Promise state to fulfilled, even though the origin Promise is rejected.
Example code:
This will produce the following output:
And the states of each Promise are as follows: