Skip to content

Commit

Permalink
Fix kriskowal#198: inspecting promises rejected with falsy reasons.
Browse files Browse the repository at this point in the history
The fix is a bit hacky, but until we get a proper story for synchronous inspection, I think it suffices.
  • Loading branch information
domenic committed Feb 10, 2013
1 parent 85309a8 commit 4522f7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ function promise(makePromise) {
* bought and sold.
*/
Q.makePromise = makePromise;
function makePromise(descriptor, fallback, valueOf, exception) {
function makePromise(descriptor, fallback, valueOf, exception, isException) {
if (fallback === void 0) {
fallback = function (op) {
return reject(new Error("Promise does not support operation: " + op));
Expand Down Expand Up @@ -493,7 +493,7 @@ function makePromise(descriptor, fallback, valueOf, exception) {
promise.valueOf = valueOf;
}

if (exception) {
if (isException) {
promise.exception = exception;
}

Expand Down Expand Up @@ -661,7 +661,7 @@ function reject(exception) {
return reject(exception);
}, function valueOf() {
return this;
}, exception);
}, exception, true);
// note that the error has not been handled
displayErrors();
rejections.push(rejection);
Expand Down
7 changes: 7 additions & 0 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,13 @@ describe("promise states", function () {
expect(promise.isPending()).toBe(false);
});

it("of rejection with a falsy value", function () {
var promise = Q.reject(undefined);
expect(promise.isFulfilled()).toBe(false);
expect(promise.isRejected()).toBe(true);
expect(promise.isPending()).toBe(false);
});

it("of deferred", function () {
var deferred = Q.defer();
var promise = deferred.promise;
Expand Down

0 comments on commit 4522f7d

Please sign in to comment.