diff options
-rw-r--r-- | lib/async.js | 2 | ||||
-rwxr-xr-x | test/test-async.js | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/async.js b/lib/async.js index 629b2a5..bfc8bdd 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 fa4f6c4..88fa9ae 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){ |