Bug 1268898 - Fix leak in sdk/event/dom. r=gabor a=sylvestre
authorThe 8472 <bugzilla.mozilla.org@infinite-source.de>
Sun, 10 Jul 2016 12:19:00 +0200
changeset 342041 02b002977b46df0249540aed40854f0905340bd4
parent 342040 3ecc86179a9af4ddb53ab1fe478511a9832e9801
child 342042 1d0e6b236087115fa817476cccfc69ea07d32f59
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor, sylvestre
bugs1268898
milestone49.0a2
Bug 1268898 - Fix leak in sdk/event/dom. r=gabor a=sylvestre
addon-sdk/source/lib/sdk/event/dom.js
--- a/addon-sdk/source/lib/sdk/event/dom.js
+++ b/addon-sdk/source/lib/sdk/event/dom.js
@@ -7,20 +7,21 @@
 module.metadata = {
   "stability": "unstable"
 };
 
 const { Ci } = require("chrome");
 
 var { emit } = require("./core");
 var { when: unload } = require("../system/unload");
-var listeners = new Map();
+var listeners = new WeakMap();
 
 const { Cu } = require("chrome");
 const { ShimWaiver } = Cu.import("resource://gre/modules/ShimWaiver.jsm");
+const { ThreadSafeChromeUtils } = Cu.import("resource://gre/modules/Services.jsm", {});
 
 var getWindowFrom = x =>
                     x instanceof Ci.nsIDOMWindow ? x :
                     x instanceof Ci.nsIDOMDocument ? x.defaultView :
                     x instanceof Ci.nsIDOMNode ? x.ownerDocument.defaultView :
                     null;
 
 function removeFromListeners() {
@@ -64,13 +65,14 @@ function open(target, type, options) {
 
   cleaners.push(() => ShimWaiver.getProperty(target, "removeEventListener")(type, listener, capture));
   ShimWaiver.getProperty(target, "addEventListener")(type, listener, capture);
 
   return output;
 }
 
 unload(() => {
-  for (let window of listeners.keys())
+  let keys = ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(listeners)
+  for (let window of keys)
     removeFromListeners.call(window);
 });
 
 exports.open = open;