Bug 1075558 - Fix Notifications.unregisterHandler. r=mcomella
authorRichard Newman <rnewman@mozilla.com>
Tue, 23 Dec 2014 18:02:20 -0800
changeset 221196 c0b11eac936107a52b971718ed310126e79417be
parent 221195 697eb6db7d96dc21e817cd27a7e46ed4ab00f9bb
child 221197 fd2a21b856ee60a9cc73687771bea9222ac5d642
push id28013
push userphilringnalda@gmail.com
push dateWed, 24 Dec 2014 23:31:28 +0000
treeherdermozilla-central@38471b0310c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1075558
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1075558 - Fix Notifications.unregisterHandler. r=mcomella
mobile/android/modules/Notifications.jsm
--- a/mobile/android/modules/Notifications.jsm
+++ b/mobile/android/modules/Notifications.jsm
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-"use strict"
+
+"use strict";
 
-let Cc = Components.classes;
-let Ci = Components.interfaces;
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
-Components.utils.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
 
 this.EXPORTED_SYMBOLS = ["Notifications"];
 
 function log(msg) {
   // Services.console.logStringMessage(msg);
 }
 
 let _notificationsMap = {};
@@ -164,19 +164,23 @@ let Notifications = {
   registerHandler: function(key, handler) {
     if (!_handlersMap[key]) {
       _handlersMap[key] = [];
     }
     _handlersMap[key].push(handler);
   },
 
   unregisterHandler: function(key, handler) {
-    let i = _handlersMap[key].indexOf(handler);
+    let h = _handlersMap[key];
+    if (!h) {
+      return;
+    }
+    let i = h.indexOf(handler);
     if (i > -1) {
-      _handlersMap.splice(i, 1);
+      h.splice(i, 1);
     }
   },
 
   create: function notif_notify(aOptions) {
     let id = this.idService.generateUUID().toString();
 
     let notification = new Notification(id, aOptions);
     _notificationsMap[id] = notification;
@@ -253,11 +257,11 @@ let Notifications = {
 
   QueryInterface: function (aIID) {
     if (!aIID.equals(Ci.nsISupports) &&
         !aIID.equals(Ci.nsIObserver) &&
         !aIID.equals(Ci.nsISupportsWeakReference))
       throw Components.results.NS_ERROR_NO_INTERFACE;
     return this;
   }
-}
+};
 
 Services.obs.addObserver(Notifications, "Notification:Event", false);