Bug 1025077 - patch 2 - ServiceWorkerContainer should unregister its promise on dtor, r=nsm
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 28 Aug 2014 17:04:51 +0100
changeset 223853 aed61458371b3d342433d9543c89ea6001ef3043
parent 223852 d3636970a300be806482b9b5ad00db036166c67b
child 223854 a2481fd3296c6f4ba35cbf22743b8a86474deac5
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1025077
milestone34.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 1025077 - patch 2 - ServiceWorkerContainer should unregister its promise on dtor, r=nsm
dom/workers/ServiceWorkerContainer.cpp
dom/workers/ServiceWorkerContainer.h
--- a/dom/workers/ServiceWorkerContainer.cpp
+++ b/dom/workers/ServiceWorkerContainer.cpp
@@ -34,27 +34,37 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Servi
 
 ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindow* aWindow)
   : DOMEventTargetHelper(aWindow)
 {
 }
 
 ServiceWorkerContainer::~ServiceWorkerContainer()
 {
+  RemoveReadyPromise();
 }
 
 void
 ServiceWorkerContainer::DisconnectFromOwner()
 {
-  nsCOMPtr<nsIServiceWorkerManager> swm = mozilla::services::GetServiceWorkerManager();
-  MOZ_ASSERT(swm);
+  RemoveReadyPromise();
+  DOMEventTargetHelper::DisconnectFromOwner();
+}
 
-  swm->RemoveReadyPromise(GetOwner());
+void
+ServiceWorkerContainer::RemoveReadyPromise()
+{
+  nsCOMPtr<nsPIDOMWindow> window = GetOwner();
+  if (window) {
+    nsCOMPtr<nsIServiceWorkerManager> swm =
+      mozilla::services::GetServiceWorkerManager();
+    MOZ_ASSERT(swm);
 
-  DOMEventTargetHelper::DisconnectFromOwner();
+    swm->RemoveReadyPromise(window);
+  }
 }
 
 JSObject*
 ServiceWorkerContainer::WrapObject(JSContext* aCx)
 {
   return ServiceWorkerContainerBinding::Wrap(aCx, this);
 }
 
--- a/dom/workers/ServiceWorkerContainer.h
+++ b/dom/workers/ServiceWorkerContainer.h
@@ -70,16 +70,18 @@ public:
                                        ErrorResult& aRv);
 
   // DOMEventTargetHelper
   void DisconnectFromOwner() MOZ_OVERRIDE;
 
 private:
   ~ServiceWorkerContainer();
 
+  void RemoveReadyPromise();
+
   // This only changes when a worker hijacks everything in its scope by calling
   // replace().
   // FIXME(nsm): Bug 982711. Provide API to let SWM invalidate this.
   nsRefPtr<workers::ServiceWorker> mControllerWorker;
 
   nsRefPtr<Promise> mReadyPromise;
 };