Bug 1626434 - Remove nsAutoPtr usage from dom/workers. r=dom-workers-and-storage-reviewers,sg
authorEric Rahm <erahm@mozilla.com>
Fri, 03 Apr 2020 21:04:51 +0000
changeset 522060 cdaca3146baddeaaad39306f913d078b5bdf8a80
parent 522059 96614a3debc33b4223d881457e5a0d21e1439668
child 522061 2ea01a23c1bfa4fa5b6b2d60b1de608006417be2
push id111997
push usererahm@mozilla.com
push dateFri, 03 Apr 2020 22:13:48 +0000
treeherderautoland@22a884a1390f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, sg
bugs1626434
milestone76.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 1626434 - Remove nsAutoPtr usage from dom/workers. r=dom-workers-and-storage-reviewers,sg Differential Revision: https://phabricator.services.mozilla.com/D69104
dom/workers/WorkerLoadInfo.cpp
dom/workers/WorkerLoadInfo.h
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerPrivate.h
dom/workers/remoteworkers/RemoteWorkerChild.cpp
--- a/dom/workers/WorkerLoadInfo.cpp
+++ b/dom/workers/WorkerLoadInfo.cpp
@@ -107,40 +107,41 @@ nsresult WorkerLoadInfo::SetPrincipalsAn
   mPrincipalIsSystem = aPrincipal->IsSystemPrincipal();
   mPrincipalIsAddonOrExpandedAddon =
       aPrincipal->GetIsAddonOrExpandedAddonPrincipal();
 
   mCSP = aCsp;
 
   if (mCSP) {
     mCSP->GetAllowsEval(&mReportCSPViolations, &mEvalAllowed);
-    mCSPInfo = new CSPInfo();
-    nsresult rv = CSPToCSPInfo(aCsp, mCSPInfo);
+    mCSPInfo = MakeUnique<CSPInfo>();
+    nsresult rv = CSPToCSPInfo(aCsp, mCSPInfo.get());
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     mEvalAllowed = true;
     mReportCSPViolations = false;
   }
 
   mLoadGroup = aLoadGroup;
 
-  mPrincipalInfo = new PrincipalInfo();
-  mStoragePrincipalInfo = new PrincipalInfo();
+  mPrincipalInfo = MakeUnique<PrincipalInfo>();
+  mStoragePrincipalInfo = MakeUnique<PrincipalInfo>();
   mOriginAttributes = nsContentUtils::GetOriginAttributes(aLoadGroup);
 
-  nsresult rv = PrincipalToPrincipalInfo(aPrincipal, mPrincipalInfo);
+  nsresult rv = PrincipalToPrincipalInfo(aPrincipal, mPrincipalInfo.get());
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aPrincipal->Equals(aStoragePrincipal)) {
     *mStoragePrincipalInfo = *mPrincipalInfo;
   } else {
-    mStoragePrincipalInfo = new PrincipalInfo();
-    rv = PrincipalToPrincipalInfo(aStoragePrincipal, mStoragePrincipalInfo);
+    mStoragePrincipalInfo = MakeUnique<PrincipalInfo>();
+    rv = PrincipalToPrincipalInfo(aStoragePrincipal,
+                                  mStoragePrincipalInfo.get());
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   rv = nsContentUtils::GetUTFOrigin(aPrincipal, mOrigin);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
--- a/dom/workers/WorkerLoadInfo.h
+++ b/dom/workers/WorkerLoadInfo.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_WorkerLoadInfo_h
 #define mozilla_dom_workers_WorkerLoadInfo_h
 
 #include "mozilla/StorageAccess.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/dom/ChannelInfo.h"
 #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
 #include "mozilla/dom/WorkerCommon.h"
 
 #include "nsIInterfaceRequestor.h"
 #include "nsILoadContext.h"
 #include "nsISupportsImpl.h"
 #include "nsIWeakReferenceUtils.h"
@@ -59,17 +60,17 @@ struct WorkerLoadInfoData {
   nsCOMPtr<nsIScriptContext> mScriptContext;
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
   nsCOMPtr<nsIContentSecurityPolicy> mCSP;
   // Thread boundaries require us to not only store a CSP object, but also a
   // serialized version of the CSP. Reason being: Serializing a CSP to a CSPInfo
   // needs to happen on the main thread, but storing the CSPInfo needs to happen
   // on the worker thread. We move the CSPInfo into the Client within
   // ScriptLoader::PreRun().
-  nsAutoPtr<mozilla::ipc::CSPInfo> mCSPInfo;
+  UniquePtr<mozilla::ipc::CSPInfo> mCSPInfo;
 
   nsCOMPtr<nsIChannel> mChannel;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
 
   class InterfaceRequestor final : public nsIInterfaceRequestor {
     NS_DECL_ISUPPORTS
 
    public:
@@ -95,18 +96,18 @@ struct WorkerLoadInfoData {
     // BrowserChild actors alive for long after their ActorDestroy() methods are
     // called.
     nsTArray<nsWeakPtr> mBrowserChildList;
   };
 
   // Only set if we have a custom overriden load group
   RefPtr<InterfaceRequestor> mInterfaceRequestor;
 
-  nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
-  nsAutoPtr<mozilla::ipc::PrincipalInfo> mStoragePrincipalInfo;
+  UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
+  UniquePtr<mozilla::ipc::PrincipalInfo> mStoragePrincipalInfo;
   nsCString mDomain;
   nsString mOrigin;  // Derived from mPrincipal; can be used on worker thread.
 
   nsString mServiceWorkerCacheName;
   Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
   Maybe<ServiceWorkerRegistrationDescriptor>
       mServiceWorkerRegistrationDescriptor;
 
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -120,33 +120,33 @@ const nsIID kDEBUGWorkerEventTargetIID =
     0xccaba3fa,
     0x5be2,
     0x4de2,
     {0xba, 0x87, 0x3b, 0x3b, 0x5b, 0x1d, 0x5, 0xfb}};
 
 #endif
 
 template <class T>
-class AutoPtrComparator {
-  typedef nsAutoPtr<T> A;
+class UniquePtrComparator {
+  typedef UniquePtr<T> A;
   typedef T* B;
 
  public:
-  bool Equals(const A& a, const B& b) const {
+  bool Equals(const A& a, const A& b) const {
     return a && b ? *a == *b : !a && !b ? true : false;
   }
-  bool LessThan(const A& a, const B& b) const {
+  bool LessThan(const A& a, const A& b) const {
     return a && b ? *a < *b : b ? true : false;
   }
 };
 
 template <class T>
-inline AutoPtrComparator<T> GetAutoPtrComparator(
-    const nsTArray<nsAutoPtr<T>>&) {
-  return AutoPtrComparator<T>();
+inline UniquePtrComparator<T> GetUniquePtrComparator(
+    const nsTArray<UniquePtr<T>>&) {
+  return UniquePtrComparator<T>();
 }
 
 // This class is used to wrap any runnables that the worker receives via the
 // nsIEventTarget::Dispatch() method (either from NS_DispatchToCurrentThread or
 // from the worker's EventTarget).
 class ExternalRunnableWrapper final : public WorkerRunnable {
   nsCOMPtr<nsIRunnable> mWrappedRunnable;
 
@@ -1298,18 +1298,18 @@ Document* WorkerPrivate::GetDocument() c
 void WorkerPrivate::SetCSP(nsIContentSecurityPolicy* aCSP) {
   AssertIsOnMainThread();
   if (!aCSP) {
     return;
   }
   aCSP->EnsureEventTarget(mMainThreadEventTarget);
 
   mLoadInfo.mCSP = aCSP;
-  mLoadInfo.mCSPInfo = new CSPInfo();
-  nsresult rv = CSPToCSPInfo(mLoadInfo.mCSP, mLoadInfo.mCSPInfo);
+  mLoadInfo.mCSPInfo = MakeUnique<CSPInfo>();
+  nsresult rv = CSPToCSPInfo(mLoadInfo.mCSP, mLoadInfo.mCSPInfo.get());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
 
 nsresult WorkerPrivate::SetCSPFromHeaderValues(
     const nsACString& aCSPHeaderValue,
     const nsACString& aCSPReportOnlyHeaderValue) {
@@ -1360,18 +1360,18 @@ nsresult WorkerPrivate::SetCSPFromHeader
   bool reportEvalViolations = false;
   rv = csp->GetAllowsEval(&reportEvalViolations, &evalAllowed);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mLoadInfo.mCSP = csp;
   mLoadInfo.mEvalAllowed = evalAllowed;
   mLoadInfo.mReportCSPViolations = reportEvalViolations;
 
-  mLoadInfo.mCSPInfo = new CSPInfo();
-  rv = CSPToCSPInfo(csp, mLoadInfo.mCSPInfo);
+  mLoadInfo.mCSPInfo = MakeUnique<CSPInfo>();
+  rv = CSPToCSPInfo(csp, mLoadInfo.mCSPInfo.get());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 void WorkerPrivate::StoreCSPOnClient() {
   MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
@@ -3607,17 +3607,18 @@ void WorkerPrivate::PropagateFirstPartyS
   for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
     data->mChildWorkers[index]->PropagateFirstPartyStorageAccessGranted();
   }
 }
 
 void WorkerPrivate::TraverseTimeouts(nsCycleCollectionTraversalCallback& cb) {
   MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
   for (uint32_t i = 0; i < data->mTimeouts.Length(); ++i) {
-    TimeoutInfo* tmp = data->mTimeouts[i];
+    // TODO(erahm): No idea what's going on here.
+    TimeoutInfo* tmp = data->mTimeouts[i].get();
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHandler)
   }
 }
 
 void WorkerPrivate::UnlinkTimeouts() {
   MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
   data->mTimeouts.Clear();
 }
@@ -3824,17 +3825,17 @@ bool WorkerPrivate::RunCurrentSyncLoop()
   MOZ_ASSERT(cx);
 
   AutoPushEventLoopGlobal eventLoopGlobal(this, cx);
 
   // This should not change between now and the time we finish running this sync
   // loop.
   uint32_t currentLoopIndex = mSyncLoopStack.Length() - 1;
 
-  SyncLoopInfo* loopInfo = mSyncLoopStack[currentLoopIndex];
+  SyncLoopInfo* loopInfo = mSyncLoopStack[currentLoopIndex].get();
 
   AutoYieldJSThreadExecution yield;
 
   MOZ_ASSERT(loopInfo);
   MOZ_ASSERT(!loopInfo->mHasRun);
   MOZ_ASSERT(!loopInfo->mCompleted);
 
 #ifdef DEBUG
@@ -3896,29 +3897,29 @@ bool WorkerPrivate::RunCurrentSyncLoop()
         // Realm, so it's safe to try to GC.
         MOZ_ASSERT(JS::CurrentGlobalOrNull(cx));
         JS_MaybeGC(cx);
       }
     }
   }
 
   // Make sure that the stack didn't change underneath us.
-  MOZ_ASSERT(mSyncLoopStack[currentLoopIndex] == loopInfo);
+  MOZ_ASSERT(mSyncLoopStack[currentLoopIndex].get() == loopInfo);
 
   return DestroySyncLoop(currentLoopIndex);
 }
 
 bool WorkerPrivate::DestroySyncLoop(uint32_t aLoopIndex) {
   MOZ_ASSERT(!mSyncLoopStack.IsEmpty());
   MOZ_ASSERT(mSyncLoopStack.Length() - 1 == aLoopIndex);
 
   AutoYieldJSThreadExecution yield;
 
   // We're about to delete the loop, stash its event target and result.
-  SyncLoopInfo* loopInfo = mSyncLoopStack[aLoopIndex];
+  const auto& loopInfo = mSyncLoopStack[aLoopIndex];
   nsIEventTarget* nestedEventTarget =
       loopInfo->mEventTarget->GetWeakNestedEventTarget();
   MOZ_ASSERT(nestedEventTarget);
 
   bool result = loopInfo->mResult;
 
   auto queue =
       static_cast<ThreadEventQueue<EventQueue>*>(mThread->EventQueue());
@@ -4037,17 +4038,17 @@ void WorkerPrivate::ReportUseCounters() 
 void WorkerPrivate::StopSyncLoop(nsIEventTarget* aSyncLoopTarget,
                                  bool aResult) {
   AssertIsOnWorkerThread();
   AssertValidSyncLoop(aSyncLoopTarget);
 
   MOZ_ASSERT(!mSyncLoopStack.IsEmpty());
 
   for (uint32_t index = mSyncLoopStack.Length(); index > 0; index--) {
-    nsAutoPtr<SyncLoopInfo>& loopInfo = mSyncLoopStack[index - 1];
+    const auto& loopInfo = mSyncLoopStack[index - 1];
     MOZ_ASSERT(loopInfo);
     MOZ_ASSERT(loopInfo->mEventTarget);
 
     if (loopInfo->mEventTarget == aSyncLoopTarget) {
       // Can't assert |loop->mHasRun| here because dispatch failures can cause
       // us to bail out early.
       MOZ_ASSERT(!loopInfo->mCompleted);
 
@@ -4076,17 +4077,17 @@ void WorkerPrivate::AssertValidSyncLoop(
   MOZ_ASSERT(workerTarget);
 
   bool valid = false;
 
   {
     MutexAutoLock lock(mMutex);
 
     for (uint32_t index = 0; index < mSyncLoopStack.Length(); index++) {
-      nsAutoPtr<SyncLoopInfo>& loopInfo = mSyncLoopStack[index];
+      const auto& loopInfo = mSyncLoopStack[index];
       MOZ_ASSERT(loopInfo);
       MOZ_ASSERT(loopInfo->mEventTarget);
 
       if (loopInfo->mEventTarget == aSyncLoopTarget) {
         valid = true;
         break;
       }
 
@@ -4469,35 +4470,35 @@ int32_t WorkerPrivate::SetTimeout(JSCont
   }
 
   // If the worker is trying to call setTimeout/setInterval and the parent
   // thread has initiated the close process then just silently fail.
   if (currentStatus >= Closing) {
     return timerId;
   }
 
-  nsAutoPtr<TimeoutInfo> newInfo(new TimeoutInfo());
+  auto newInfo = MakeUnique<TimeoutInfo>();
   newInfo->mIsInterval = aIsInterval;
   newInfo->mId = timerId;
 
   if (MOZ_UNLIKELY(timerId == INT32_MAX)) {
     NS_WARNING("Timeout ids overflowed!");
     data->mNextTimeoutId = 1;
   }
 
   newInfo->mHandler = aHandler;
 
   // See if any of the optional arguments were passed.
   aTimeout = std::max(0, aTimeout);
   newInfo->mInterval = TimeDuration::FromMilliseconds(aTimeout);
 
   newInfo->mTargetTime = TimeStamp::Now() + newInfo->mInterval;
 
-  nsAutoPtr<TimeoutInfo>* insertedInfo = data->mTimeouts.InsertElementSorted(
-      newInfo.forget(), GetAutoPtrComparator(data->mTimeouts));
+  const auto& insertedInfo = data->mTimeouts.InsertElementSorted(
+      std::move(newInfo), GetUniquePtrComparator(data->mTimeouts));
 
   LOG(TimeoutsLog(), ("Worker %p has new timeout: delay=%d interval=%s\n", this,
                       aTimeout, aIsInterval ? "yes" : "no"));
 
   // If the timeout we just made is set to fire next then we need to update the
   // timer, unless we're currently running timeouts.
   if (insertedInfo == data->mTimeouts.Elements() &&
       !data->mRunningExpiredTimeouts) {
@@ -4530,17 +4531,17 @@ int32_t WorkerPrivate::SetTimeout(JSCont
 
 void WorkerPrivate::ClearTimeout(int32_t aId) {
   MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
 
   if (!data->mTimeouts.IsEmpty()) {
     NS_ASSERTION(data->mTimerRunning, "Huh?!");
 
     for (uint32_t index = 0; index < data->mTimeouts.Length(); index++) {
-      nsAutoPtr<TimeoutInfo>& info = data->mTimeouts[index];
+      const auto& info = data->mTimeouts[index];
       if (info->mId == aId) {
         info->mCanceled = true;
         break;
       }
     }
   }
 }
 
@@ -4554,33 +4555,32 @@ bool WorkerPrivate::RunExpiredTimeouts(J
     return true;
   }
 
   NS_ASSERTION(data->mTimer && data->mTimerRunnable, "Must have a timer!");
   NS_ASSERTION(!data->mTimeouts.IsEmpty(), "Should have some work to do!");
 
   bool retval = true;
 
-  AutoPtrComparator<TimeoutInfo> comparator =
-      GetAutoPtrComparator(data->mTimeouts);
+  auto comparator = GetUniquePtrComparator(data->mTimeouts);
   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
 
   // We want to make sure to run *something*, even if the timer fired a little
   // early. Fudge the value of now to at least include the first timeout.
   const TimeStamp actual_now = TimeStamp::Now();
   const TimeStamp now = std::max(actual_now, data->mTimeouts[0]->mTargetTime);
 
   if (now != actual_now) {
     LOG(TimeoutsLog(), ("Worker %p fudged timeout by %f ms.\n", this,
                         (now - actual_now).ToMilliseconds()));
   }
 
   AutoTArray<TimeoutInfo*, 10> expiredTimeouts;
   for (uint32_t index = 0; index < data->mTimeouts.Length(); index++) {
-    nsAutoPtr<TimeoutInfo>& info = data->mTimeouts[index];
+    TimeoutInfo* info = data->mTimeouts[index].get();
     if (info->mTargetTime > now) {
       break;
     }
     expiredTimeouts.AppendElement(info);
   }
 
   // Guard against recursion.
   data->mRunningExpiredTimeouts = true;
@@ -4629,17 +4629,17 @@ bool WorkerPrivate::RunExpiredTimeouts(J
   // NB: The timeouts present in expiredTimeouts must have the same order
   // with respect to each other in mTimeouts.  That is, mTimeouts is just
   // expiredTimeouts with extra elements inserted.  There may be unexpired
   // timeouts that have been inserted between the expired timeouts if the
   // timeout event handler called setTimeout/setInterval.
   for (uint32_t index = 0, expiredTimeoutIndex = 0,
                 expiredTimeoutLength = expiredTimeouts.Length();
        index < data->mTimeouts.Length();) {
-    nsAutoPtr<TimeoutInfo>& info = data->mTimeouts[index];
+    const auto& info = data->mTimeouts[index];
     if ((expiredTimeoutIndex < expiredTimeoutLength &&
          info == expiredTimeouts[expiredTimeoutIndex] &&
          ++expiredTimeoutIndex) ||
         info->mCanceled) {
       if (info->mIsInterval && !info->mCanceled) {
         // Reschedule intervals.
         info->mTargetTime = info->mTargetTime + info->mInterval;
         // Don't resort the list here, we'll do that at the end.
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -12,16 +12,17 @@
 #include "mozilla/dom/WorkerStatus.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/MozPromise.h"
 #include "mozilla/RelativeTimeline.h"
 #include "mozilla/StorageAccess.h"
 #include "mozilla/ThreadSafeWeakPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/UseCounter.h"
 #include "nsContentUtils.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIEventTarget.h"
 #include "nsTObserverArray.h"
 
 #include "js/ContextOptions.h"
 #include "mozilla/dom/RemoteWorkerChild.h"
@@ -1095,17 +1096,17 @@ class WorkerPrivate : public RelativeTim
 #ifdef DEBUG
     bool mHasRun;
 #endif
   };
 
   // This is only modified on the worker thread, but in DEBUG builds
   // AssertValidSyncLoop function iterates it on other threads. Therefore
   // modifications are done with mMutex held *only* in DEBUG builds.
-  nsTArray<nsAutoPtr<SyncLoopInfo>> mSyncLoopStack;
+  nsTArray<UniquePtr<SyncLoopInfo>> mSyncLoopStack;
 
   nsCOMPtr<nsITimer> mCancelingTimer;
 
   // fired on the main thread if the worker script fails to load
   nsCOMPtr<nsIRunnable> mLoadFailedRunnable;
 
   RefPtr<PerformanceStorage> mPerformanceStorage;
 
@@ -1149,17 +1150,17 @@ class WorkerPrivate : public RelativeTim
   // Things touched on worker thread only.
   struct WorkerThreadAccessible {
     explicit WorkerThreadAccessible(WorkerPrivate* aParent);
 
     RefPtr<WorkerGlobalScope> mScope;
     RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope;
     nsTArray<WorkerPrivate*> mChildWorkers;
     nsTObserverArray<WorkerRef*> mWorkerRefs;
-    nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts;
+    nsTArray<UniquePtr<TimeoutInfo>> mTimeouts;
 
     nsCOMPtr<nsITimer> mTimer;
     nsCOMPtr<nsITimerCallback> mTimerRunnable;
 
     nsCOMPtr<nsITimer> mGCTimer;
 
     RefPtr<MemoryReporter> mMemoryReporter;
 
--- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp
@@ -330,18 +330,19 @@ nsresult RemoteWorkerChild::ExecWorkerOn
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   WorkerLoadInfo info;
   info.mBaseURI = DeserializeURI(aData.baseScriptURL());
   info.mResolvedScriptURI = DeserializeURI(aData.resolvedScriptURL());
 
-  info.mPrincipalInfo = new PrincipalInfo(aData.principalInfo());
-  info.mStoragePrincipalInfo = new PrincipalInfo(aData.storagePrincipalInfo());
+  info.mPrincipalInfo = MakeUnique<PrincipalInfo>(aData.principalInfo());
+  info.mStoragePrincipalInfo =
+      MakeUnique<PrincipalInfo>(aData.storagePrincipalInfo());
 
   info.mReferrerInfo = aData.referrerInfo();
   info.mDomain = aData.domain();
   info.mPrincipal = principal;
   info.mStoragePrincipal = storagePrincipal;
   info.mLoadingPrincipal = loadingPrincipal;
   info.mStorageAccess = aData.storageAccess();
   info.mOriginAttributes =
@@ -366,18 +367,18 @@ nsresult RemoteWorkerChild::ExecWorkerOn
   if (aData.clientInfo().isSome()) {
     clientInfo.emplace(ClientInfo(aData.clientInfo().ref()));
   }
 
   if (clientInfo.isSome()) {
     Maybe<mozilla::ipc::CSPInfo> cspInfo = clientInfo.ref().GetCspInfo();
     if (cspInfo.isSome()) {
       info.mCSP = CSPInfoToCSP(cspInfo.ref(), nullptr);
-      info.mCSPInfo = new CSPInfo();
-      rv = CSPToCSPInfo(info.mCSP, info.mCSPInfo);
+      info.mCSPInfo = MakeUnique<CSPInfo>();
+      rv = CSPToCSPInfo(info.mCSP, info.mCSPInfo.get());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
   }
 
   rv = info.SetPrincipalsAndCSPOnMainThread(
       info.mPrincipal, info.mStoragePrincipal, info.mLoadGroup, info.mCSP);