Bug 1450948 - collect actorSpecs in a weakmap. r=ochameau

MozReview-Commit-ID: 7O4edWRb7cF

--HG--
extra : rebase_source : 80421fa98d9f988cf0b73508a811b41568012465
This commit is contained in:
yulia 2018-04-25 14:46:44 +02:00
Родитель 318a381a6e
Коммит bb64c024ae
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -926,6 +926,13 @@ Pool.prototype = extend(EventEmitter.prototype, {
});
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.
*
@ -938,6 +945,7 @@ exports.Pool = Pool;
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()) {
@ -1170,8 +1178,6 @@ var generateRequestHandlers = function(actorSpec, actorProto) {
actorProto.requestTypes[spec.request.type] = handler;
});
actorProto._actorSpec = actorSpec;
return actorProto;
};
@ -1197,6 +1203,8 @@ var ActorClassWithSpec = function(actorSpec, actorProto) {
};
cls.prototype = extend(Actor.prototype, generateRequestHandlers(actorSpec, actorProto));
actorSpecs.set(cls.prototype, actorSpec);
return cls;
};
exports.ActorClassWithSpec = ActorClassWithSpec;