@@ -23,6 +23,7 @@ const {
23
23
SetPrototypeValues,
24
24
StringPrototypeEndsWith,
25
25
StringPrototypeReplace,
26
+ StringPrototypeReplaceAll,
26
27
StringPrototypeSlice,
27
28
StringPrototypeStartsWith,
28
29
Symbol,
@@ -33,15 +34,14 @@ const {
33
34
const {
34
35
errnoException,
35
36
codes : {
36
- ERR_ASSERTION ,
37
- ERR_INVALID_ARG_TYPE ,
38
37
ERR_INVALID_ARG_VALUE ,
39
38
ERR_OUT_OF_RANGE ,
40
39
ERR_UNKNOWN_SIGNAL
41
40
}
42
41
} = require ( 'internal/errors' ) ;
43
42
const format = require ( 'internal/util/inspect' ) . format ;
44
43
const {
44
+ isInt32,
45
45
validateArray,
46
46
validateNumber,
47
47
validateObject,
@@ -120,9 +120,9 @@ function wrapProcessMethods(binding) {
120
120
function cpuUsage ( prevValue ) {
121
121
// If a previous value was passed in, ensure it has the correct shape.
122
122
if ( prevValue ) {
123
- if ( ! previousValueIsValid ( prevValue . user ) ) {
124
- validateObject ( prevValue , 'prevValue' ) ;
123
+ validateObject ( prevValue , 'prevValue' ) ;
125
124
125
+ if ( ! previousValueIsValid ( prevValue . user ) ) {
126
126
validateNumber ( prevValue . user , 'prevValue.user' ) ;
127
127
throw new ERR_INVALID_ARG_VALUE . RangeError ( 'prevValue.user' ,
128
128
prevValue . user ) ;
@@ -192,18 +192,15 @@ function wrapProcessMethods(binding) {
192
192
function kill ( pid , sig ) {
193
193
let err ;
194
194
195
- // eslint-disable-next-line eqeqeq
196
- if ( pid != ( pid | 0 ) ) {
197
- throw new ERR_INVALID_ARG_TYPE ( 'pid' , 'number' , pid ) ;
198
- }
195
+ validateNumber ( pid , 'pid' ) ;
199
196
200
197
// Preserve null signal
201
- if ( sig === ( sig | 0 ) ) {
198
+ if ( isInt32 ( sig ) ) {
202
199
// XXX(joyeecheung): we have to use process._kill here because
203
200
// it's monkey-patched by tests.
204
201
err = process . _kill ( pid , sig ) ;
205
202
} else {
206
- sig = sig || 'SIGTERM' ;
203
+ sig ||= 'SIGTERM' ;
207
204
if ( constants [ sig ] ) {
208
205
err = process . _kill ( pid , constants [ sig ] ) ;
209
206
} else {
@@ -251,7 +248,6 @@ function wrapProcessMethods(binding) {
251
248
} ;
252
249
}
253
250
254
- const replaceUnderscoresRegex = / _ / g;
255
251
const leadingDashesRegex = / ^ - - ? / ;
256
252
const trailingValuesRegex = / = .* $ / ;
257
253
@@ -333,7 +329,7 @@ function buildAllowedFlags() {
333
329
// on a dummy option set and see whether it rejects the argument or
334
330
// not.
335
331
if ( typeof key === 'string' ) {
336
- key = StringPrototypeReplace ( key , replaceUnderscoresRegex , '-' ) ;
332
+ key = StringPrototypeReplaceAll ( key , '_' , '-' ) ;
337
333
if ( RegExpPrototypeTest ( leadingDashesRegex , key ) ) {
338
334
key = StringPrototypeReplace ( key , trailingValuesRegex , '' ) ;
339
335
return ArrayPrototypeIncludes ( this [ kInternal ] . array , key ) ;
0 commit comments