@@ -7,18 +7,17 @@ const {
7
7
Object,
8
8
Set,
9
9
Symbol,
10
- NumberIsNaN,
11
10
SymbolToStringTag,
12
11
} = primordials ;
13
12
14
13
const {
15
14
codes : {
16
15
ERR_INVALID_ARG_TYPE ,
17
16
ERR_EVENT_RECURSION ,
18
- ERR_OUT_OF_RANGE ,
19
17
ERR_MISSING_ARGS
20
18
}
21
19
} = require ( 'internal/errors' ) ;
20
+ const { validateInteger, validateObject } = require ( 'internal/validators' ) ;
22
21
23
22
const { customInspectSymbol } = require ( 'internal/util' ) ;
24
23
const { inspect } = require ( 'util' ) ;
@@ -54,11 +53,10 @@ class Event {
54
53
55
54
56
55
constructor ( type , options ) {
57
- if ( arguments . length === 0 ) {
56
+ if ( arguments . length === 0 )
58
57
throw new ERR_MISSING_ARGS ( 'type' ) ;
59
- }
60
- if ( options != null && typeof options !== 'object' )
61
- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
58
+ if ( options != null )
59
+ validateObject ( options , 'options' ) ;
62
60
const { cancelable, bubbles, composed } = { ...options } ;
63
61
this . #cancelable = ! ! cancelable ;
64
62
this . #bubbles = ! ! bubbles ;
@@ -350,9 +348,7 @@ class NodeEventTarget extends EventTarget {
350
348
}
351
349
352
350
setMaxListeners ( n ) {
353
- if ( typeof n !== 'number' || n < 0 || NumberIsNaN ( n ) ) {
354
- throw new ERR_OUT_OF_RANGE ( 'n' , 'a non-negative number' , n ) ;
355
- }
351
+ validateInteger ( n , 'n' , 0 ) ;
356
352
this . #maxListeners = n ;
357
353
return this ;
358
354
}
@@ -430,11 +426,9 @@ function validateListener(listener) {
430
426
}
431
427
432
428
function validateEventListenerOptions ( options ) {
433
- if ( typeof options === 'boolean' ) {
434
- options = { capture : options } ;
435
- }
436
- if ( options == null || typeof options !== 'object' )
437
- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
429
+ if ( typeof options === 'boolean' )
430
+ return { capture : options } ;
431
+ validateObject ( options , 'options' ) ;
438
432
const {
439
433
once = false ,
440
434
capture = false ,
0 commit comments