11'use strict' ;
22
33const {
4- Map,
4+ ArrayPrototypePush,
5+ ArrayPrototypeSlice,
6+ ArrayPrototypeSome,
57 ObjectKeys,
68 ObjectValues,
9+ RegExpPrototypeTest,
10+ SafeMap,
11+ StringPrototypeStartsWith,
712} = primordials ;
813
914const assert = require ( 'internal/assert' ) ;
@@ -23,7 +28,7 @@ const{validatePort } = require('internal/validators');
2328
2429module . exports = cluster ;
2530
26- const handles = new Map ( ) ;
31+ const handles = new SafeMap ( ) ;
2732cluster . isWorker = false ;
2833cluster . isMaster = true ;
2934cluster . Worker = Worker ;
@@ -53,7 +58,7 @@ cluster.schedulingPolicy = schedulingPolicy;
5358
5459cluster . setupMaster = function ( options ) {
5560const settings = {
56- args : process . argv . slice ( 2 ) ,
61+ args : ArrayPrototypeSlice ( process . argv , 2 ) ,
5762exec : process . argv [ 1 ] ,
5863execArgv : process . execArgv ,
5964silent : false ,
@@ -65,8 +70,10 @@ cluster.setupMaster = function(options){
6570// Without --logfile=v8-%p.log, everything ends up in a single, unusable
6671// file. (Unusable because what V8 logs are memory addresses and each
6772// process has its own memory mappings.)
68- if ( settings . execArgv . some ( ( s ) => s . startsWith ( '--prof' ) ) &&
69- ! settings . execArgv . some ( ( s ) => s . startsWith ( '--logfile=' ) ) ) {
73+ if ( ArrayPrototypeSome ( settings . execArgv ,
74+ ( s ) => StringPrototypeStartsWith ( s , '--prof' ) ) &&
75+ ! ArrayPrototypeSome ( settings . execArgv ,
76+ ( s ) => StringPrototypeStartsWith ( s , '--logfile=' ) ) ) {
7077settings . execArgv = [ ...settings . execArgv , '--logfile=v8-%p.log' ] ;
7178}
7279
@@ -109,8 +116,9 @@ function createWorkerProcess(id, env){
109116const nodeOptions = process . env . NODE_OPTIONS ?
110117process . env . NODE_OPTIONS : '' ;
111118
112- if ( execArgv . some ( ( arg ) => arg . match ( debugArgRegex ) ) ||
113- nodeOptions . match ( debugArgRegex ) ) {
119+ if ( ArrayPrototypeSome ( execArgv ,
120+ ( arg ) => RegExpPrototypeTest ( debugArgRegex , arg ) ) ||
121+ RegExpPrototypeTest ( debugArgRegex , nodeOptions ) ) {
114122let inspectPort ;
115123if ( 'inspectPort' in cluster . settings ) {
116124if ( typeof cluster . settings . inspectPort === 'function' )
@@ -126,7 +134,7 @@ function createWorkerProcess(id, env){
126134debugPortOffset ++ ;
127135}
128136
129- execArgv . push ( `--inspect-port=${ inspectPort } ` ) ;
137+ ArrayPrototypePush ( execArgv , `--inspect-port=${ inspectPort } ` ) ;
130138}
131139
132140return fork ( cluster . settings . exec , cluster . settings . args , {
0 commit comments