Bug 1465103 - Convert service worker and clients release assertions to diagnostic assertions. r=asuth, a=RyanVM DEVEDITION_61_0b11_BUILD1 DEVEDITION_61_0b11_RELEASE FENNEC_61_0b11_BUILD1 FENNEC_61_0b11_RELEASE FIREFOX_61_0b11_BUILD1 FIREFOX_61_0b11_RELEASE
authorBen Kelly <ben@wanderview.com>
Fri, 01 Jun 2018 13:36:34 -0700
changeset 806193 c13cb09f0c253f11b1612633c4d0e32e2af04856
parent 806192 8721ccdef78438e3968b2304d62f980817ac9055
child 806194 aa9a2162fe05e38133728abbab213a8c1e9a8eb1
push id112844
push usermaglione.k@gmail.com
push dateFri, 08 Jun 2018 22:18:59 +0000
reviewersasuth, RyanVM
bugs1465103
milestone61.0
Bug 1465103 - Convert service worker and clients release assertions to diagnostic assertions. r=asuth, a=RyanVM
dom/clients/manager/ClientHandle.cpp
dom/clients/manager/ClientHandleOpChild.cpp
dom/clients/manager/ClientManager.cpp
dom/clients/manager/ClientThing.h
dom/serviceworkers/ServiceWorkerManager.cpp
--- a/dom/clients/manager/ClientHandle.cpp
+++ b/dom/clients/manager/ClientHandle.cpp
@@ -45,26 +45,26 @@ ClientHandle::StartOp(const ClientOpCons
 {
   // Hold a ref to the client until the remote operation completes.  Otherwise
   // the ClientHandle might get de-refed and teardown the actor before we
   // get an answer.
   RefPtr<ClientHandle> kungFuGrip = this;
 
   MaybeExecute([aArgs, kungFuGrip, aRejectCallback,
                 resolve = Move(aResolveCallback)] (ClientHandleChild* aActor) {
-    MOZ_RELEASE_ASSERT(aActor);
+    MOZ_DIAGNOSTIC_ASSERT(aActor);
     ClientHandleOpChild* actor =
       new ClientHandleOpChild(kungFuGrip, aArgs, Move(resolve),
                               Move(aRejectCallback));
     if (!aActor->SendPClientHandleOpConstructor(actor, aArgs)) {
       // Constructor failure will call reject callback via ActorDestroy()
       return;
     }
   }, [aRejectCallback] {
-    MOZ_RELEASE_ASSERT(aRejectCallback);
+    MOZ_DIAGNOSTIC_ASSERT(aRejectCallback);
     aRejectCallback(NS_ERROR_DOM_INVALID_STATE_ERR);
   });
 }
 
 void
 ClientHandle::OnShutdownThing()
 {
   NS_ASSERT_OWNINGTHREAD(ClientHandle);
--- a/dom/clients/manager/ClientHandleOpChild.cpp
+++ b/dom/clients/manager/ClientHandleOpChild.cpp
@@ -34,15 +34,15 @@ ClientHandleOpChild::Recv__delete__(cons
 ClientHandleOpChild::ClientHandleOpChild(ClientHandle* aClientHandle,
                                          const ClientOpConstructorArgs& aArgs,
                                          const ClientOpCallback&& aResolveCallback,
                                          const ClientOpCallback&& aRejectCallback)
   : mClientHandle(aClientHandle)
   , mResolveCallback(Move(aResolveCallback))
   , mRejectCallback(Move(aRejectCallback))
 {
-  MOZ_RELEASE_ASSERT(mClientHandle);
-  MOZ_RELEASE_ASSERT(mResolveCallback);
-  MOZ_RELEASE_ASSERT(mRejectCallback);
+  MOZ_DIAGNOSTIC_ASSERT(mClientHandle);
+  MOZ_DIAGNOSTIC_ASSERT(mResolveCallback);
+  MOZ_DIAGNOSTIC_ASSERT(mRejectCallback);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/clients/manager/ClientManager.cpp
+++ b/dom/clients/manager/ClientManager.cpp
@@ -23,22 +23,31 @@ namespace dom {
 
 using mozilla::ipc::BackgroundChild;
 using mozilla::ipc::PBackgroundChild;
 using mozilla::ipc::PrincipalInfo;
 
 namespace {
 
 const uint32_t kBadThreadLocalIndex = -1;
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
 const uint32_t kThreadLocalMagic1 = 0x8d57eea6;
 const uint32_t kThreadLocalMagic2 = 0x59f375c9;
+#endif
+
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
 uint32_t sClientManagerThreadLocalMagic1 = kThreadLocalMagic1;
+#endif
+
 uint32_t sClientManagerThreadLocalIndex = kBadThreadLocalIndex;
+
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
 uint32_t sClientManagerThreadLocalMagic2 = kThreadLocalMagic2;
 uint32_t sClientManagerThreadLocalIndexDuplicate = kBadThreadLocalIndex;
+#endif
 
 } // anonymous namespace
 
 ClientManager::ClientManager()
 {
   PBackgroundChild* parentActor = BackgroundChild::GetOrCreateForCurrentThread();
   if (NS_WARN_IF(!parentActor)) {
     Shutdown();
@@ -79,21 +88,21 @@ ClientManager::ClientManager()
 }
 
 ClientManager::~ClientManager()
 {
   NS_ASSERT_OWNINGTHREAD(ClientManager);
 
   Shutdown();
 
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
-  MOZ_RELEASE_ASSERT(this == PR_GetThreadPrivate(sClientManagerThreadLocalIndex));
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
+  MOZ_DIAGNOSTIC_ASSERT(this == PR_GetThreadPrivate(sClientManagerThreadLocalIndex));
 
 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   PRStatus status =
 #endif
     PR_SetThreadPrivate(sClientManagerThreadLocalIndex, nullptr);
   MOZ_DIAGNOSTIC_ASSERT(status == PR_SUCCESS);
 }
 
@@ -189,34 +198,34 @@ ClientManager::StartOp(const ClientOpCon
   RefPtr<ClientOpPromise> ref = promise.get();
   return ref.forget();
 }
 
 // static
 already_AddRefed<ClientManager>
 ClientManager::GetOrCreateForCurrentThread()
 {
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
   RefPtr<ClientManager> cm =
     static_cast<ClientManager*>(PR_GetThreadPrivate(sClientManagerThreadLocalIndex));
 
   if (!cm) {
     cm = new ClientManager();
 
 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
     PRStatus status =
 #endif
       PR_SetThreadPrivate(sClientManagerThreadLocalIndex, cm.get());
     MOZ_DIAGNOSTIC_ASSERT(status == PR_SUCCESS);
   }
 
-  MOZ_RELEASE_ASSERT(cm);
+  MOZ_DIAGNOSTIC_ASSERT(cm);
   return cm.forget();
 }
 
 WorkerPrivate*
 ClientManager::GetWorkerPrivate() const
 {
   NS_ASSERT_OWNINGTHREAD(ClientManager);
   MOZ_DIAGNOSTIC_ASSERT(GetActor());
@@ -224,29 +233,31 @@ ClientManager::GetWorkerPrivate() const
 }
 
 // static
 void
 ClientManager::Startup()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex == kBadThreadLocalIndex);
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic1 == kThreadLocalMagic1);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalMagic2 == kThreadLocalMagic2);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex == kBadThreadLocalIndex);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex == sClientManagerThreadLocalIndexDuplicate);
 
 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   PRStatus status =
 #endif
     PR_NewThreadPrivateIndex(&sClientManagerThreadLocalIndex, nullptr);
   MOZ_DIAGNOSTIC_ASSERT(status == PR_SUCCESS);
 
-  MOZ_RELEASE_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
+  MOZ_DIAGNOSTIC_ASSERT(sClientManagerThreadLocalIndex != kBadThreadLocalIndex);
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   sClientManagerThreadLocalIndexDuplicate = sClientManagerThreadLocalIndex;
+#endif
 
   ClientPrefsInit();
 }
 
 // static
 UniquePtr<ClientSource>
 ClientManager::CreateSource(ClientType aType, nsISerialEventTarget* aEventTarget,
                             nsIPrincipal* aPrincipal)
--- a/dom/clients/manager/ClientThing.h
+++ b/dom/clients/manager/ClientThing.h
@@ -12,46 +12,54 @@ namespace mozilla {
 namespace dom {
 
 // Base class representing various Client "things" such as ClientHandle,
 // ClientSource, and ClientManager.  Currently it provides a common set
 // of code for handling activation and shutdown of IPC actors.
 template <typename ActorType>
 class ClientThing
 {
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   static const uint32_t kMagic1 = 0xC9FE2C9C;
   static const uint32_t kMagic2 = 0x832072D4;
+#endif
 
   ActorType* mActor;
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   uint32_t mMagic1;
   uint32_t mMagic2;
+#endif
   bool mShutdown;
 
 protected:
   ClientThing()
     : mActor(nullptr)
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
     , mMagic1(kMagic1)
     , mMagic2(kMagic2)
+#endif
     , mShutdown(false)
   {
   }
 
   ~ClientThing()
   {
     AssertIsValid();
     ShutdownThing();
+#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
     mMagic1 = 0;
     mMagic2 = 0;
+#endif
   }
 
   void
   AssertIsValid() const
   {
-    MOZ_RELEASE_ASSERT(mMagic1 == kMagic1);
-    MOZ_RELEASE_ASSERT(mMagic2 == kMagic2);
+    MOZ_DIAGNOSTIC_ASSERT(mMagic1 == kMagic1);
+    MOZ_DIAGNOSTIC_ASSERT(mMagic2 == kMagic2);
   }
 
   // Return the current actor.
   ActorType*
   GetActor() const
   {
     AssertIsValid();
     return mActor;
--- a/dom/serviceworkers/ServiceWorkerManager.cpp
+++ b/dom/serviceworkers/ServiceWorkerManager.cpp
@@ -307,17 +307,17 @@ ServiceWorkerManager::Init(ServiceWorker
 
   mActor = static_cast<ServiceWorkerManagerChild*>(actor);
 }
 
 RefPtr<GenericPromise>
 ServiceWorkerManager::StartControllingClient(const ClientInfo& aClientInfo,
                                              ServiceWorkerRegistrationInfo* aRegistrationInfo)
 {
-  MOZ_RELEASE_ASSERT(aRegistrationInfo->GetActive());
+  MOZ_DIAGNOSTIC_ASSERT(aRegistrationInfo->GetActive());
 
   RefPtr<GenericPromise> ref;
 
   const ServiceWorkerDescriptor& active =
     aRegistrationInfo->GetActive()->Descriptor();
 
   auto entry = mControlledClients.LookupForAdd(aClientInfo.Id());
   if (entry) {