Skip to content

Commit 6530310

Browse files
nakamura-toisaacs
authored andcommitted
domain: Remove first arg from intercepted fn
Fix to remove the first-arg, in case arguments length is more than 2 Add domain.intercept() test about first-arg removal
1 parent 2a8380c commit 6530310

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/domain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Domain.prototype.bind = function(cb, interceptError) {
185185
// slower for less common case: cb(er, foo, bar, baz, ...)
186186
args = new Array(len - 1);
187187
for (var i = 1; i < len; i++) {
188-
args[i] = arguments[i - 1];
188+
args[i - 1] = arguments[i];
189189
}
190190
break;
191191
}

test/simple/test-domain.js

+9
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ function fn2(data) {
150150
var bound = d.intercept(fn2);
151151
bound(null, 'data');
152152

153+
// intercepted should never pass first argument to callback
154+
// even if arguments length is more than 2.
155+
function fn3(data, data2) {
156+
assert.equal(data, 'data', 'should not be null err argument');
157+
assert.equal(data2, 'data2', 'should not be data argument');
158+
}
159+
160+
bound = d.intercept(fn3);
161+
bound(null, 'data', 'data2');
153162

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

0 commit comments

Comments
 (0)