Commit aa250ea4 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Promises: make null a legal argument for .then

R=svenpanne@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20037 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 88eba5e3
......@@ -210,7 +210,10 @@ function PromiseHandle(value, handler, deferred) {
// Multi-unwrapped chaining with thenable coercion.
function PromiseThen(onResolve, onReject) {
onResolve = IS_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve;
onResolve =
IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve;
onReject =
IS_NULL_OR_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject;
var that = this;
var constructor = this.constructor;
return this.chain(
......@@ -230,11 +233,10 @@ function PromiseCoerce(constructor, x) {
var then;
try {
then = x.then;
} catch(e) {
var deferred = %_CallFunction(constructor, PromiseDeferred);
PromiseCoerce.table.set(x, deferred.promise);
deferred.reject(e);
return deferred.promise;
} catch(r) {
var promise = %_CallFunction(constructor, r, PromiseRejected);
PromiseCoerce.table.set(x, promise);
return promise;
}
if (typeof then === 'function') {
if (PromiseCoerce.table.has(x)) {
......@@ -244,8 +246,8 @@ function PromiseCoerce(constructor, x) {
PromiseCoerce.table.set(x, deferred.promise);
try {
%_CallFunction(x, deferred.resolve, deferred.reject, then);
} catch(e) {
deferred.reject(e);
} catch(r) {
deferred.reject(r);
}
return deferred.promise;
}
......
......@@ -100,7 +100,12 @@ function assertAsyncDone(iteration) {
(function() {
Promise.resolve(5).then(undefined, assertUnreachable).chain(
function(x) { assertAsync(x === 5, "resolved/then-nohandler") },
function(x) { assertAsync(x === 5, "resolved/then-nohandler-undefined") },
assertUnreachable
)
assertAsyncRan()
Promise.resolve(6).then(null, assertUnreachable).chain(
function(x) { assertAsync(x === 6, "resolved/then-nohandler-null") },
assertUnreachable
)
assertAsyncRan()
......@@ -109,7 +114,12 @@ function assertAsyncDone(iteration) {
(function() {
Promise.reject(5).then(assertUnreachable, undefined).chain(
assertUnreachable,
function(r) { assertAsync(r === 5, "rejected/then-nohandler") }
function(r) { assertAsync(r === 5, "rejected/then-nohandler-undefined") }
)
assertAsyncRan()
Promise.reject(6).then(assertUnreachable, null).chain(
assertUnreachable,
function(r) { assertAsync(r === 6, "rejected/then-nohandler-null") }
)
assertAsyncRan()
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment