1
1
'use strict' ;
2
2
3
3
const {
4
- Map,
4
+ ArrayPrototypeJoin,
5
+ FunctionPrototype,
5
6
ObjectAssign,
7
+ ReflectApply,
8
+ SafeMap,
6
9
} = primordials ;
7
10
8
11
const assert = require ( 'internal/assert' ) ;
@@ -12,9 +15,9 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
12
15
const Worker = require ( 'internal/cluster/worker' ) ;
13
16
const { internal, sendHelper } = require ( 'internal/cluster/utils' ) ;
14
17
const cluster = new EventEmitter ( ) ;
15
- const handles = new Map ( ) ;
16
- const indexes = new Map ( ) ;
17
- const noop = ( ) => { } ;
18
+ const handles = new SafeMap ( ) ;
19
+ const indexes = new SafeMap ( ) ;
20
+ const noop = FunctionPrototype ;
18
21
19
22
module . exports = cluster ;
20
23
@@ -49,7 +52,7 @@ cluster._setupWorker = function() {
49
52
if ( message . act === 'newconn' )
50
53
onconnection ( message , handle ) ;
51
54
else if ( message . act === 'disconnect' )
52
- _disconnect . call ( worker , true ) ;
55
+ ReflectApply ( _disconnect , worker , [ true ] ) ;
53
56
}
54
57
} ;
55
58
@@ -62,10 +65,13 @@ cluster._getServer = function(obj, options, cb) {
62
65
process . platform !== 'win32' )
63
66
address = path . resolve ( address ) ;
64
67
65
- const indexesKey = [ address ,
66
- options . port ,
67
- options . addressType ,
68
- options . fd ] . join ( ':' ) ;
68
+ const indexesKey = ArrayPrototypeJoin (
69
+ [
70
+ address ,
71
+ options . port ,
72
+ options . addressType ,
73
+ options . fd ,
74
+ ] , ':' ) ;
69
75
70
76
let index = indexes . get ( indexesKey ) ;
71
77
@@ -119,7 +125,7 @@ function shared(message, handle, indexesKey, cb) {
119
125
send ( { act : 'close' , key } ) ;
120
126
handles . delete ( key ) ;
121
127
indexes . delete ( indexesKey ) ;
122
- return close . apply ( handle , arguments ) ;
128
+ return ReflectApply ( close , handle , arguments ) ;
123
129
} ;
124
130
assert ( handles . has ( key ) === false ) ;
125
131
handles . set ( key , handle ) ;
@@ -228,9 +234,9 @@ function _disconnect(masterInitiated) {
228
234
229
235
// Extend generic Worker with methods specific to worker processes.
230
236
Worker . prototype . disconnect = function ( ) {
231
- if ( ! [ 'disconnecting' , 'destroying' ] . includes ( this . state ) ) {
237
+ if ( this . state !== 'disconnecting' && this . state !== 'destroying' ) {
232
238
this . state = 'disconnecting' ;
233
- _disconnect . call ( this ) ;
239
+ ReflectApply ( _disconnect , this , [ ] ) ;
234
240
}
235
241
236
242
return this ;
0 commit comments