@@ -45,15 +45,24 @@ let debug = require('internal/util/debuglog').debuglog(
4545) ;
4646const { Buffer } = require ( 'buffer' ) ;
4747const { Pipe, constants : PipeConstants } = internalBinding ( 'pipe_wrap' ) ;
48+
49+ const {
50+ AbortError,
51+ codes : errorCodes ,
52+ } = require ( 'internal/errors' ) ;
4853const {
4954 ERR_INVALID_ARG_VALUE ,
5055 ERR_CHILD_PROCESS_IPC_REQUIRED ,
5156 ERR_CHILD_PROCESS_STDIO_MAXBUFFER ,
5257 ERR_INVALID_ARG_TYPE ,
53- ERR_OUT_OF_RANGE
54- } = require ( 'internal/errors' ) . codes ;
58+ ERR_OUT_OF_RANGE ,
59+ } = errorCodes ;
5560const { clearTimeout, setTimeout } = require ( 'timers' ) ;
56- const { validateString, isInt32 } = require ( 'internal/validators' ) ;
61+ const {
62+ validateString,
63+ isInt32,
64+ validateAbortSignal,
65+ } = require ( 'internal/validators' ) ;
5766const child_process = require ( 'internal/child_process' ) ;
5867const {
5968 getValidStdio,
@@ -232,6 +241,9 @@ function execFile(file /* , args, options, callback */) {
232241 // Validate maxBuffer, if present.
233242 validateMaxBuffer ( options . maxBuffer ) ;
234243
244+ // Validate signal, if present
245+ validateAbortSignal ( options . signal , 'options.signal' ) ;
246+
235247 options . killSignal = sanitizeKillSignal ( options . killSignal ) ;
236248
237249 const child = spawn ( file , args , {
@@ -349,6 +361,20 @@ function execFile(file /* , args, options, callback */) {
349361 timeoutId = null ;
350362 } , options . timeout ) ;
351363 }
364+ if ( options . signal ) {
365+ if ( options . signal . aborted ) {
366+ process . nextTick ( ( ) => kill ( ) ) ;
367+ } else {
368+ options . signal . addEventListener ( 'abort' , ( ) => {
369+ if ( ! ex ) {
370+ ex = new AbortError ( ) ;
371+ }
372+ kill ( ) ;
373+ } ) ;
374+ const remove = ( ) => options . signal . removeEventListener ( 'abort' , kill ) ;
375+ child . once ( 'close' , remove ) ;
376+ }
377+ }
352378
353379 if ( child . stdout ) {
354380 if ( encoding )
0 commit comments