Bug 1298939: Don't register cleanup functions for listeners until the first time they're added. r=rpl
authorKris Maglione <maglione.k@gmail.com>
Fri, 26 Aug 2016 16:58:54 -0700
changeset 312351 3be5f41dcbd78ecfc12706d5de83cc3a429f9a42
parent 312350 c4d0a934472960be184bee8048a99c9c8c1d65a1
child 312352 2d673f97bf4dd6fc3d4be6ef1888e417e30b7100
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1298939
milestone51.0a1
Bug 1298939: Don't register cleanup functions for listeners until the first time they're added. r=rpl MozReview-Commit-ID: Ai8MxlB2qSb
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -974,31 +974,31 @@ EventManager.prototype = {
 // Similar to EventManager, but it doesn't try to consolidate event
 // notifications. Each addListener call causes us to register once. It
 // allows extra arguments to be passed to addListener.
 function SingletonEventManager(context, name, register) {
   this.context = context;
   this.name = name;
   this.register = register;
   this.unregister = new Map();
-  context.callOnClose(this);
 }
 
 SingletonEventManager.prototype = {
   addListener(callback, ...args) {
     let wrappedCallback = (...args) => {
       if (this.context.unloaded) {
         dump(`${this.name} event fired after context unloaded.\n`);
       } else if (this.unregister.has(callback)) {
         return callback(...args);
       }
     };
 
     let unregister = this.register(wrappedCallback, ...args);
     this.unregister.set(callback, unregister);
+    this.context.callOnClose(this);
   },
 
   removeListener(callback) {
     if (!this.unregister.has(callback)) {
       return;
     }
 
     let unregister = this.unregister.get(callback);