@@ -248,6 +248,40 @@ ObjectDefineProperty(exec, promisify.custom, {
248248 value : customPromiseExecFunction ( exec )
249249} ) ;
250250
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+
251285/**
252286 * Spawns the specified file as a shell.
253287 * @param {string } file
@@ -274,26 +308,7 @@ ObjectDefineProperty(exec, promisify.custom, {
274308 * @returns {ChildProcess }
275309 */
276310function 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 ) ;
297312
298313 options = {
299314 encoding : 'utf8' ,
@@ -841,17 +856,22 @@ function checkExecSyncError(ret, args, cmd) {
841856 * }} [options]
842857 * @returns {Buffer | string }
843858 */
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 ) ;
846861
847862 const inheritStderr = ! options . stdio ;
848- const ret = spawnSync ( options . file ,
849- ArrayPrototypeSlice ( options . args , 1 ) , options ) ;
863+ const ret = spawnSync ( file , args , options ) ;
850864
851865 if ( inheritStderr && ret . stderr )
852866 process . stderr . write ( ret . stderr ) ;
853867
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 ) ;
855875
856876 if ( err )
857877 throw err ;
0 commit comments