@@ -178,24 +178,23 @@ function setupKillAndExit() {
178
178
179
179
180
180
function setupSignalHandlers ( ) {
181
- // Load events module in order to access prototype elements on process like
182
- // process.addListener.
183
- const signalWraps = { } ;
181
+ const signalWraps = Object . create ( null ) ;
182
+ let Signal ;
184
183
185
184
function isSignal ( event ) {
186
185
return typeof event === 'string' && constants [ event ] !== undefined ;
187
186
}
188
187
189
188
// Detect presence of a listener for the special signal types
190
- process . on ( 'newListener' , function ( type , listener ) {
191
- if ( isSignal ( type ) &&
192
- ! signalWraps . hasOwnProperty ( type ) ) {
193
- const Signal = process . binding ( 'signal_wrap' ) . Signal ;
189
+ process . on ( 'newListener' , function ( type ) {
190
+ if ( isSignal ( type ) && signalWraps [ type ] === undefined ) {
191
+ if ( Signal === undefined )
192
+ Signal = process . binding ( 'signal_wrap' ) . Signal ;
194
193
const wrap = new Signal ( ) ;
195
194
196
195
wrap . unref ( ) ;
197
196
198
- wrap . onsignal = function ( ) { process . emit ( type , type ) ; } ;
197
+ wrap . onsignal = process . emit . bind ( process , type , type ) ;
199
198
200
199
const signum = constants [ type ] ;
201
200
const err = wrap . start ( signum ) ;
@@ -208,8 +207,8 @@ function setupSignalHandlers() {
208
207
}
209
208
} ) ;
210
209
211
- process . on ( 'removeListener' , function ( type , listener ) {
212
- if ( signalWraps . hasOwnProperty ( type ) && this . listenerCount ( type ) === 0 ) {
210
+ process . on ( 'removeListener' , function ( type ) {
211
+ if ( signalWraps [ type ] !== undefined && this . listenerCount ( type ) === 0 ) {
213
212
signalWraps [ type ] . close ( ) ;
214
213
delete signalWraps [ type ] ;
215
214
}
0 commit comments