Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau
MozReview-Commit-ID: 7O4edWRb7cF
--- 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