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

Commit

Permalink
fix: prevent calling addEventListener on non-functions
Browse files Browse the repository at this point in the history
This was throwing exceptions in firefox for the following case:
```javascript
elt.onclick = null;
```
  • Loading branch information
jribble authored and btford committed Mar 29, 2014
1 parent 3485c1b commit 7acebca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions test/zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ describe('Zone.patch', function () {
expect(log).toEqual('b');
});

it('should handle removing onclick', function () {
var log = '';
button.onclick = function () {
log += 'a';
};
button.onclick = null;

button.click();
expect(log).toEqual('');
});

});

describe('hooks', function () {
Expand Down
8 changes: 6 additions & 2 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ Zone.patchProperty = function (obj, prop) {
this.removeEventListener(eventName, this[_prop]);
}

this[_prop] = fn;

this.addEventListener(eventName, fn, false);
if (typeof fn === 'function') {
this[_prop] = fn;
this.addEventListener(eventName, fn, false);
} else {
this[_prop] = null;
}
};

desc.get = function () {
Expand Down

0 comments on commit 7acebca

Please sign in to comment.