1+ var path = require ( 'path' ) ;
2+
13var binary = require ( 'node-pre-gyp' ) ;
2- var path = require ( 'path' )
3- var bindingPath = binary . find ( path . resolve ( path . join ( __dirname , '../package.json' ) ) ) ;
44
5- var supportedSignals = [
6- 'SIGBREAK' ,
7- 'SIGINT'
8- ] ;
5+ var bindingPath = binary . find ( path . resolve ( path . join ( __dirname , '../package.json' ) ) ) ;
96
10- var supportedSignalsAsNumber = {
11- 'SIGBREAK' : 1 ,
12- 'SIGINT' : 2
13- }
7+ var Options = require ( './options' ) ;
8+ var Signals = require ( './signals' ) ;
149
1510function WindowsKillClass ( options ) {
1611 this . _native = require ( bindingPath ) ;
1712 this . _nodeKill = process . kill ;
1813
19- this . _shouldReplaceNodesKill = true ;
20- if ( options && options . hasOwnProperty ( 'replaceNodeKill' ) && ( options . replaceNodeKill === false || options . replaceNodeKill === true ) ) {
21- this . _shouldReplaceNodesKill = options . replaceNodeKill ;
22- }
23-
24- this . _shouldWarmUp = false ;
25- if ( options && options . hasOwnProperty ( 'warmUp' ) && ( options . warmUp === false || options . warmUp === true ) ) {
26- this . _shouldWarmUp = options . warmUp ;
27- }
14+ this . _options = new Options ( options ) ;
15+ this . _signals = new Signals ( ) ;
2816
2917 this . _applyOptions ( ) ;
3018} ;
3119
3220WindowsKillClass . prototype . _applyOptions = function ( ) {
33- if ( this . _shouldReplaceNodesKill ) {
21+ if ( this . _options . get ( 'replaceNodeKill' ) === true ) {
3422 this . _replaceNodeKill ( ) ;
3523 }
3624
37- if ( this . _shouldWarmUp ) {
25+ if ( this . _options . get ( 'warmUp' ) === true ) {
3826 this . _native . warmUp ( ) ;
3927 }
4028}
@@ -47,12 +35,13 @@ WindowsKillClass.prototype._replaceNodeKill = function () {
4735}
4836
4937WindowsKillClass . prototype . kill = function ( pid , signal ) {
50- if ( supportedSignals . indexOf ( signal ) >= 0 ) {
38+ if ( this . _signals . isSupported ( signal ) ) {
5139 if ( pid != ( pid | 0 ) ) {
5240 throw new TypeError ( 'invalid pid.' ) ;
5341 }
5442
55- error = this . _native . send ( pid , supportedSignalsAsNumber [ signal ] ) ;
43+ error = this . _native . send ( pid , this . _signals . idToNumber ( signal ) ) ;
44+
5645 if ( error ) {
5746 throw new Error ( 'windows-kill ' + error ) ;
5847 }
0 commit comments