From 10168c3e1dab54387f52bd36fdd527ea55922479 Mon Sep 17 00:00:00 2001 From: Tim Finley Date: Fri, 16 Jun 2017 13:15:28 -0400 Subject: [PATCH 1/3] Adds `Q.getUnhandledRejectionValues()` function for debug access to the actual rejection values (and not only the string-ified reasons in `Q.getUnhandledReasons()`). --- q.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/q.js b/q.js index 6e467958..a9558e72 100644 --- a/q.js +++ b/q.js @@ -1118,6 +1118,12 @@ Q.getUnhandledReasons = function () { return unhandledReasons.slice(); }; +Q.getUnhandledRejectionValues = function () { + return unhandledRejections.map(function(rejectedPromise) { + return rejectedPromise.exception; + }); +}; + Q.stopUnhandledRejectionTracking = function () { resetUnhandledRejections(); trackUnhandledRejections = false; From 432ab751d74d8c7fab0436a864002df242ee5619 Mon Sep 17 00:00:00 2001 From: Tim Finley Date: Fri, 16 Jun 2017 13:15:47 -0400 Subject: [PATCH 2/3] A couple tests --- spec/q-spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/q-spec.js b/spec/q-spec.js index 6d4068b5..383e04e7 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -2976,4 +2976,21 @@ describe("unhandled rejection reporting", function () { expect(Q.getUnhandledReasons()).toEqual([]); }); + + describe("getUnhandledRejectionValues", function () { + it("contains a reference to the rejection value", function () { + var rejectionRef = { some: "reason" }; + Q.reject(rejectionRef); + + expect(Q.getUnhandledRejectionValues()).toEqual([rejectionRef]); + }); + + it("resets after calling `Q.resetUnhandledRejections`", function () { + Q.reject("a reason"); + + Q.resetUnhandledRejections(); + expect(Q.getUnhandledRejectionValues()).toEqual([]); + }); + }); + }); From e66fb3895020858206ed7e0c90bde1d81b269494 Mon Sep 17 00:00:00 2001 From: Tim Finley Date: Fri, 16 Jun 2017 13:21:51 -0400 Subject: [PATCH 3/3] Use `array_map` helper instead of Array.prorotype.map (to maintain browser support) --- q.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/q.js b/q.js index a9558e72..e2f09093 100644 --- a/q.js +++ b/q.js @@ -1119,7 +1119,7 @@ Q.getUnhandledReasons = function () { }; Q.getUnhandledRejectionValues = function () { - return unhandledRejections.map(function(rejectedPromise) { + return array_map(unhandledRejections, function(rejectedPromise) { return rejectedPromise.exception; }); };