Bug 1286798 - Review fix 2 - Ensure all "storage" event listeners are gone before removing. draft
authorAndrew Sutherland <asutherland@asutherland.org>
Mon, 12 Nov 2018 10:44:04 -0500
changeset 481733 093f401c66911a6f517e315f3d89dfd4998b0a24
parent 481732 0f321e587e0c6bcbbc51e5d5e02934eb19ce767b
child 481734 64a7417dc109fb913b0c4ac76b4a857be336cc7d
push id10
push userbugmail@asutherland.org
push dateSun, 18 Nov 2018 18:57:42 +0000
bugs1286798
milestone65.0a1
Bug 1286798 - Review fix 2 - Ensure all "storage" event listeners are gone before removing. EventListenerRemoved is invoked on any removal, not just the final removal, so we need to make sure it's the final removal before removing.
dom/base/nsGlobalWindowInner.cpp
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -6709,17 +6709,22 @@ nsGlobalWindowInner::EventListenerRemove
       mTabChild &&
       (!mDoc || !(mDoc->GetSandboxFlags() & SANDBOXED_MODALS))) {
     mBeforeUnloadListenerCount--;
     MOZ_ASSERT(mBeforeUnloadListenerCount >= 0);
     mTabChild->BeforeUnloadRemoved();
   }
 
   if (aType == nsGkAtoms::onstorage) {
-    if (NextGenLocalStorageEnabled() && mLocalStorage) {
+    auto elm = GetExistingListenerManager();
+    if (NextGenLocalStorageEnabled() && mLocalStorage &&
+        // The remove event is fired even if this isn't the last listener, so
+        // only remove if there are no other listeners left.
+        elm &&
+        !elm->HasListenersFor(nsGkAtoms::onstorage)) {
       auto object = static_cast<LSObject*>(mLocalStorage.get());
 
       object->DropObserver();
     }
   }
 }
 
 void