@@ -447,19 +447,19 @@ function setupChannel(target, channel) {
447
447
// TODO(bnoordhuis) Check that nread > 0.
448
448
if ( pool ) {
449
449
// Linebreak is used as a message end sign
450
- var lines = decoder . write ( pool ) . split ( '\n' ) ;
451
- var chunks = lines . slice ( 0 , - 1 ) ;
450
+ var chunks = decoder . write ( pool ) . split ( '\n' ) ;
451
+ var numCompleteChunks = chunks . length - 1 ;
452
452
// Last line does not have trailing linebreak
453
- var incompleteChunk = lines [ lines . length - 1 ] ;
454
- if ( chunks . length === 0 ) {
453
+ var incompleteChunk = chunks [ numCompleteChunks ] ;
454
+ if ( numCompleteChunks === 0 ) {
455
455
jsonBuffer += incompleteChunk ;
456
456
this . buffering = jsonBuffer . length !== 0 ;
457
457
return ;
458
458
}
459
459
chunks [ 0 ] = jsonBuffer + chunks [ 0 ] ;
460
460
461
- chunks . forEach ( function ( json ) {
462
- var message = JSON . parse ( json ) ;
461
+ for ( var i = 0 ; i < numCompleteChunks ; i ++ ) {
462
+ var message = JSON . parse ( chunks [ i ] ) ;
463
463
464
464
// There will be at most one NODE_HANDLE message in every chunk we
465
465
// read because SCM_RIGHTS messages don't get coalesced. Make sure
@@ -468,7 +468,7 @@ function setupChannel(target, channel) {
468
468
handleMessage ( target , message , recvHandle ) ;
469
469
else
470
470
handleMessage ( target , message , undefined ) ;
471
- } ) ;
471
+ }
472
472
jsonBuffer = incompleteChunk ;
473
473
this . buffering = jsonBuffer . length !== 0 ;
474
474
0 commit comments