diff options
-rw-r--r-- | lib/async.js | 14 | ||||
-rwxr-xr-x | test/test-async.js | 11 |
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/async.js b/lib/async.js index f80dbcf..9c2b6af 100644 --- a/lib/async.js +++ b/lib/async.js @@ -62,6 +62,12 @@ return _toString.call(obj) === '[object Array]'; }; + // Ported from underscore.js isObject + var _isObject = function(obj) { + var type = typeof obj; + return type === 'function' || type === 'object' && !!obj; + }; + function _isArrayLike(arr) { return _isArray(arr) || ( // has a positive integer length property @@ -1012,7 +1018,7 @@ function _console_fn(name) { return _restParam(function (fn, args) { fn.apply(null, args.concat([_restParam(function (err, args) { - if (typeof console !== 'undefined') { + if (typeof console === 'object') { if (err) { if (console.error) { console.error(err); @@ -1185,7 +1191,7 @@ return callback(e); } // if result is Promise object - if (typeof result !== 'undefined' && typeof result.then === "function") { + if (_isObject(result) && typeof result.then === "function") { result.then(function(value) { callback(null, value); }).catch(function(err) { @@ -1198,11 +1204,11 @@ }; // Node.js - if (typeof module !== 'undefined' && module.exports) { + if (typeof module === 'object' && module.exports) { module.exports = async; } // AMD / RequireJS - else if (typeof define !== 'undefined' && define.amd) { + else if (typeof define === 'function' && define.amd) { define([], function () { return async; }); diff --git a/test/test-async.js b/test/test-async.js index 72ef132..8a7ea8d 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -4311,6 +4311,17 @@ exports['asyncify'] = { }); }, + 'asyncify null': function (test) { + var parse = async.asyncify(function() { + return null; + }); + parse("{\"a\":1}", function (err, result) { + test.ok(!err); + test.ok(result === null); + test.done(); + }); + }, + 'variable numbers of arguments': function (test) { async.asyncify(function (x, y, z) { test.ok(arguments.length === 3); |