Bug 1265716 - Don't try to emit notification events if the extension has been unloaded, r?aswan
MozReview-Commit-ID: GBdf7bzEFpa
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -47,24 +47,31 @@ Notification.prototype = {
svc.closeAlert(this.id);
} catch (e) {
// This will fail if the OS doesn't support this function.
}
notificationsMap.get(this.extension).delete(this.id);
},
observe(subject, topic, data) {
+ let notifications = notificationsMap.get(this.extension);
+
+ // Don't try to emit events if the extension has been unloaded
+ if (!notifications) {
+ return;
+ }
+
if (topic === "alertclickcallback") {
- notificationsMap.get(this.extension).emit("clicked", data);
+ notifications.emit("clicked", data);
}
if (topic === "alertfinished") {
- notificationsMap.get(this.extension).emit("closed", data);
+ notifications.emit("closed", data);
}
- notificationsMap.get(this.extension).delete(this.id);
+ notifications.delete(this.id);
},
};
/* eslint-disable mozilla/balanced-listeners */
extensions.on("startup", (type, extension) => {
let map = new Map();
EventEmitter.decorate(map);
notificationsMap.set(extension, map);