From 6d2f9399ed5fbf6a68152973cd2aaeeab71b792b Mon Sep 17 00:00:00 2001 From: deroke <45258253+deroke@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:01:17 +0200 Subject: [PATCH] fix: check _cbs existance --- player/js/utils/BaseEvent.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/player/js/utils/BaseEvent.js b/player/js/utils/BaseEvent.js index be894df46..a6327fbf9 100644 --- a/player/js/utils/BaseEvent.js +++ b/player/js/utils/BaseEvent.js @@ -1,6 +1,7 @@ function BaseEvent() {} BaseEvent.prototype = { triggerEvent: function (eventName, args) { + if (!this._cbs) return; if (this._cbs[eventName]) { var callbacks = this._cbs[eventName]; for (var i = 0; i < callbacks.length; i += 1) { @@ -9,16 +10,19 @@ BaseEvent.prototype = { } }, addEventListener: function (eventName, callback) { - if (!this._cbs[eventName]) { - this._cbs[eventName] = []; + if (this._cbs) { + if (!this._cbs[eventName]) { + this._cbs[eventName] = []; + } + this._cbs[eventName].push(callback); } - this._cbs[eventName].push(callback); return function () { this.removeEventListener(eventName, callback); }.bind(this); }, removeEventListener: function (eventName, callback) { + if (!this._cbs) return; if (!callback) { this._cbs[eventName] = null; } else if (this._cbs[eventName]) {