Bug 1455437 - Prevent multiple Map query by simplifying _sendEvent method. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 18 Apr 2018 15:42:37 -0700
changeset 786548 4d70c59eac6595a924f2ccac095d7666034b1a29
parent 786547 cd9bdf0f1c4835b40023f5b408d64152048b3521
push id107505
push userbmo:poirot.alex@gmail.com
push dateMon, 23 Apr 2018 14:32:06 +0000
reviewersjryans
bugs1455437
milestone61.0a1
Bug 1455437 - Prevent multiple Map query by simplifying _sendEvent method. r=jryans MozReview-Commit-ID: H5ora5qsunx
devtools/shared/protocol.js
--- 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;