@@ -178,24 +178,23 @@ function setupKillAndExit() {
178178
179179
180180function 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 ;
184183
185184 function isSignal ( event ) {
186185 return typeof event === 'string' && constants [ event ] !== undefined ;
187186 }
188187
189188 // 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 ;
194193 const wrap = new Signal ( ) ;
195194
196195 wrap . unref ( ) ;
197196
198- wrap . onsignal = function ( ) { process . emit ( type , type ) ; } ;
197+ wrap . onsignal = process . emit . bind ( process , type , type ) ;
199198
200199 const signum = constants [ type ] ;
201200 const err = wrap . start ( signum ) ;
@@ -208,8 +207,8 @@ function setupSignalHandlers() {
208207 }
209208 } ) ;
210209
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 ) {
213212 signalWraps [ type ] . close ( ) ;
214213 delete signalWraps [ type ] ;
215214 }
0 commit comments