Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

treat undefined the same as null #6

Merged
merged 1 commit into from about 2 years ago

2 participants

Aaron Heckmann Brian Noguchi
Aaron Heckmann

so we can next(undefined) or next(null) or next()

fixes LearnBoost/mongoose#785

Aaron Heckmann treat undefined the same as null
so we can next(undefined) or next(null) or next()
d47a376
Brian Noguchi bnoguchi merged commit 89d472a into from April 17, 2012
Brian Noguchi bnoguchi closed this April 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 16, 2012
Aaron Heckmann treat undefined the same as null
so we can next(undefined) or next(null) or next()
d47a376
This page is out of date. Refresh to see the latest.

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();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.