@@ -146,6 +146,12 @@ exports.execFile = function(file /*, args, options, callback*/) {
146
146
throw new TypeError ( 'Incorrect value of args option' ) ;
147
147
}
148
148
149
+ // Validate the timeout, if present.
150
+ validateTimeout ( options . timeout ) ;
151
+
152
+ // Validate maxBuffer, if present.
153
+ validateMaxBuffer ( options . maxBuffer ) ;
154
+
149
155
var child = spawn ( file , args , {
150
156
cwd : options . cwd ,
151
157
env : options . env ,
@@ -466,31 +472,17 @@ function spawnSync(/*file, args, options*/) {
466
472
debug ( 'spawnSync' , opts . args , options ) ;
467
473
468
474
// Validate the timeout, if present.
469
- if ( options . timeout != null &&
470
- ! ( Number . isInteger ( options . timeout ) && options . timeout >= 0 ) ) {
471
- throw new TypeError ( '"timeout" must be an unsigned integer' ) ;
472
- }
475
+ validateTimeout ( options . timeout ) ;
473
476
474
477
// Validate maxBuffer, if present.
475
- if ( options . maxBuffer != null &&
476
- ! ( Number . isInteger ( options . maxBuffer ) && options . maxBuffer >= 0 ) ) {
477
- throw new TypeError ( '"maxBuffer" must be an unsigned integer' ) ;
478
- }
478
+ validateMaxBuffer ( options . maxBuffer ) ;
479
479
480
480
options . file = opts . file ;
481
481
options . args = opts . args ;
482
482
options . envPairs = opts . envPairs ;
483
483
484
- // Validate the kill signal, if present.
485
- if ( typeof options . killSignal === 'string' ||
486
- typeof options . killSignal === 'number' ) {
487
- options . killSignal = lookupSignal ( options . killSignal ) ;
488
-
489
- if ( options . killSignal === 0 )
490
- throw new RangeError ( '"killSignal" cannot be 0' ) ;
491
- } else if ( options . killSignal != null ) {
492
- throw new TypeError ( '"killSignal" must be a string or number' ) ;
493
- }
484
+ // Validate and translate the kill signal, if present.
485
+ options . killSignal = validateKillSignal ( options . killSignal ) ;
494
486
495
487
options . stdio = _validateStdio ( options . stdio || 'pipe' , true ) . stdio ;
496
488
@@ -600,3 +592,31 @@ function execSync(command /*, options*/) {
600
592
return ret . stdout ;
601
593
}
602
594
exports . execSync = execSync ;
595
+
596
+
597
+ function validateTimeout ( timeout ) {
598
+ if ( timeout != null && ! ( Number . isInteger ( timeout ) && timeout >= 0 ) ) {
599
+ throw new TypeError ( '"timeout" must be an unsigned integer' ) ;
600
+ }
601
+ }
602
+
603
+
604
+ function validateMaxBuffer ( maxBuffer ) {
605
+ if ( maxBuffer != null && ! ( typeof maxBuffer === 'number' && maxBuffer >= 0 ) ) {
606
+ throw new TypeError ( '"maxBuffer" must be a positive number' ) ;
607
+ }
608
+ }
609
+
610
+
611
+ function validateKillSignal ( killSignal ) {
612
+ if ( typeof killSignal === 'string' || typeof killSignal === 'number' ) {
613
+ killSignal = lookupSignal ( killSignal ) ;
614
+
615
+ if ( killSignal === 0 )
616
+ throw new RangeError ( '"killSignal" cannot be 0' ) ;
617
+ } else if ( killSignal != null ) {
618
+ throw new TypeError ( '"killSignal" must be a string or number' ) ;
619
+ }
620
+
621
+ return killSignal ;
622
+ }
0 commit comments