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) {
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