Permalink
Browse files

fix: Events#off threw if Object.prototype had extra enumerable proper…

…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 79639138ba41eda75f0f6a07071f9a9e6a551f80
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/js/utils/events.js
View
@@ -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;
}

0 comments on commit 7963913

Please sign in to comment.