diff --git a/lib/child_process.js b/lib/child_process.js index 6cce1b09e565..a78664c4abd4 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -59,22 +59,29 @@ function stdioStringToArray(option) { } exports.fork = function fork(modulePath /* , args, options */) { - // Get options and args arguments. var execArgv; - var options = {}; - var args = []; - var pos = 1; - if (pos < arguments.length && Array.isArray(arguments[pos])) { - args = arguments[pos++]; - } - if (pos < arguments.length && arguments[pos] != null) { - if (typeof arguments[pos] !== 'object') { - throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]); - } + var args = arguments[1]; + var options = arguments[2]; + + if (Array.isArray(args)) { + args = args.slice(0); + } else if (options !== undefined && + (args === undefined || + args === null || + typeof args !== 'object') + ) { + args = []; + } else { + options = args; + args = []; + } - options = util._extend({}, arguments[pos++]); + if (options === undefined || options === null) { + options = {}; + } else if (typeof options !== 'object') { + throw new ERR_INVALID_ARG_VALUE('options', 'object', options); } // Prepare arguments for fork: