From ddedf5c3092757d0aae861d681f70d015fa52ffe Mon Sep 17 00:00:00 2001 From: "rossberg@chromium.org" Date: Thu, 27 Mar 2014 16:11:23 +0000 Subject: [PATCH] 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 --- src/promise.js | 10 ++++++---- test/mjsunit/es6/promises.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/promise.js b/src/promise.js index 9937f0c..5a834bd 100644 --- a/src/promise.js +++ b/src/promise.js @@ -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 ); } diff --git a/test/mjsunit/es6/promises.js b/test/mjsunit/es6/promises.js index 48b96f6..ba5a306 100644 --- a/test/mjsunit/es6/promises.js +++ b/test/mjsunit/es6/promises.js @@ -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") })(); -- 2.7.4