From 63948a81dd6196227af3f382575982f89b5cf7d8 Mon Sep 17 00:00:00 2001 From: RBLU Date: Tue, 2 Jun 2015 20:45:44 +0200 Subject: [PATCH] fix(each): each with empty array that has other property never calls final callback --- lib/async.js | 2 +- test/test-async.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/async.js b/lib/async.js index 629b2a5fd..bfc8bdd69 100644 --- a/lib/async.js +++ b/lib/async.js @@ -221,7 +221,7 @@ async.eachOf = function (object, iterator, callback) { callback = _once(callback || noop); object = object || []; - var size = object.length || _keys(object).length; + var size = _isArrayLike(object) ? object.length : _keys(object).length; var completed = 0; if (!size) { return callback(null); diff --git a/test/test-async.js b/test/test-async.js index fa4f6c45e..88fa9ae8f 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1375,6 +1375,22 @@ exports['each empty array'] = function(test){ setTimeout(test.done, 25); }; + +exports['each empty array, with other property on the array'] = function(test){ + test.expect(1); + var myArray = []; + myArray.myProp = "anything"; + async.each(myArray, function(x, callback){ + test.ok(false, 'iterator should not be called'); + callback(); + }, function(err){ + if (err) throw err; + test.ok(true, 'should call callback'); + }); + setTimeout(test.done, 25); +}; + + exports['each error'] = function(test){ test.expect(1); async.each([1,2,3], function(x, callback){