@@ -230,12 +230,16 @@ util.inherits(ChildProcess, EventEmitter);
230
230
231
231
232
232
function flushStdio ( subprocess ) {
233
- if ( subprocess . stdio == null ) return ;
234
- subprocess . stdio . forEach ( function ( stream , fd , stdio ) {
233
+ const stdio = subprocess . stdio ;
234
+
235
+ if ( stdio == null ) return ;
236
+
237
+ for ( var i = 0 ; i < stdio . length ; i ++ ) {
238
+ const stream = stdio [ i ] ;
235
239
if ( ! stream || ! stream . readable || stream . _readableState . readableListening )
236
- return ;
240
+ continue ;
237
241
stream . resume ( ) ;
238
- } ) ;
242
+ }
239
243
}
240
244
241
245
@@ -268,6 +272,7 @@ ChildProcess.prototype.spawn = function(options) {
268
272
const self = this ;
269
273
var ipc ;
270
274
var ipcFd ;
275
+ var i ;
271
276
// If no `stdio` option was given - use default
272
277
var stdio = options . stdio || 'pipe' ;
273
278
@@ -302,11 +307,12 @@ ChildProcess.prototype.spawn = function(options) {
302
307
if ( err !== uv . UV_ENOENT ) return err ;
303
308
} else if ( err ) {
304
309
// Close all opened fds on error
305
- stdio . forEach ( function ( stdio ) {
306
- if ( stdio . type === 'pipe' ) {
307
- stdio . handle . close ( ) ;
310
+ for ( i = 0 ; i < stdio . length ; i ++ ) {
311
+ const stream = stdio [ i ] ;
312
+ if ( stream . type === 'pipe' ) {
313
+ stream . handle . close ( ) ;
308
314
}
309
- } ) ;
315
+ }
310
316
311
317
this . _handle . close ( ) ;
312
318
this . _handle = null ;
@@ -315,27 +321,29 @@ ChildProcess.prototype.spawn = function(options) {
315
321
316
322
this . pid = this . _handle . pid ;
317
323
318
- stdio . forEach ( function ( stdio , i ) {
319
- if ( stdio . type === 'ignore' ) return ;
324
+ for ( i = 0 ; i < stdio . length ; i ++ ) {
325
+ const stream = stdio [ i ] ;
326
+ if ( stream . type === 'ignore' ) continue ;
320
327
321
- if ( stdio . ipc ) {
328
+ if ( stream . ipc ) {
322
329
self . _closesNeeded ++ ;
323
- return ;
330
+ continue ;
324
331
}
325
332
326
- if ( stdio . handle ) {
333
+ if ( stream . handle ) {
327
334
// when i === 0 - we're dealing with stdin
328
335
// (which is the only one writable pipe)
329
- stdio . socket = createSocket ( self . pid !== 0 ? stdio . handle : null , i > 0 ) ;
336
+ stream . socket = createSocket ( self . pid !== 0 ?
337
+ stream . handle : null , i > 0 ) ;
330
338
331
339
if ( i > 0 && self . pid !== 0 ) {
332
340
self . _closesNeeded ++ ;
333
- stdio . socket . on ( 'close' , function ( ) {
341
+ stream . socket . on ( 'close' , function ( ) {
334
342
maybeClose ( self ) ;
335
343
} ) ;
336
344
}
337
345
}
338
- } ) ;
346
+ }
339
347
340
348
this . stdin = stdio . length >= 1 && stdio [ 0 ] . socket !== undefined ?
341
349
stdio [ 0 ] . socket : null ;
@@ -797,11 +805,11 @@ function _validateStdio(stdio, sync) {
797
805
}
798
806
799
807
// Defaults
800
- if ( stdio === null || stdio === undefined ) {
808
+ if ( stdio == null ) {
801
809
stdio = i < 3 ? 'pipe' : 'ignore' ;
802
810
}
803
811
804
- if ( stdio === null || stdio === 'ignore' ) {
812
+ if ( stdio === 'ignore' ) {
805
813
acc . push ( { type : 'ignore' } ) ;
806
814
} else if ( stdio === 'pipe' || typeof stdio === 'number' && stdio < 0 ) {
807
815
var a = {
@@ -887,7 +895,7 @@ function getSocketList(type, slave, key) {
887
895
function maybeClose ( subprocess ) {
888
896
subprocess . _closesGot ++ ;
889
897
890
- if ( subprocess . _closesGot == subprocess . _closesNeeded ) {
898
+ if ( subprocess . _closesGot === subprocess . _closesNeeded ) {
891
899
subprocess . emit ( 'close' , subprocess . exitCode , subprocess . signalCode ) ;
892
900
}
893
901
}
0 commit comments