diff --git a/lib/child_process.js b/lib/child_process.js index e19f4ff89d2..0c1b4c99c1f 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -711,7 +711,7 @@ var spawn = exports.spawn = function(file /*, args, options*/) { if (Array.isArray(arguments[1])) { args = arguments[1].slice(0); options = arguments[2]; - } else if (arguments[1] && !Array.isArray(arguments[1])) { + } else if (arguments[1] && typeof arguments[1] !== 'object') { throw new TypeError('Incorrect value of args option'); } else { args = []; diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js index 791adcbc208..d18ce943ec9 100644 --- a/test/simple/test-child-process-spawn-typeerror.js +++ b/test/simple/test-child-process-spawn-typeerror.js @@ -22,12 +22,13 @@ var spawn = require('child_process').spawn, assert = require('assert'), windows = (process.platform === 'win32'), - cmd = (windows) ? 'ls' : 'dir', + cmd = (windows) ? 'dir' : 'ls', + invalidcmd = (windows) ? 'ls' : 'dir', errors = 0; try { // Ensure this throws a TypeError - var child = spawn(cmd, 'this is not an array'); + var child = spawn(invalidcmd, 'this is not an array'); child.on('error', function (err) { errors++; @@ -37,6 +38,11 @@ try { assert.equal(e instanceof TypeError, true); } +// verify that args argument is optional +assert.doesNotThrow(function() { + spawn(cmd, {}); +}); + process.on('exit', function() { assert.equal(errors, 0); });