Bug 1444338: Make sure weak progress listener is not collected too early. r=mconley
authorKris Maglione <maglione.k@gmail.com>
Fri, 09 Mar 2018 08:44:37 -0800
changeset 462388 0441c697499ad35b67384ae28971cd4b26dff12a
parent 462387 bfe063307abd3fe4444b701af6c2e26b4e7ed02d
child 462389 13163586e52bf7cacc5c6237837c13c64bdf5bd5
child 462413 3dc420775cf024cedc9bdcc43d020f7319f00a77
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1444338
milestone60.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 1444338: Make sure weak progress listener is not collected too early. r=mconley MozReview-Commit-ID: GAwko5pkcc8
browser/components/search/test/head.js
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -80,45 +80,51 @@ function promiseNewEngine(basename, opti
           }
         });
       }
     });
   });
 }
 
 let promiseStateChangeFrameScript = "data:," + encodeURIComponent(`(${
-  function processScript() {
+  () => {
     ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
     /* globals docShell, sendAsyncMessage */
 
+    const global = this;
+    const LISTENER = Symbol("listener");
     let listener = {
       QueryInterface: XPCOMUtils.generateQI(["nsISupportsWeakReference",
                                              "nsIWebProgressListener"]),
 
       onStateChange: function onStateChange(webProgress, req, flags, status) {
         // Only care about top-level document starts
         if (!webProgress.isTopLevel ||
             !(flags & Ci.nsIWebProgressListener.STATE_START)) {
           return;
         }
 
         req.QueryInterface(Ci.nsIChannel);
         let spec = req.originalURI.spec;
         if (spec == "about:blank")
           return;
 
+        delete global[LISTENER];
         docShell.removeProgressListener(listener);
 
         req.cancel(Cr.NS_ERROR_FAILURE);
 
         sendAsyncMessage("PromiseStateChange::StateChanged", spec);
       },
     };
 
+    // Make sure the weak reference stays alive.
+    global[LISTENER] = listener;
+
     docShell.QueryInterface(Ci.nsIWebProgress);
     docShell.addProgressListener(listener,
                                  Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
   }
 })()`);
 
 function promiseStateChangeURI() {
   const MSG = "PromiseStateChange::StateChanged";