@@ -230,12 +230,16 @@ util.inherits(ChildProcess, EventEmitter);
230230
231231
232232function 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 ] ;
235239 if ( ! stream || ! stream . readable || stream . _readableState . readableListening )
236- return ;
240+ continue ;
237241 stream . resume ( ) ;
238- } ) ;
242+ }
239243}
240244
241245
@@ -268,6 +272,7 @@ ChildProcess.prototype.spawn = function(options) {
268272 const self = this ;
269273 var ipc ;
270274 var ipcFd ;
275+ var i ;
271276 // If no `stdio` option was given - use default
272277 var stdio = options . stdio || 'pipe' ;
273278
@@ -302,11 +307,12 @@ ChildProcess.prototype.spawn = function(options) {
302307 if ( err !== uv . UV_ENOENT ) return err ;
303308 } else if ( err ) {
304309 // 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 ( ) ;
308314 }
309- } ) ;
315+ }
310316
311317 this . _handle . close ( ) ;
312318 this . _handle = null ;
@@ -315,27 +321,29 @@ ChildProcess.prototype.spawn = function(options) {
315321
316322 this . pid = this . _handle . pid ;
317323
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 ;
320327
321- if ( stdio . ipc ) {
328+ if ( stream . ipc ) {
322329 self . _closesNeeded ++ ;
323- return ;
330+ continue ;
324331 }
325332
326- if ( stdio . handle ) {
333+ if ( stream . handle ) {
327334 // when i === 0 - we're dealing with stdin
328335 // (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 ) ;
330338
331339 if ( i > 0 && self . pid !== 0 ) {
332340 self . _closesNeeded ++ ;
333- stdio . socket . on ( 'close' , function ( ) {
341+ stream . socket . on ( 'close' , function ( ) {
334342 maybeClose ( self ) ;
335343 } ) ;
336344 }
337345 }
338- } ) ;
346+ }
339347
340348 this . stdin = stdio . length >= 1 && stdio [ 0 ] . socket !== undefined ?
341349 stdio [ 0 ] . socket : null ;
@@ -797,11 +805,11 @@ function _validateStdio(stdio, sync) {
797805 }
798806
799807 // Defaults
800- if ( stdio === null || stdio === undefined ) {
808+ if ( stdio == null ) {
801809 stdio = i < 3 ? 'pipe' : 'ignore' ;
802810 }
803811
804- if ( stdio === null || stdio === 'ignore' ) {
812+ if ( stdio === 'ignore' ) {
805813 acc . push ( { type : 'ignore' } ) ;
806814 } else if ( stdio === 'pipe' || typeof stdio === 'number' && stdio < 0 ) {
807815 var a = {
@@ -888,7 +896,7 @@ function getSocketList(type, slave, key) {
888896function maybeClose ( subprocess ) {
889897 subprocess . _closesGot ++ ;
890898
891- if ( subprocess . _closesGot == subprocess . _closesNeeded ) {
899+ if ( subprocess . _closesGot === subprocess . _closesNeeded ) {
892900 subprocess . emit ( 'close' , subprocess . exitCode , subprocess . signalCode ) ;
893901 }
894902}
0 commit comments