@@ -87,7 +87,6 @@ const kChannelHandle = Symbol('kChannelHandle');
87
87
const kIsUsedAsStdio = Symbol ( 'kIsUsedAsStdio' ) ;
88
88
const kPendingMessages = Symbol ( 'kPendingMessages' ) ;
89
89
const kKillSignal = Symbol ( 'kKillSignal' ) ;
90
- const kWasClosed = Symbol ( 'kWasClosed' ) ;
91
90
92
91
// This object contain function to convert TCP objects to native handle objects
93
92
// and back again.
@@ -266,7 +265,6 @@ function ChildProcess(killSignal) {
266
265
this . exitCode = null ;
267
266
this . killed = false ;
268
267
this . spawnfile = null ;
269
- this [ kWasClosed ] = false ;
270
268
this [ kKillSignal ] = killSignal ;
271
269
272
270
this . _handle = new Process ( ) ;
@@ -318,6 +316,15 @@ function ChildProcess(killSignal) {
318
316
ObjectSetPrototypeOf ( ChildProcess . prototype , EventEmitter . prototype ) ;
319
317
ObjectSetPrototypeOf ( ChildProcess , EventEmitter ) ;
320
318
319
+ ObjectDefineProperty ( ChildProcess . prototype , 'closed' , {
320
+ __proto__ : null ,
321
+ get ( ) {
322
+ return this . _closesGot === this . _closesNeeded ;
323
+ } ,
324
+ configurable : true ,
325
+ enumerable : false ,
326
+ } ) ;
327
+
321
328
322
329
function flushStdio ( subprocess ) {
323
330
const stdio = subprocess . stdio ;
@@ -523,7 +530,7 @@ ChildProcess.prototype.kill = function(sig) {
523
530
} ;
524
531
525
532
ChildProcess . prototype [ SymbolAsyncDispose ] = async function ( ) {
526
- if ( ! this [ kWasClosed ] ) {
533
+ if ( ! this . closed ) {
527
534
const promise = EventEmitter . once ( this , 'close' ) ;
528
535
const ret = this . kill ( this [ kKillSignal ] ) ;
529
536
assert ( ret , 'unexpected kill failure' ) ;
@@ -1109,9 +1116,7 @@ function getSocketList(type, worker, key) {
1109
1116
1110
1117
function maybeClose ( subprocess ) {
1111
1118
subprocess . _closesGot ++ ;
1112
-
1113
- if ( subprocess . _closesGot === subprocess . _closesNeeded ) {
1114
- subprocess [ kWasClosed ] = true ;
1119
+ if ( subprocess . closed ) {
1115
1120
subprocess . emit ( 'close' , subprocess . exitCode , subprocess . signalCode ) ;
1116
1121
}
1117
1122
}
0 commit comments