Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau
authoryulia <ystartsev@mozilla.com>
Wed, 25 Apr 2018 14:46:44 +0200
changeset 460819 902a66d98a6a3894bece6525370f220d2de749c2
parent 460818 f03bcb0ba0b4013b912fd08e12fcdb75c79fbce2
child 460820 dbf976eaf769cae4d8a87b4f6e26d7a6caa20d92
push id165
push userfmarier@mozilla.com
push dateMon, 30 Apr 2018 23:50:51 +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