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