Bug 1299411 - Unify fire and fireWithoutClone. r=kmag
authorRob Wu <rob@robwu.nl>
Sat, 24 Sep 2016 11:48:43 +0200
changeset 320060 e08ee4c2b1e2a0f9020f9a02f5c0ded4b1aa4ab2
parent 320059 502aaf0691ccecb5988d719cf904fb52c992dce3
child 320061 0ce4a6653d1966333fa72a29f762fdde5614d02f
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1299411
milestone52.0a1
Bug 1299411 - Unify fire and fireWithoutClone. r=kmag 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;
   },