Commit 00a9b910 authored by Stefan Penner's avatar Stefan Penner

Merge pull request #77 from domenic/denodeify-this-fix

Make `RSVP.denodeify` pass along `thisArg`.
parents 8c80ba5e 32559fcb
...@@ -16,6 +16,7 @@ function makeNodeCallbackFor(resolve, reject) { ...@@ -16,6 +16,7 @@ function makeNodeCallbackFor(resolve, reject) {
function denodeify(nodeFunc) { function denodeify(nodeFunc) {
return function() { return function() {
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject; var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var thisArg = this;
var promise = new Promise(function(nodeResolve, nodeReject) { var promise = new Promise(function(nodeResolve, nodeReject) {
resolve = nodeResolve; resolve = nodeResolve;
...@@ -26,7 +27,7 @@ function denodeify(nodeFunc) { ...@@ -26,7 +27,7 @@ function denodeify(nodeFunc) {
nodeArgs.push(makeNodeCallbackFor(resolve, reject)); nodeArgs.push(makeNodeCallbackFor(resolve, reject));
try { try {
nodeFunc.apply(this, nodeArgs); nodeFunc.apply(thisArg, nodeArgs);
} catch(e) { } catch(e) {
reject(e); reject(e);
} }
......
...@@ -273,6 +273,23 @@ describe("RSVP extensions", function() { ...@@ -273,6 +273,23 @@ describe("RSVP extensions", function() {
}); });
}); });
specify('calls node function with same thisArg', function(done) {
var thisArg = null;
function nodeFunc(cb) {
thisArg = this;
cb();
}
var denodeifiedFunc = RSVP.denodeify(nodeFunc);
var expectedThis = { expect: "me" };
denodeifiedFunc.call(expectedThis).then(function() {
assert.equal(thisArg, expectedThis);
done();
});
});
specify('waits for promise/thenable arguments to settle before passing them to the node function', function(done) { specify('waits for promise/thenable arguments to settle before passing them to the node function', function(done) {
var args = null; var args = null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment