Skip to content

Commit

Permalink
domain: Remove first arg from intercepted fn
Browse files Browse the repository at this point in the history
Fix to remove the first-arg, in case arguments length is more than 2
Add domain.intercept() test about first-arg removal
  • Loading branch information
nakamura-to authored and isaacs committed Jul 9, 2012
1 parent 2a8380c commit 6530310
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Domain.prototype.bind = function(cb, interceptError) {
// slower for less common case: cb(er, foo, bar, baz, ...)
args = new Array(len - 1);
for (var i = 1; i < len; i++) {
args[i] = arguments[i - 1];
args[i - 1] = arguments[i];
}
break;
}
Expand Down
9 changes: 9 additions & 0 deletions test/simple/test-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ function fn2(data) {
var bound = d.intercept(fn2);
bound(null, 'data');

// intercepted should never pass first argument to callback
// even if arguments length is more than 2.
function fn3(data, data2) {
assert.equal(data, 'data', 'should not be null err argument');
assert.equal(data2, 'data2', 'should not be data argument');
}

bound = d.intercept(fn3);
bound(null, 'data', 'data2');

// throwing in a bound fn is also caught,
// even if it's asynchronous, by hitting the
Expand Down

0 comments on commit 6530310

Please sign in to comment.