Skip to content

Commit

Permalink
fix: Events#off threw if Object.prototype had extra enumerable proper…
Browse files Browse the repository at this point in the history
…ties, don't remove all events if off receives a falsey value (#4669)

If Object.prototype was modified to have extra properties, the `off` method crashed because `data.handlers` would've been removed before getting to the extra property.

Also, this fixes an issue where if a falsey value was passed to off, the events system would remove all the events, i.e. `player.off('')`. Instead, we make sure that only if it is called as `player.off()` will they be removed.
  • Loading branch information
mmodrow authored and gkatsev committed Oct 30, 2017
1 parent afea980 commit 7963913
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/js/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,11 @@ export function off(elem, type, fn) {
};

// Are we removing all bound events?
if (!type) {
if (type === undefined) {
for (const t in data.handlers) {
removeType(t);
if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) {
removeType(t);
}
}
return;
}
Expand Down

0 comments on commit 7963913

Please sign in to comment.