Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau draft
authoryulia <ystartsev@mozilla.com>
Wed, 25 Apr 2018 14:46:44 +0200
changeset 788335 80421fa98d9f988cf0b73508a811b41568012465
parent 787833 4003f1c84108aed4f37bca2d3c8cfb32d5ac40e9
push id107962
push userbmo:ystartsev@mozilla.com
push dateThu, 26 Apr 2018 09:52:05 +0000
reviewersochameau
bugs1450948
milestone61.0a1
Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau MozReview-Commit-ID: 7O4edWRb7cF
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -922,27 +922,35 @@ Pool.prototype = extend(EventEmitter.pro
    */
   cleanup: function() {
     this.destroy();
   }
 });
 exports.Pool = Pool;
 
 /**
+ * Keep track of which actorSpecs have been created. If a replica of a spec
+ * is created, it can be caught, and specs which inherit from other specs will
+ * not overwrite eachother.
+ */
+var actorSpecs = new WeakMap();
+
+/**
  * An actor in the actor tree.
  *
  * @param optional conn
  *   Either a DebuggerServerConnection or a DebuggerClient.  Must have
  *   addActorPool, removeActorPool, and poolFor.
  *   conn can be null if the subclass provides a conn property.
  * @constructor
  */
 var Actor = function(conn) {
   Pool.call(this, conn);
 
+  this._actorSpec = actorSpecs.get(Object.getPrototypeOf(this));
   // Forward events to the connection.
   if (this._actorSpec && this._actorSpec.events) {
     for (let [name, request] of this._actorSpec.events.entries()) {
       this.on(name, (...args) => {
         this._sendEvent(name, request, ...args);
       });
     }
   }
@@ -1165,18 +1173,16 @@ var generateRequestHandlers = function(a
           return p.then(() => this.writeError(e));
         });
       }
     };
 
     actorProto.requestTypes[spec.request.type] = handler;
   });
 
-  actorProto._actorSpec = actorSpec;
-
   return actorProto;
 };
 
 /**
  * Create an actor class for the given actor specification and prototype.
  *
  * @param object actorSpec
  *    The actor specification. Must have a 'typeName' property.
@@ -1192,16 +1198,18 @@ var ActorClassWithSpec = function(actorS
   // Existing Actors are relying on the initialize instead of constructor methods.
   let cls = function() {
     let instance = Object.create(cls.prototype);
     instance.initialize.apply(instance, arguments);
     return instance;
   };
   cls.prototype = extend(Actor.prototype, generateRequestHandlers(actorSpec, actorProto));
 
+  actorSpecs.set(cls.prototype, actorSpec);
+
   return cls;
 };
 exports.ActorClassWithSpec = ActorClassWithSpec;
 
 /**
  * Base class for client-side actor fronts.
  *
  * @param optional conn