This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ function patchEventTargetMethods(obj) {
96
96
// This is required for the addEventListener hook on the root zone.
97
97
obj [ keys . common . addEventListener ] = obj . addEventListener ;
98
98
obj . addEventListener = function ( eventName , handler , useCapturing ) {
99
+ if ( ! handler ) {
100
+ return ;
101
+ }
99
102
var eventType = eventName + ( useCapturing ? '$capturing' : '$bubbling' ) ;
100
103
var fn ;
101
104
//Ignore special listeners of IE11 & Edge dev tools, see https://github.com/angular/zone.js/issues/150
@@ -129,6 +132,9 @@ function patchEventTargetMethods(obj) {
129
132
// This is required for the removeEventListener hook on the root zone.
130
133
obj [ keys . common . removeEventListener ] = obj . removeEventListener ;
131
134
obj . removeEventListener = function ( eventName , handler , useCapturing ) {
135
+ if ( ! handler ) {
136
+ return ;
137
+ }
132
138
var eventType = eventName + ( useCapturing ? '$capturing' : '$bubbling' ) ;
133
139
if ( handler [ boundFnsKey ] && handler [ boundFnsKey ] [ eventType ] ) {
134
140
var _bound = handler [ boundFnsKey ] ;
Original file line number Diff line number Diff line change @@ -113,6 +113,20 @@ describe('element', function () {
113
113
expect ( eventListener . handleEvent ) . not . toHaveBeenCalled ( ) ;
114
114
} ) ;
115
115
116
+ it ( 'should have no effect while calling addEventListener without listener' , function ( ) {
117
+ expect ( function ( ) {
118
+ button . addEventListener ( 'click' , null ) ;
119
+ button . addEventListener ( 'click' , undefined ) ;
120
+ } ) . not . toThrowError ( ) ;
121
+ } ) ;
122
+
123
+ it ( 'should have no effect while calling removeEventListener without listener' , function ( ) {
124
+ expect ( function ( ) {
125
+ button . removeEventListener ( 'click' , null ) ;
126
+ button . removeEventListener ( 'click' , undefined ) ;
127
+ } ) . not . toThrowError ( ) ;
128
+ } ) ;
129
+
116
130
117
131
it ( 'should only add a listener once for a given set of arguments' , function ( ) {
118
132
var log = [ ] ;
You can’t perform that action at this time.
0 commit comments