Harden internal uses of .chain

R=yangguo@chromium.org
BUG=

Review URL: https://codereview.chromium.org/212553009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20309 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
rossberg@chromium.org 2014-03-27 16:11:23 +00:00
parent 4608bdeccc
commit ddedf5c309
2 changed files with 8 additions and 6 deletions

View File

@ -170,7 +170,7 @@ function PromiseChain(onResolve, onReject) { // a.k.a. flatMap
}
function PromiseCatch(onReject) {
return this.chain(UNDEFINED, onReject);
return this.then(UNDEFINED, onReject);
}
function PromiseEnqueue(value, tasks) {
@ -189,7 +189,7 @@ function PromiseHandle(value, handler, deferred) {
if (result === deferred.promise)
throw MakeTypeError('promise_cyclic', [result]);
else if (IsPromise(result))
result.chain(deferred.resolve, deferred.reject);
%_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain);
else
deferred.resolve(result);
} catch(e) {
@ -208,13 +208,15 @@ function PromiseThen(onResolve, onReject) {
IS_NULL_OR_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject;
var that = this;
var constructor = this.constructor;
return this.chain(
return %_CallFunction(
this,
function(x) {
x = PromiseCoerce(constructor, x);
return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) :
IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x);
},
onReject
onReject,
PromiseChain
);
}

View File

@ -790,11 +790,11 @@ function assertAsyncDone(iteration) {
log = ""
Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16])
assertTrue(log === "nx14cn", "subclass/all/arg")
assertTrue(log === "nx14n", "subclass/all/arg")
log = ""
MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26])
assertTrue(log === "nx24nnx21cnnx23cncnnx25cnnx26cn", "subclass/all/self")
assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self")
})();