Permalink
Browse files

Fix next() passing extra arguments as error to last function.

  • Loading branch information...
1 parent 3401fae commit 940dfc1791e445f5832931aeb70fbe14b272d586 Chakrit Wichian committed Feb 8, 2013
Showing with 13 additions and 2 deletions.
  1. +4 −2 lib/jam.js
  2. +9 −0 test/jam.js
View
@@ -165,8 +165,10 @@ module.exports = (function() {
var next = steps.shift()
, args = Array.prototype.slice.call(arguments)
- args.shift(); // error arg.
- if (steps.length) args.unshift(resolve); // next arg. replacement
+ if (steps.length) {
+ args.shift(); // error arg
+ args.unshift(resolve); // next() function
+ }
return next.apply(this, args);
});
View
@@ -68,6 +68,15 @@
});
});
+ it('should not pass error to the last function in the chain if arguments were given to last `next` call', function(done) {
+ this.jam(function(next) { next(null, 'one', 'two', 'three'); })
+ (function(e) {
+ // 'one' may accidentally be passed due to an arguments shifting bug
+ assert.ok(!e);
+ done();
+ });
+ });
+
it('should pass error to the last function in the chain if error is given to `next`', function(done) {
var e = new Error('test');

0 comments on commit 940dfc1

Please sign in to comment.