Bug 1455437 - Prevent multiple Map query by simplifying _sendEvent method. r=jryans
MozReview-Commit-ID: H5ora5qsunx
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -940,42 +940,36 @@ exports.Pool = Pool;
* conn can be null if the subclass provides a conn property.
* @constructor
*/
var Actor = function(conn) {
Pool.call(this, conn);
// Forward events to the connection.
if (this._actorSpec && this._actorSpec.events) {
- for (let key of this._actorSpec.events.keys()) {
- let name = key;
+ for (let [name, request] of this._actorSpec.events.entries()) {
this.on(name, (...args) => {
- this._sendEvent(name, ...args);
+ this._sendEvent(name, request, ...args);
});
}
}
};
Actor.prototype = extend(Pool.prototype, {
// Will contain the actor's ID
actorID: null,
// Existing Actors extending this class expect initialize to contain constructor logic.
initialize: Actor,
toString: function() {
return "[Actor " + this.typeName + "/" + this.actorID + "]";
},
- _sendEvent: function(name, ...args) {
- if (!this._actorSpec.events.has(name)) {
- // It's ok to emit events that don't go over the wire.
- return;
- }
- let request = this._actorSpec.events.get(name);
+ _sendEvent: function(name, request, ...args) {
let packet;
try {
packet = request.write(args, this);
} catch (ex) {
console.error("Error sending event: " + name);
throw ex;
}
packet.from = packet.from || this.actorID;