From 67e9298fb6509d5f6ad2f7e67620a2d82549a1e8 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 15 Jan 2014 17:16:22 -0800 Subject: [PATCH] child_process: fix spawn() optional arguments Spawn's arguments were documented to be optional, as they are for the other similar child_process APIs, but the code was missing. Result was `child_process.spawn('node', {})` errored when calling slice() on an Object, now it behaves as the documentation said it would. --- lib/child_process.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index f7312215cd..eec0313337 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -695,8 +695,16 @@ exports.execFile = function(file /* args, options, callback */) { }; -var spawn = exports.spawn = function(file, args, options) { - args = args ? args.slice(0) : []; +var spawn = exports.spawn = function(file /*, args, options*/) { + var args, options; + if (Array.isArray(arguments[1])) { + args = arguments[1].slice(0); + options = arguments[2]; + } else { + args = []; + options = arguments[1]; + } + args.unshift(file); var env = (options ? options.env : null) || process.env;