Bug 1473513 - reduce number of poolFor calls; r=ochameau draft
authoryulia <ystartsev@mozilla.com>
Tue, 21 Aug 2018 11:45:42 +0200
changeset 830722 358847f12aa241dd6048d418f14538dbbef43983
parent 830721 5c4005041d8b65cd4e7f08e4edd8b2c57e7642c8
push id118849
push userbmo:ystartsev@mozilla.com
push dateWed, 22 Aug 2018 10:34:16 +0000
reviewersochameau
bugs1473513
milestone63.0a1
Bug 1473513 - reduce number of poolFor calls; r=ochameau MozReview-Commit-ID: 9VqKPauAP9j
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -854,26 +854,28 @@ Pool.prototype = extend(EventEmitter.pro
   },
 
   /**
    * Add an actor as a child of this pool.
    */
   manage: function(actor) {
     if (!actor.actorID) {
       actor.actorID = this.conn.allocID(actor.actorPrefix || actor.typeName);
-    }
+    } else {
+      // If the actor is already registerd in a pool, remove it without destroying it.
+      // This happens for example when an addon is reloaded. To see this behavior, take a
+      // look at devtools/server/tests/unit/test_addon_reload.js
 
-    // If the actor is already in a pool, remove it without destroying it.
-    // TODO: not all actors have been moved to protocol.js, so they do not all have
-    // a parent field. Remove the check for the parent once the conversion is finished
-    const parent = this.poolFor(actor.actorID);
-    if (parent) {
-      parent.unmanage(actor);
+      // TODO: not all actors have been moved to protocol.js, so they do not all have
+      // a parent field. Remove the check for the parent once the conversion is finished
+      const parent = this.poolFor(actor.actorID);
+      if (parent) {
+        parent.unmanage(actor);
+      }
     }
-
     this._poolMap.set(actor.actorID, actor);
     return actor;
   },
 
   /**
    * Remove an actor as a child of this pool.
    */
   unmanage: function(actor) {