Bug 1029735 - ContentSearch sometimes leaks event listeners and their closures. r=ttaubert
authorDrew Willcoxon <adw@mozilla.com>
Tue, 24 Jun 2014 12:49:52 -0700
changeset 190647 7d9d619896bf378f4c7df8cce717ed70d7c87dee
parent 190646 92a4b7143c827133fc544ce6982caa5382f2b14c
child 190648 348cffe9034465fc7a107048cb50fd905afc38cb
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersttaubert
bugs1029735
milestone33.0a1
Bug 1029735 - ContentSearch sometimes leaks event listeners and their closures. r=ttaubert
browser/modules/ContentSearch.jsm
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -71,16 +71,17 @@ this.ContentSearch = {
     // Add a temporary event handler that exists only while the message is in
     // the event queue.  If the message's source docshell changes browsers in
     // the meantime, then we need to update msg.target.  event.detail will be
     // the docshell's new parent <xul:browser> element.
     msg.handleEvent = function (event) {
       this.target = event.detail;
     };
     msg.target.addEventListener("SwapDocShells", msg, true);
+    msg.originalTarget = msg.target;
 
     this._eventQueue.push({
       type: "Message",
       data: msg,
     });
     this._processEventQueue();
   },
 
@@ -110,17 +111,17 @@ 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);
+      msg.originalTarget.removeEventListener("SwapDocShells", msg, true);
     }
   }),
 
   _onMessageGetState: function (msg, data) {
     return this._currentStateObj().then(state => {
       this._reply(msg, "State", state);
     });
   },