Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau
authoryulia <ystartsev@mozilla.com>
Wed, 25 Apr 2018 14:46:44 +0200
changeset 471853 902a66d98a6a3894bece6525370f220d2de749c2
parent 471852 f03bcb0ba0b4013b912fd08e12fcdb75c79fbce2
child 471854 dbf976eaf769cae4d8a87b4f6e26d7a6caa20d92
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1450948
milestone61.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 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