@@ -601,19 +601,40 @@ class EventTarget {
601601 if ( arguments . length < 2 )
602602 throw new ERR_MISSING_ARGS ( 'type' , 'listener' ) ;
603603
604- // We validateOptions before the validateListener check because the spec
605- // requires us to hit getters.
606- const {
607- once,
608- capture,
609- passive,
610- signal,
611- isNodeStyleListener,
612- weak,
613- resistStopPropagation,
614- } = validateEventListenerOptions ( options ) ;
615-
616- validateAbortSignal ( signal , 'options.signal' ) ;
604+ let once = false ;
605+ let capture = false ;
606+ let passive = false ;
607+ let isNodeStyleListener = false ;
608+ let weak = false ;
609+ let resistStopPropagation = false ;
610+
611+ if ( options !== kEmptyObject ) {
612+ // We validateOptions before the validateListener check because the spec
613+ // requires us to hit getters.
614+ options = validateEventListenerOptions ( options ) ;
615+
616+ once = options . once ;
617+ capture = options . capture ;
618+ passive = options . passive ;
619+ isNodeStyleListener = options . isNodeStyleListener ;
620+ weak = options . weak ;
621+ resistStopPropagation = options . resistStopPropagation ;
622+
623+ const signal = options . signal ;
624+
625+ validateAbortSignal ( signal , 'options.signal' ) ;
626+
627+ if ( signal ) {
628+ if ( signal . aborted ) {
629+ return ;
630+ }
631+ // TODO(benjamingr) make this weak somehow? ideally the signal would
632+ // not prevent the event target from GC.
633+ signal . addEventListener ( 'abort' , ( ) => {
634+ this . removeEventListener ( type , listener , options ) ;
635+ } , { __proto__ : null , once : true , [ kWeakHandler ] : this , [ kResistStopPropagation ] : true } ) ;
636+ }
637+ }
617638
618639 if ( ! validateEventListener ( listener ) ) {
619640 // The DOM silently allows passing undefined as a second argument
@@ -627,18 +648,8 @@ class EventTarget {
627648 process . emitWarning ( w ) ;
628649 return ;
629650 }
630- type = webidl . converters . DOMString ( type ) ;
631651
632- if ( signal ) {
633- if ( signal . aborted ) {
634- return ;
635- }
636- // TODO(benjamingr) make this weak somehow? ideally the signal would
637- // not prevent the event target from GC.
638- signal . addEventListener ( 'abort' , ( ) => {
639- this . removeEventListener ( type , listener , options ) ;
640- } , { __proto__ : null , once : true , [ kWeakHandler ] : this , [ kResistStopPropagation ] : true } ) ;
641- }
652+ type = webidl . converters . DOMString ( type ) ;
642653
643654 let root = this [ kEvents ] . get ( type ) ;
644655
0 commit comments