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