Bug 928389 - Default to strong listeners added via DOMRequestHelper. r=fabrice, genelian, bkelly
authorFernando Jiménez <ferjmoreno@gmail.com>
Mon, 02 Dec 2013 21:39:04 +0100
changeset 174022 2f40cd447dc01e873012c0ec9bda9ea1c427695b
parent 174021 f8b57cbe128a54b3250d3aa37c2905cd0c0a2a4f
child 174023 f3174f0757c883fca4bf3307f277a69bba8731b1
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, genelian, bkelly
bugs928389
milestone28.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 928389 - Default to strong listeners added via DOMRequestHelper. r=fabrice, genelian, bkelly
dom/base/DOMRequestHelper.jsm
dom/base/test/test_domrequesthelper.xul
--- a/dom/base/DOMRequestHelper.jsm
+++ b/dom/base/DOMRequestHelper.jsm
@@ -35,43 +35,42 @@ this.DOMRequestIpcHelper = function DOMR
   // kind of listener that we added (strong or weak). It's an object of this
   // form:
   //  {
   //    "message1": true,
   //    "messagen": false
   //  }
   //
   // where each property is the name of the message and its value is a boolean
-  // that indicates if the listener is strong or not.
+  // that indicates if the listener is weak or not.
   this._listeners = null;
   this._requests = null;
   this._window = null;
 }
 
 DOMRequestIpcHelper.prototype = {
   /**
-   * An object which "inherits" from DOMRequestIpcHelper, declares its own
-   * queryInterface method and adds at least one weak listener to the Message
-   * Manager MUST implement Ci.nsISupportsWeakReference.
+   * An object which "inherits" from DOMRequestIpcHelper and declares its own
+   * queryInterface method MUST implement Ci.nsISupportsWeakReference.
    */
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
                                          Ci.nsIObserver]),
 
    /**
    *  'aMessages' is expected to be an array of either:
    *  - objects of this form:
    *    {
    *      name: "messageName",
-   *      strongRef: false
+   *      weakRef: false
    *    }
-   *    where 'name' is the message identifier and 'strongRef' a boolean
-   *    indicating if the listener should be a strong referred one or not.
+   *    where 'name' is the message identifier and 'weakRef' a boolean
+   *    indicating if the listener should be a weak referred one or not.
    *
    *  - or only strings containing the message name, in which case the listener
-   *    will be added as a weak reference by default.
+   *    will be added as a strong reference by default.
    */
   addMessageListeners: function(aMessages) {
     if (!aMessages) {
       return;
     }
 
     if (!this._listeners) {
       this._listeners = {};
@@ -81,26 +80,26 @@ DOMRequestIpcHelper.prototype = {
       aMessages = [aMessages];
     }
 
     aMessages.forEach((aMsg) => {
       let name = aMsg.name || aMsg;
       // If the listener is already set and it is of the same type we just
       // bail out. If it is not of the same type, we throw an exception.
       if (this._listeners[name] != undefined) {
-        if (!!aMsg.strongRef == this._listeners[name]) {
+        if (!!aMsg.weakRef == this._listeners[name]) {
           return;
         } else {
           throw Cr.NS_ERROR_FAILURE;
         }
       }
 
-      aMsg.strongRef ? cpmm.addMessageListener(name, this)
-                     : cpmm.addWeakMessageListener(name, this);
-      this._listeners[name] = !!aMsg.strongRef;
+      aMsg.weakRef ? cpmm.addWeakMessageListener(name, this)
+                   : cpmm.addMessageListener(name, this);
+      this._listeners[name] = !!aMsg.weakRef;
     });
   },
 
   /**
    * 'aMessages' is expected to be a string or an array of strings containing
    * the message names of the listeners to be removed.
    */
   removeMessageListeners: function(aMessages) {
@@ -112,38 +111,38 @@ DOMRequestIpcHelper.prototype = {
       aMessages = [aMessages];
     }
 
     aMessages.forEach((aName) => {
       if (this._listeners[aName] == undefined) {
         return;
       }
 
-      this._listeners[aName] ? cpmm.removeMessageListener(aName, this)
-                             : cpmm.removeWeakMessageListener(aName, this);
+      this._listeners[aName] ? cpmm.removeWeakMessageListener(aName, this)
+                             : cpmm.removeMessageListener(aName, this);
       delete this._listeners[aName];
     });
   },
 
   /**
    * Initialize the helper adding the corresponding listeners to the messages
    * provided as the second parameter.
    *
    * 'aMessages' is expected to be an array of either:
    *
    *  - objects of this form:
    *    {
    *      name: 'messageName',
-   *      strongRef: false
+   *      weakRef: false
    *    }
-   *    where 'name' is the message identifier and 'strongRef' a boolean
-   *    indicating if the listener should be a strong referred one or not.
+   *    where 'name' is the message identifier and 'weakRef' a boolean
+   *    indicating if the listener should be a weak referred one or not.
    *
    *  - or only strings containing the message name, in which case the listener
-   *    will be added as a weak referred one by default.
+   *    will be added as a strong referred one by default.
    */
   initDOMRequestHelper: function(aWindow, aMessages) {
     // Query our required interfaces to force a fast fail if they are not
     // provided. These calls will throw if the interface is not available.
     this.QueryInterface(Ci.nsISupportsWeakReference);
     this.QueryInterface(Ci.nsIObserver);
 
     if (aMessages) {
@@ -172,18 +171,18 @@ DOMRequestIpcHelper.prototype = {
     }
 
     this._destroyed = true;
 
     Services.obs.removeObserver(this, "inner-window-destroyed");
 
     if (this._listeners) {
       Object.keys(this._listeners).forEach((aName) => {
-        this._listeners[aName] ? cpmm.removeMessageListener(aName, this)
-                               : cpmm.removeWeakMessageListener(aName, this);
+        this._listeners[aName] ? cpmm.removeWeakMessageListener(aName, this)
+                               : cpmm.removeMessageListener(aName, this);
         delete this._listeners[aName];
       });
     }
 
     this._listeners = null;
     this._requests = null;
 
     // Objects inheriting from DOMRequestIPCHelper may have an uninit function.
--- a/dom/base/test/test_domrequesthelper.xul
+++ b/dom/base/test/test_domrequesthelper.xul
@@ -196,20 +196,20 @@
         ok(true, "== DestroyDOMRequestHelper");
         destroyDOMRequestHelperTest();
         next();
       },
       function() {
         ok(true, "== InitDOMRequestHelper with objects array");
         initDOMRequestHelperTest([{
           name: "name1",
-          strongRef: false
+          weakRef: false
         }, {
           name: "nameN",
-          strongRef: true
+          weakRef: true
         }]);
         checkMessageListeners({"name1": false, "nameN": true}, 2);
         next();
       },
       function() {
         ok(true, "== AddMessageListeners empty array");
         addMessageListenersTest([], {"name1": false, "nameN": true}, 2);
         next();
@@ -238,20 +238,20 @@
           "nameN": true
         }, 5);
         next();
       },
       function() {
         ok(true, "== AddMessageListeners new listeners, objects array");
         addMessageListenersTest([{
           name: "name5",
-          strongRef: true
+          weakRef: true
         }, {
           name: "name6",
-          strongRef: false
+          weakRef: false
         }], {
           "name1": false,
           "name2": false,
           "name3": false,
           "name4": false,
           "name5": true,
           "name6": false,
           "nameN": true
@@ -315,17 +315,17 @@
           next();
         } catch (ex) {
           ok(false, "Unexpected exception " + ex);
         }
       },
       function() {
         ok(true, "== AddMessageListeners, same message, different kind");
         try {
-          addMessageListenersTest({name: "name4", strongRef: true}, {
+          addMessageListenersTest({name: "name4", weakRef: true}, {
             "name4": true,
             "name5": true,
             "name6": false,
             "nameN": true
           }, 4);
           ok(false, "Should have thrown an exception");
         } catch (ex) {
           ok(true, "Expected exception");
@@ -430,41 +430,41 @@
         ok(true, "== Test window destroyed without messages and with GC");
         checkWindowDestruction({ gc: true }, function(uninitCalled) {
           ok(!uninitCalled, "uninit() should NOT have been called");
           next();
         });
       },
       function() {
         ok(true, "== Test window destroyed with weak messages and without GC");
-        checkWindowDestruction({ messages: [{ name: "foo", strongRef: false }],
+        checkWindowDestruction({ messages: [{ name: "foo", weakRef: true }],
                                  gc: false }, function(uninitCalled) {
           ok(uninitCalled, "uninit() should have been called");
           next();
         });
       },
       function() {
         ok(true, "== Test window destroyed with weak messages and with GC");
-        checkWindowDestruction({ messages: [{ name: "foo", strongRef: false }],
+        checkWindowDestruction({ messages: [{ name: "foo", weakRef: true }],
                                  gc: true }, function(uninitCalled) {
           ok(!uninitCalled, "uninit() should NOT have been called");
           next();
         });
       },
       function() {
         ok(true, "== Test window destroyed with strong messages and without GC");
-        checkWindowDestruction({ messages: [{ name: "foo", strongRef: true }],
+        checkWindowDestruction({ messages: [{ name: "foo", weakRef: false }],
                                  gc: false }, function(uninitCalled) {
           ok(uninitCalled, "uninit() should have been called");
           next();
         });
       },
       function() {
         ok(true, "== Test window destroyed with strong messages and with GC");
-        checkWindowDestruction({ messages: [{ name: "foo", strongRef: true }],
+        checkWindowDestruction({ messages: [{ name: "foo", weakRef: false }],
                                  gc: true }, function(uninitCalled) {
           ok(uninitCalled, "uninit() should have been called");
           next();
         });
       }
     ];
 
     function next() {