Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 7acebca

Browse files
jribblebtford
authored andcommitted
fix: prevent calling addEventListener on non-functions
This was throwing exceptions in firefox for the following case: ```javascript elt.onclick = null; ```
1 parent 3485c1b commit 7acebca

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: test/zone.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ describe('Zone.patch', function () {
143143
expect(log).toEqual('b');
144144
});
145145

146+
it('should handle removing onclick', function () {
147+
var log = '';
148+
button.onclick = function () {
149+
log += 'a';
150+
};
151+
button.onclick = null;
152+
153+
button.click();
154+
expect(log).toEqual('');
155+
});
156+
146157
});
147158

148159
describe('hooks', function () {

Diff for: zone.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ Zone.patchProperty = function (obj, prop) {
106106
this.removeEventListener(eventName, this[_prop]);
107107
}
108108

109-
this[_prop] = fn;
110109

111-
this.addEventListener(eventName, fn, false);
110+
if (typeof fn === 'function') {
111+
this[_prop] = fn;
112+
this.addEventListener(eventName, fn, false);
113+
} else {
114+
this[_prop] = null;
115+
}
112116
};
113117

114118
desc.get = function () {

0 commit comments

Comments
 (0)