@@ -248,6 +248,40 @@ ObjectDefineProperty(exec, promisify.custom, {
248
248
value : customPromiseExecFunction ( exec )
249
249
} ) ;
250
250
251
+ function normalizeExecFileArgs ( file , args , options , callback ) {
252
+ if ( ArrayIsArray ( args ) ) {
253
+ args = ArrayPrototypeSlice ( args )
254
+ } else if ( args != null && typeof args === 'object' ) {
255
+ callback = options ;
256
+ options = args ;
257
+ args = null ;
258
+ } else if ( typeof args === 'function' ) {
259
+ callback = args ;
260
+ options = null ;
261
+ args = null ;
262
+ }
263
+
264
+ if ( args == null ) {
265
+ args = [ ] ;
266
+ }
267
+
268
+ if ( typeof options === 'function' ) {
269
+ callback = options ;
270
+ } else if ( options != null ) {
271
+ validateObject ( options , 'options' ) ;
272
+ }
273
+
274
+ if ( options == null ) {
275
+ options = { } ;
276
+ }
277
+
278
+ if ( callback != null ) {
279
+ validateFunction ( callback , 'callback' ) ;
280
+ }
281
+
282
+ return [ file , args , options , callback ] ;
283
+ }
284
+
251
285
/**
252
286
* Spawns the specified file as a shell.
253
287
* @param {string } file
@@ -274,26 +308,7 @@ ObjectDefineProperty(exec, promisify.custom, {
274
308
* @returns {ChildProcess }
275
309
*/
276
310
function execFile ( file , args = [ ] , options , callback ) {
277
- if ( args != null && typeof args === 'object' && ! ArrayIsArray ( args ) ) {
278
- callback = options ;
279
- options = args ;
280
- args = null ;
281
- } else if ( typeof args === 'function' ) {
282
- callback = args ;
283
- options = null ;
284
- args = null ;
285
- }
286
-
287
- if ( typeof options === 'function' ) {
288
- callback = options ;
289
- options = null ;
290
- } else if ( options != null ) {
291
- validateObject ( options , 'options' ) ;
292
- }
293
-
294
- if ( callback != null ) {
295
- validateFunction ( callback , 'callback' ) ;
296
- }
311
+ [ file , args , options , callback ] = normalizeExecFileArgs ( file , args , options , callback ) ;
297
312
298
313
options = {
299
314
encoding : 'utf8' ,
@@ -841,17 +856,22 @@ function checkExecSyncError(ret, args, cmd) {
841
856
* }} [options]
842
857
* @returns {Buffer | string }
843
858
*/
844
- function execFileSync ( command , args , options ) {
845
- options = normalizeSpawnArguments ( command , args , options ) ;
859
+ function execFileSync ( file , args , options ) {
860
+ [ file , args , options ] = normalizeExecFileArgs ( file , args , options ) ;
846
861
847
862
const inheritStderr = ! options . stdio ;
848
- const ret = spawnSync ( options . file ,
849
- ArrayPrototypeSlice ( options . args , 1 ) , options ) ;
863
+ const ret = spawnSync ( file , args , options ) ;
850
864
851
865
if ( inheritStderr && ret . stderr )
852
866
process . stderr . write ( ret . stderr ) ;
853
867
854
- const err = checkExecSyncError ( ret , options . args , undefined ) ;
868
+ if ( typeof options . argv0 === 'string' ) {
869
+ ArrayPrototypeUnshift ( args , options . argv0 ) ;
870
+ } else {
871
+ ArrayPrototypeUnshift ( args , file ) ;
872
+ }
873
+
874
+ const err = checkExecSyncError ( ret , args ) ;
855
875
856
876
if ( err )
857
877
throw err ;
0 commit comments