Bug 1241339 - ObserverService may keep Console object alive until shutdown, r=baku
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 21 Jan 2016 15:17:33 +0200
changeset 280925 95a25c159a0ebe141f0c87ad2ba6cd0b7ac1d316
parent 280924 276bf29a46c45596ca99e1c0283aa1d6a3707a50
child 280926 a8b5e254799b4ba7050c2291cc3b07cf6c7ee98d
push id70623
push useropettay@mozilla.com
push dateThu, 21 Jan 2016 13:25:57 +0000
treeherdermozilla-inbound@95a25c159a0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1241339
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1241339 - ObserverService may keep Console object alive until shutdown, r=baku
dom/base/Console.cpp
dom/base/Console.h
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -680,17 +680,18 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Con
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Console)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Console)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Console)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
+  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 Console::Console(nsPIDOMWindow* aWindow)
   : mWindow(aWindow)
   , mOuterID(0)
   , mInnerID(0)
 {
   if (mWindow) {
@@ -704,17 +705,17 @@ Console::Console(nsPIDOMWindow* aWindow)
     if (outerWindow) {
       mOuterID = outerWindow->WindowID();
     }
   }
 
   if (NS_IsMainThread()) {
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
-      obs->AddObserver(this, "inner-window-destroyed", false);
+      obs->AddObserver(this, "inner-window-destroyed", true);
     }
   }
 
   mozilla::HoldJSObjects(this);
 }
 
 Console::~Console()
 {
--- a/dom/base/Console.h
+++ b/dom/base/Console.h
@@ -9,37 +9,39 @@
 
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/JSObjectHolder.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsIObserver.h"
+#include "nsWeakReference.h"
 #include "nsWrapperCache.h"
 #include "nsDOMNavigationTiming.h"
 #include "nsPIDOMWindow.h"
 
 class nsIConsoleAPIStorage;
 class nsIPrincipal;
 
 namespace mozilla {
 namespace dom {
 
 class ConsoleCallData;
 struct ConsoleStackEntry;
 
 class Console final : public nsIObserver
                     , public nsWrapperCache
+                    , public nsSupportsWeakReference
 {
   ~Console();
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Console)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console, nsIObserver)
   NS_DECL_NSIOBSERVER
 
   explicit Console(nsPIDOMWindow* aWindow);
 
   // WebIDL methods
   nsISupports* GetParentObject() const
   {
     return mWindow;