From 2dc17aa16127182d666fd5c5420c9b2edfede551 Mon Sep 17 00:00:00 2001 From: Daniel Foley Date: Wed, 9 Apr 2014 14:02:08 -0700 Subject: [PATCH] 170 Promise#nodeify should not pass as an explicit argument to a Node.js continuation callback --- src/nodeify.js | 4 +++- test/mocha/q_nodeify.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nodeify.js b/src/nodeify.js index e98eef876..ab7985ab8 100644 --- a/src/nodeify.js +++ b/src/nodeify.js @@ -14,7 +14,9 @@ function thrower(r) { function Promise$_successAdapter(val, receiver) { var nodeback = this; ASSERT(typeof nodeback == "function"); - var ret = tryCatch2(nodeback, receiver, null, val); + var ret = val === void 0 + ? tryCatch1(nodeback, receiver, null) + : tryCatch2(nodeback, receiver, null, val); if (ret === errorObj) { async.invokeLater(thrower, void 0, ret.e); } diff --git a/test/mocha/q_nodeify.js b/test/mocha/q_nodeify.js index c4ddbab2c..a39a82c11 100644 --- a/test/mocha/q_nodeify.js +++ b/test/mocha/q_nodeify.js @@ -110,7 +110,16 @@ describe("nodeify", function () { sinon.assert.calledOnce(spy); sinon.assert.calledWith(spy, null, 10); }, 100); + }); + it("calls back with an undefined resolution", function (done) { + var spy = sinon.spy(); + Q().nodeify(spy); + setTimeout(function(){ + sinon.assert.calledOnce(spy); + sinon.assert.calledWithExactly(spy, null); + done(); + }, 10); }); it("calls back with an error", function () {