Bug 1456981 Use DOMMozPromiseRequestHolder in ServiceWorkerContainer. r=baku
authorBen Kelly <ben@wanderview.com>
Thu, 26 Apr 2018 13:53:20 -0700
changeset 472061 43385aef5932a5d988709919e82c90c96af1ba1b
parent 472060 89c938649297519b4f11780a8d1d9c5d6e695f35
child 472062 83d635a4720194bec17d98035878d33cca1aa0e8
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1456981
milestone61.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 1456981 Use DOMMozPromiseRequestHolder in ServiceWorkerContainer. r=baku
dom/serviceworkers/ServiceWorkerContainer.cpp
--- a/dom/serviceworkers/ServiceWorkerContainer.cpp
+++ b/dom/serviceworkers/ServiceWorkerContainer.cpp
@@ -16,16 +16,17 @@
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/Services.h"
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsServiceManagerUtils.h"
 
 #include "mozilla/LoadInfo.h"
+#include "mozilla/dom/DOMMozPromiseRequestHolder.h"
 #include "mozilla/dom/DOMPrefs.h"
 #include "mozilla/dom/Navigator.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ServiceWorker.h"
 #include "mozilla/dom/ServiceWorkerContainerBinding.h"
 
 #include "ServiceWorker.h"
 #include "ServiceWorkerContainerImpl.h"
@@ -352,33 +353,37 @@ ServiceWorkerContainer::Register(const n
   window->NoteCalledRegisterForServiceWorkerScope(cleanedScopeURL);
 
   RefPtr<Promise> outer = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   RefPtr<ServiceWorkerContainer> self = this;
+  RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>> holder =
+    new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>(global);
 
   mInner->Register(clientInfo.ref(), cleanedScopeURL, cleanedScriptURL,
                    aOptions.mUpdateViaCache)->Then(
     global->EventTargetFor(TaskCategory::Other), __func__,
-    [self, outer] (const ServiceWorkerRegistrationDescriptor& aDesc) {
+    [self, outer, holder] (const ServiceWorkerRegistrationDescriptor& aDesc) {
+      holder->Complete();
       ErrorResult rv;
       nsIGlobalObject* global = self->GetGlobalIfValid(rv);
       if (rv.Failed()) {
         outer->MaybeReject(rv);
         return;
       }
       RefPtr<ServiceWorkerRegistration> reg =
         global->GetOrCreateServiceWorkerRegistration(aDesc);
       outer->MaybeResolve(reg);
-    }, [self, outer] (const CopyableErrorResult& aRv) {
+    }, [self, outer, holder] (const CopyableErrorResult& aRv) {
+      holder->Complete();
       outer->MaybeReject(CopyableErrorResult(aRv));
-    });
+    })->Track(*holder);
 
   return outer.forget();
 }
 
 already_AddRefed<ServiceWorker>
 ServiceWorkerContainer::GetController()
 {
   RefPtr<ServiceWorker> ref = mControllerWorker;
@@ -405,38 +410,42 @@ ServiceWorkerContainer::GetRegistrations
   }
 
   RefPtr<Promise> outer = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   RefPtr<ServiceWorkerContainer> self = this;
+  RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationListPromise>> holder =
+    new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationListPromise>(global);
 
   mInner->GetRegistrations(clientInfo.ref())->Then(
     global->EventTargetFor(TaskCategory::Other), __func__,
-    [self, outer] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aDescList) {
+    [self, outer, holder] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aDescList) {
+      holder->Complete();
       ErrorResult rv;
       nsIGlobalObject* global = self->GetGlobalIfValid(rv);
       if (rv.Failed()) {
         outer->MaybeReject(rv);
         return;
       }
       nsTArray<RefPtr<ServiceWorkerRegistration>> regList;
       for (auto& desc : aDescList) {
         RefPtr<ServiceWorkerRegistration> reg =
           global->GetOrCreateServiceWorkerRegistration(desc);
         if (reg) {
           regList.AppendElement(Move(reg));
         }
       }
       outer->MaybeResolve(regList);
-    }, [self, outer] (const CopyableErrorResult& aRv) {
+    }, [self, outer, holder] (const CopyableErrorResult& aRv) {
+      holder->Complete();
       outer->MaybeReject(CopyableErrorResult(aRv));
-    });
+    })->Track(*holder);
 
   return outer.forget();
 }
 
 already_AddRefed<Promise>
 ServiceWorkerContainer::GetRegistration(const nsAString& aURL,
                                         ErrorResult& aRv)
 {
@@ -474,38 +483,42 @@ ServiceWorkerContainer::GetRegistration(
   }
 
   RefPtr<Promise> outer = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   RefPtr<ServiceWorkerContainer> self = this;
+  RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>> holder =
+    new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>(global);
 
   mInner->GetRegistration(clientInfo.ref(), spec)->Then(
     global->EventTargetFor(TaskCategory::Other), __func__,
-    [self, outer] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
+    [self, outer, holder] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
+      holder->Complete();
       ErrorResult rv;
       nsIGlobalObject* global = self->GetGlobalIfValid(rv);
       if (rv.Failed()) {
         outer->MaybeReject(rv);
         return;
       }
       RefPtr<ServiceWorkerRegistration> reg =
         global->GetOrCreateServiceWorkerRegistration(aDescriptor);
       outer->MaybeResolve(reg);
-    }, [self, outer] (const CopyableErrorResult& aRv) {
+    }, [self, outer, holder] (const CopyableErrorResult& aRv) {
+      holder->Complete();
       ErrorResult rv;
       Unused << self->GetGlobalIfValid(rv);
       if (!rv.Failed() && !aRv.Failed()) {
         outer->MaybeResolveWithUndefined();
         return;
       }
       outer->MaybeReject(CopyableErrorResult(aRv));
-    });
+    })->Track(*holder);
 
   return outer.forget();
 }
 
 Promise*
 ServiceWorkerContainer::GetReady(ErrorResult& aRv)
 {
   if (mReadyPromise) {
@@ -526,33 +539,37 @@ ServiceWorkerContainer::GetReady(ErrorRe
 
   mReadyPromise = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   RefPtr<ServiceWorkerContainer> self = this;
   RefPtr<Promise> outer = mReadyPromise;
+  RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>> holder =
+    new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>(global);
 
   mInner->GetReady(clientInfo.ref())->Then(
     global->EventTargetFor(TaskCategory::Other), __func__,
-    [self, outer] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
+    [self, outer, holder] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
+      holder->Complete();
       ErrorResult rv;
       nsIGlobalObject* global = self->GetGlobalIfValid(rv);
       if (rv.Failed()) {
         outer->MaybeReject(rv);
         return;
       }
       RefPtr<ServiceWorkerRegistration> reg =
         global->GetOrCreateServiceWorkerRegistration(aDescriptor);
       NS_ENSURE_TRUE_VOID(reg);
       outer->MaybeResolve(reg);
-    }, [self, outer] (const CopyableErrorResult& aRv) {
+    }, [self, outer, holder] (const CopyableErrorResult& aRv) {
+      holder->Complete();
       outer->MaybeReject(CopyableErrorResult(aRv));
-    });
+    })->Track(*holder);
 
   return mReadyPromise;
 }
 
 // Testing only.
 void
 ServiceWorkerContainer::GetScopeForUrl(const nsAString& aUrl,
                                        nsString& aScope,