Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Sep 10, 2018
1 parent 1ba4bf7 commit 9be07de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rsvp/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9be07de

Please sign in to comment.