@@ -111,28 +111,27 @@ const MAX_BUFFER = 1024 * 1024;
111
111
* }} [options]
112
112
* @returns {ChildProcess }
113
113
*/
114
- function fork ( modulePath /* , args, options */ ) {
114
+ function fork ( modulePath , args = [ ] , options ) {
115
115
modulePath = getValidatedPath ( modulePath , 'modulePath' ) ;
116
116
117
117
// Get options and args arguments.
118
118
let execArgv ;
119
- let options = { } ;
120
- let args = [ ] ;
121
- let pos = 1 ;
122
- if ( pos < arguments . length && ArrayIsArray ( arguments [ pos ] ) ) {
123
- args = arguments [ pos ++ ] ;
124
- }
125
119
126
- if ( pos < arguments . length && arguments [ pos ] == null ) {
127
- pos ++ ;
120
+ if ( args == null ) {
121
+ args = [ ] ;
122
+ } else if ( typeof args !== 'object' ) {
123
+ throw new ERR_INVALID_ARG_VALUE ( 'args' , args ) ;
124
+ } else if ( ! ArrayIsArray ( args ) ) {
125
+ options = args ;
126
+ args = [ ] ;
128
127
}
129
128
130
- if ( pos < arguments . length && arguments [ pos ] ! = null ) {
131
- if ( typeof arguments [ pos ] !== 'object' ) {
132
- throw new ERR_INVALID_ARG_VALUE ( `arguments[ ${ pos } ]` , arguments [ pos ] ) ;
133
- }
134
-
135
- options = { ...arguments [ pos ++ ] } ;
129
+ if ( options = = null ) {
130
+ options = { } ;
131
+ } else if ( typeof options !== 'object' ) {
132
+ throw new ERR_INVALID_ARG_VALUE ( 'options' , options ) ;
133
+ } else {
134
+ options = { ...options } ;
136
135
}
137
136
138
137
// Prepare arguments for fork:
@@ -276,31 +275,34 @@ ObjectDefineProperty(exec, promisify.custom, {
276
275
* ) => any} [callback]
277
276
* @returns {ChildProcess }
278
277
*/
279
- function execFile ( file /* , args, options, callback */ ) {
280
- let args = [ ] ;
281
- let callback ;
282
- let options ;
283
-
284
- // Parse the optional positional parameters.
285
- let pos = 1 ;
286
- if ( pos < arguments . length && ArrayIsArray ( arguments [ pos ] ) ) {
287
- args = arguments [ pos ++ ] ;
288
- } else if ( pos < arguments . length && arguments [ pos ] == null ) {
289
- pos ++ ;
290
- }
291
-
292
- if ( pos < arguments . length && typeof arguments [ pos ] === 'object' ) {
293
- options = arguments [ pos ++ ] ;
294
- } else if ( pos < arguments . length && arguments [ pos ] == null ) {
295
- pos ++ ;
278
+ function execFile ( file , args = [ ] , options , callback ) {
279
+ if ( args == null ) {
280
+ args = [ ] ;
281
+ } else if ( typeof args === 'object' ) {
282
+ if ( ! ArrayIsArray ( args ) ) {
283
+ callback = options ;
284
+ options = args ;
285
+ args = [ ] ;
286
+ }
287
+ } else if ( typeof args === 'function' ) {
288
+ callback = args ;
289
+ options = { } ;
290
+ args = [ ] ;
291
+ } else {
292
+ throw new ERR_INVALID_ARG_VALUE ( 'args' , args ) ;
296
293
}
297
294
298
- if ( pos < arguments . length && typeof arguments [ pos ] === 'function' ) {
299
- callback = arguments [ pos ++ ] ;
295
+ if ( options == null ) {
296
+ options = { } ;
297
+ } else if ( typeof options === 'function' ) {
298
+ callback = options ;
299
+ options = { } ;
300
+ } else if ( typeof options !== 'object' ) {
301
+ throw new ERR_INVALID_ARG_VALUE ( 'options' , options ) ;
300
302
}
301
303
302
- if ( ! callback && pos < arguments . length && arguments [ pos ] != null ) {
303
- throw new ERR_INVALID_ARG_VALUE ( 'args ' , arguments [ pos ] ) ;
304
+ if ( callback && typeof callback !== 'function' ) {
305
+ throw new ERR_INVALID_ARG_VALUE ( 'callback ' , callback ) ;
304
306
}
305
307
306
308
options = {
0 commit comments