From: Toshihiro Nakamura Date: Sun, 8 Jul 2012 00:30:07 +0000 (+0900) Subject: domain: Remove first arg from intercepted fn X-Git-Tag: v0.8.3~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6530310ed59c1056aa71c17133b5dbee87e2415c;p=platform%2Fupstream%2Fnodejs.git 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 --- diff --git a/lib/domain.js b/lib/domain.js index 7c4a852..1524627 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -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; } diff --git a/test/simple/test-domain.js b/test/simple/test-domain.js index ee2ddd5..a478c1e 100644 --- a/test/simple/test-domain.js +++ b/test/simple/test-domain.js @@ -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