diff --git a/lib/rsvp/promise.js b/lib/rsvp/promise.js index 6f3af6ea..da1523a8 100644 --- a/lib/rsvp/promise.js +++ b/lib/rsvp/promise.js @@ -228,8 +228,12 @@ class Promise { let promise = this; let constructor = promise.constructor; - return promise.then(value => constructor.resolve(callback()).then(() => value), - reason => constructor.resolve(callback()).then(() => { throw reason; }), label); + if (typeof callback === 'function') { + return promise.then(value => constructor.resolve(callback()).then(() => value), + reason => constructor.resolve(callback()).then(() => { throw reason; })); + } + + return promise.then(callback, callback); } } diff --git a/test/extension-test.js b/test/extension-test.js index 31d727c2..221997d1 100644 --- a/test/extension-test.js +++ b/test/extension-test.js @@ -2508,6 +2508,23 @@ describe("RSVP extensions", function() { }); }); }); + + it("preserves the original fulfillment value even if a non-callable callback is given", function(done) { + var fulfillmentValue = 1; + var promise = Promise.resolve(fulfillmentValue); + promise['finally']().then(function(value) { + assert.equal(fulfillmentValue, value); + done(); + }); + }); + it("preserves the original rejection reason even if a non-callable callback is given", function(done) { + var rejectionReason = new Error(); + var promise = Promise.reject(rejectionReason); + promise['finally']().then(undefined, function(reason) { + assert.equal(rejectionReason, reason); + done(); + }); + }); }); describe("inheritance", function() {