Bug 1299592 - Handle dead windows in ContentSearch.jsm. r=felipe
authorEric Rahm <erahm@mozilla.com>
Thu, 01 Sep 2016 13:32:36 -0700
changeset 312354 6435e739a7ff8a1d9e9a3f6efccc34d4eb620f6d
parent 312353 2948b2f6ffffe9c5a22db1deb85120781bcc3d8d
child 312355 146e402be57e5c6fb052e0c1e2e7f781a4b4345e
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1299592
milestone51.0a1
Bug 1299592 - Handle dead windows in ContentSearch.jsm. r=felipe In addition to having a null messageManager it's also possible the target is already a dead wrapper if the browser has been closed.
browser/modules/ContentSearch.jsm
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -391,17 +391,19 @@ this.ContentSearch = {
     }
   },
 
   _onMessage: Task.async(function* (msg) {
     let methodName = "_onMessage" + msg.data.type;
     if (methodName in this) {
       yield this._initService();
       yield this[methodName](msg, msg.data.data);
-      msg.target.removeEventListener("SwapDocShells", msg, true);
+      if (!Cu.isDeadWrapper(msg.target)) {
+        msg.target.removeEventListener("SwapDocShells", msg, true);
+      }
     }
   }),
 
   _onMessageGetState: function (msg, data) {
     return this.currentStateObj().then(state => {
       this._reply(msg, "State", state);
     });
   },
@@ -484,17 +486,17 @@ this.ContentSearch = {
       this._suggestionMap.set(browser, data);
     }
     return data;
   },
 
   _reply: function (msg, type, data) {
     // We reply asyncly to messages, and by the time we reply the browser we're
     // responding to may have been destroyed.  messageManager is null then.
-    if (msg.target.messageManager) {
+    if (!Cu.isDeadWrapper(msg.target) && msg.target.messageManager) {
       msg.target.messageManager.sendAsyncMessage(...this._msgArgs(type, data));
     }
   },
 
   _broadcast: function (type, data) {
     Cc["@mozilla.org/globalmessagemanager;1"].
       getService(Ci.nsIMessageListenerManager).
       broadcastAsyncMessage(...this._msgArgs(type, data));