@@ -7,18 +7,17 @@ const {
77 Object,
88 Set,
99 Symbol,
10- NumberIsNaN,
1110 SymbolToStringTag,
1211} = primordials ;
1312
1413const {
1514 codes : {
1615 ERR_INVALID_ARG_TYPE ,
1716 ERR_EVENT_RECURSION ,
18- ERR_OUT_OF_RANGE ,
1917 ERR_MISSING_ARGS
2018 }
2119} = require ( 'internal/errors' ) ;
20+ const { validateInteger, validateObject } = require ( 'internal/validators' ) ;
2221
2322const { customInspectSymbol } = require ( 'internal/util' ) ;
2423const { inspect } = require ( 'util' ) ;
@@ -54,11 +53,10 @@ class Event {
5453
5554
5655 constructor ( type , options ) {
57- if ( arguments . length === 0 ) {
56+ if ( arguments . length === 0 )
5857 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' ) ;
6260 const { cancelable, bubbles, composed } = { ...options } ;
6361 this . #cancelable = ! ! cancelable ;
6462 this . #bubbles = ! ! bubbles ;
@@ -350,9 +348,7 @@ class NodeEventTarget extends EventTarget {
350348 }
351349
352350 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 ) ;
356352 this . #maxListeners = n ;
357353 return this ;
358354 }
@@ -430,11 +426,9 @@ function validateListener(listener) {
430426}
431427
432428function 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' ) ;
438432 const {
439433 once = false ,
440434 capture = false ,
0 commit comments