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) { ...@@ -210,7 +210,10 @@ function PromiseHandle(value, handler, deferred) {
// Multi-unwrapped chaining with thenable coercion. // Multi-unwrapped chaining with thenable coercion.
function PromiseThen(onResolve, onReject) { 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 that = this;
var constructor = this.constructor; var constructor = this.constructor;
return this.chain( return this.chain(
...@@ -230,11 +233,10 @@ function PromiseCoerce(constructor, x) { ...@@ -230,11 +233,10 @@ function PromiseCoerce(constructor, x) {
var then; var then;
try { try {
then = x.then; then = x.then;
} catch(e) { } catch(r) {
var deferred = %_CallFunction(constructor, PromiseDeferred); var promise = %_CallFunction(constructor, r, PromiseRejected);
PromiseCoerce.table.set(x, deferred.promise); PromiseCoerce.table.set(x, promise);
deferred.reject(e); return promise;
return deferred.promise;
} }
if (typeof then === 'function') { if (typeof then === 'function') {
if (PromiseCoerce.table.has(x)) { if (PromiseCoerce.table.has(x)) {
...@@ -244,8 +246,8 @@ function PromiseCoerce(constructor, x) { ...@@ -244,8 +246,8 @@ function PromiseCoerce(constructor, x) {
PromiseCoerce.table.set(x, deferred.promise); PromiseCoerce.table.set(x, deferred.promise);
try { try {
%_CallFunction(x, deferred.resolve, deferred.reject, then); %_CallFunction(x, deferred.resolve, deferred.reject, then);
} catch(e) { } catch(r) {
deferred.reject(e); deferred.reject(r);
} }
return deferred.promise; return deferred.promise;
} }
......
...@@ -100,7 +100,12 @@ function assertAsyncDone(iteration) { ...@@ -100,7 +100,12 @@ function assertAsyncDone(iteration) {
(function() { (function() {
Promise.resolve(5).then(undefined, assertUnreachable).chain( 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 assertUnreachable
) )
assertAsyncRan() assertAsyncRan()
...@@ -109,7 +114,12 @@ function assertAsyncDone(iteration) { ...@@ -109,7 +114,12 @@ function assertAsyncDone(iteration) {
(function() { (function() {
Promise.reject(5).then(assertUnreachable, undefined).chain( Promise.reject(5).then(assertUnreachable, undefined).chain(
assertUnreachable, 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() 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