From 75b2c9c5de5d81d9358a2c1a4508552dbd7f831b Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 14 Jan 2016 15:33:03 -0800 Subject: [PATCH] Fix crash when removing a listener // FREEBIE --- js/libtextsecure.js | 10 ++++++---- libtextsecure/event_target.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 8d0ce463..32087a88 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -36242,10 +36242,12 @@ window.textsecure.utils = function() { this.listeners = {}; } var listeners = this.listeners[eventName]; - for (var i=0; i < listeners.length; ++ i) { - if (listeners[i] === callback) { - listeners.splice(i, 1); - return; + if (typeof listeners === 'object') { + for (var i=0; i < listeners.length; ++ i) { + if (listeners[i] === callback) { + listeners.splice(i, 1); + return; + } } } this.listeners[eventName] = listeners; diff --git a/libtextsecure/event_target.js b/libtextsecure/event_target.js index e3833d63..7b8cc347 100644 --- a/libtextsecure/event_target.js +++ b/libtextsecure/event_target.js @@ -59,10 +59,12 @@ this.listeners = {}; } var listeners = this.listeners[eventName]; - for (var i=0; i < listeners.length; ++ i) { - if (listeners[i] === callback) { - listeners.splice(i, 1); - return; + if (typeof listeners === 'object') { + for (var i=0; i < listeners.length; ++ i) { + if (listeners[i] === callback) { + listeners.splice(i, 1); + return; + } } } this.listeners[eventName] = listeners;