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
--- 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;
},