summaryrefslogtreecommitdiff
path: root/lib/child_process.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/child_process.js')
-rw-r--r--lib/child_process.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index 0c1b4c99c..53e0bb24f 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -591,7 +591,7 @@ exports.exec = function(command /*, options, callback */) {
exports.execFile = function(file /* args, options, callback */) {
- var args, optionArg, callback;
+ var args = [], optionArg, callback;
var options = {
encoding: 'utf8',
timeout: 0,
@@ -601,18 +601,28 @@ exports.execFile = function(file /* args, options, callback */) {
env: null
};
- // Parse the parameters.
+ // Parse the optional positional parameters.
+ var pos = 1;
+ if (pos < arguments.length && Array.isArray(arguments[pos])) {
+ args = arguments[pos++];
+ }
+ else if(pos < arguments.length && arguments[pos] == null) {
+ pos++;
+ }
- if (typeof arguments[arguments.length - 1] === 'function') {
- callback = arguments[arguments.length - 1];
+ if (pos < arguments.length && typeof arguments[pos] === 'object') {
+ options = util._extend(options, arguments[pos++]);
+ }
+ else if(pos < arguments.length && arguments[pos] == null) {
+ pos++;
}
- if (Array.isArray(arguments[1])) {
- args = arguments[1];
- options = util._extend(options, arguments[2]);
- } else {
- args = [];
- options = util._extend(options, arguments[1]);
+ if (pos < arguments.length && typeof arguments[pos] === 'function') {
+ callback = arguments[pos++];
+ }
+
+ if (pos === 1 && arguments.length > 1) {
+ throw new TypeError('Incorrect value of args option');
}
var child = spawn(file, args, {