@@ -125,22 +125,23 @@ function preventAddEventListener(
125125 }
126126 return context . reflect ( ) ;
127127 } ;
128+ const protect = owner => {
129+ const { addEventListener } = owner ;
130+ Object . defineProperty ( owner , 'addEventListener' , {
131+ set ( ) { } ,
132+ get ( ) { return addEventListener ; }
133+ } ) ;
134+ } ;
128135 runAt ( ( ) => {
129136 proxyApplyFn ( 'EventTarget.prototype.addEventListener' , proxyFn ) ;
130- if ( extraArgs . protect ) {
131- const { addEventListener } = EventTarget . prototype ;
132- Object . defineProperty ( EventTarget . prototype , 'addEventListener' , {
133- set ( ) { } ,
134- get ( ) { return addEventListener ; }
135- } ) ;
137+ if ( extraArgs . protect ) { protect ( EventTarget . prototype ) ; }
138+ if ( Object . hasOwn ( document , 'addEventListener' ) ) {
139+ proxyApplyFn ( 'document.addEventListener' , proxyFn ) ;
140+ if ( extraArgs . protect ) { protect ( document ) ; }
136141 }
137- proxyApplyFn ( 'document.addEventListener' , proxyFn ) ;
138- if ( extraArgs . protect ) {
139- const { addEventListener } = document ;
140- Object . defineProperty ( document , 'addEventListener' , {
141- set ( ) { } ,
142- get ( ) { return addEventListener ; }
143- } ) ;
142+ if ( Object . hasOwn ( window , 'addEventListener' ) ) {
143+ proxyApplyFn ( 'window.addEventListener' , proxyFn ) ;
144+ if ( extraArgs . protect ) { protect ( window ) ; }
144145 }
145146 } , extraArgs . runAt ) ;
146147}
0 commit comments