diff --git a/lib/child_process.js b/lib/child_process.js index 53e0bb24ff4..640f68e617a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -525,6 +525,8 @@ exports.fork = function(modulePath /*, args, options*/) { if (Array.isArray(arguments[1])) { args = arguments[1]; options = util._extend({}, arguments[2]); + } else if (arguments[1] && typeof arguments[1] !== 'object') { + throw new TypeError('Incorrect value of args option'); } else { args = []; options = util._extend({}, arguments[1]); diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js index b5d1249e588..e28bd2a519a 100644 --- a/test/simple/test-child-process-spawn-typeerror.js +++ b/test/simple/test-child-process-spawn-typeerror.js @@ -22,8 +22,10 @@ var assert = require('assert'); var child_process = require('child_process'); var spawn = child_process.spawn; +var fork = child_process.fork; var execFile = child_process.execFile; var cmd = (process.platform === 'win32') ? 'dir' : 'ls'; +var empty = require('../common').fixturesDir + '/empty.js'; // verify that args argument must be an array @@ -45,3 +47,12 @@ assert.throws(function() { assert.doesNotThrow(function() { execFile(cmd, {}); }); + +// verify that fork has same argument parsing behaviour as spawn +assert.throws(function() { + fork(empty, 'this is not an array'); +}, TypeError); + +assert.doesNotThrow(function() { + execFile(empty, {}); +});