Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

treat undefined the same as null

so we can next(undefined) or next(null) or next()
  • Loading branch information...
commit d47a376987d5e64895341bd53bba1b14a50d3f4e 1 parent f778859
Aaron Heckmann authored April 16, 2012

Showing 2 changed files with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. 2  hooks.js
  2. 10  test.js
2  hooks.js
@@ -36,7 +36,7 @@ module.exports = {
36 36
             var _args = Array.prototype.slice.call(arguments)
37 37
               , currPre
38 38
               , preArgs;
39  
-            if (_args.length && !(arguments[0] === null && typeof lastArg === 'function'))
  39
+            if (_args.length && !(arguments[0] == null && typeof lastArg === 'function'))
40 40
               hookArgs = _args;
41 41
             if (++_current < _total) {
42 42
               currPre = pres[_current]
10  test.js
@@ -267,7 +267,7 @@ module.exports = {
267 267
     }
268 268
     didCatch.should.be.true;
269 269
   },
270  
-  "should proceed without mutating arguments if `next(null)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
  270
+  "should proceed without mutating arguments if `next(null|undefined)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
271 271
     var A = function () {};
272 272
     _.extend(A, hooks);
273 273
     var counter = 0;
@@ -278,6 +278,9 @@ module.exports = {
278 278
     A.pre('save', function (next) {
279 279
       next(null);
280 280
     });
  281
+    A.pre('save', function (next) {
  282
+      next(undefined);
  283
+    });
281 284
     var a = new A();
282 285
     a.save( function (err) {
283 286
       if (err instanceof Error) counter++;
@@ -286,13 +289,16 @@ module.exports = {
286 289
     counter.should.equal(-1);
287 290
     a.value.should.eql(1);
288 291
   },
289  
-  "should proceed with mutating arguments if `next(null)` is callback in a serial pre, and the last argument of the target method is not a function": function () {
  292
+  "should proceed with mutating arguments if `next(null|undefined)` is callback in a serial pre, and the last argument of the target method is not a function": function () {
290 293
     var A = function () {};
291 294
     _.extend(A, hooks);
292 295
     A.prototype.set = function (v) {
293 296
       this.value = v;
294 297
     };
295 298
     A.pre('set', function (next) {
  299
+      next(undefined);
  300
+    });
  301
+    A.pre('set', function (next) {
296 302
       next(null);
297 303
     });
298 304
     var a = new A();

0 notes on commit d47a376

Please sign in to comment.
Something went wrong with that request. Please try again.