Bug 1299411 - Unify fire and fireWithoutClone. draft
authorRob Wu <rob@robwu.nl>
Sat, 24 Sep 2016 11:48:43 +0200
changeset 429205 79017d9c912697630d4354e748c8328b8c0b7737
parent 429204 b73635f95a04da1fe572fade4a2e00322c7bb521
child 429206 cb9d7efa71123bf0752c4f323861d3e9ec379dc9
child 430560 0923e59b89f3bad1163228e754dabd3efdec1d1c
child 430570 8b3b2a7da7d6167a6ba86ecd8f63ef1c0f2a38c9
push id33512
push userbmo:rob@robwu.nl
push dateTue, 25 Oct 2016 14:01:58 +0000
bugs1299411
milestone52.0a1
Bug 1299411 - Unify fire and fireWithoutClone. Unify implementation of fire and fireWithoutClone. `fireWithoutClone` was running the callbacks synchronously. After this commit the callback is run asynchronously. This is safe because the only user of this method is `Port`'s `onDisconnect`. MozReview-Commit-ID: 1kiYavsu3e7
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -965,33 +965,37 @@ EventManager.prototype = {
     }
   },
 
   hasListener(callback) {
     return this.callbacks.has(callback);
   },
 
   fire(...args) {
+    this._fireCommon("runSafe", args);
+  },
+
+  fireWithoutClone(...args) {
+    this._fireCommon("runSafeWithoutClone", args);
+  },
+
+  _fireCommon(runSafeMethod, args) {
     for (let callback of this.callbacks) {
       Promise.resolve(callback).then(callback => {
         if (this.context.unloaded) {
           dump(`${this.name} event fired after context unloaded.\n`);
+        } else if (!this.context.active) {
+          dump(`${this.name} event fired while context is inactive.\n`);
         } else if (this.callbacks.has(callback)) {
-          this.context.runSafe(callback, ...args);
+          this.context[runSafeMethod](callback, ...args);
         }
       });
     }
   },
 
-  fireWithoutClone(...args) {
-    for (let callback of this.callbacks) {
-      this.context.runSafeWithoutClone(callback, ...args);
-    }
-  },
-
   close() {
     if (this.callbacks.size) {
       this.unregister();
     }
     this.callbacks.clear();
     this.register = null;
     this.unregister = null;
   },