Commit 32559fcb authored by Domenic Denicola's avatar Domenic Denicola

Make `RSVP.denodeify` pass along `thisArg`.

See discussion in #55.
parent 8c80ba5e
......@@ -16,6 +16,7 @@ function makeNodeCallbackFor(resolve, reject) {
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var thisArg = this;
var promise = new Promise(function(nodeResolve, nodeReject) {
resolve = nodeResolve;
......@@ -26,7 +27,7 @@ function denodeify(nodeFunc) {
nodeArgs.push(makeNodeCallbackFor(resolve, reject));
try {
nodeFunc.apply(this, nodeArgs);
nodeFunc.apply(thisArg, nodeArgs);
} catch(e) {
reject(e);
}
......
......@@ -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) {
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