diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index cbbcf1dfc5e2..1f89d23a3949 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -1441,7 +1441,7 @@ already_AddRefed nsScriptSecurityManager::SystemPrincipalSingletonConstructor() { if (gScriptSecMan) - return do_AddRef(gScriptSecMan->mSystemPrincipal.get()).downcast(); + return do_AddRef(gScriptSecMan->mSystemPrincipal).downcast(); return nullptr; } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index b55a761ae2b4..06e8e97719d0 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2501,7 +2501,7 @@ nsDocument::MaybeDowngradePrincipal(nsIPrincipal* aPrincipal) MOZ_ASSERT(expanded->WhiteList().Length() > 0); - return do_AddRef(expanded->WhiteList().LastElement().get()); + return do_AddRef(expanded->WhiteList().LastElement()); } if (!sChromeInContentPrefCached) { diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index b092e235bfd8..b0ad1b97a564 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -144,7 +144,7 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, RefPtr fm = new nsFontMetrics(aFont, params, mContext); // the mFontMetrics list has the "head" at the end, because append // is cheaper than insert - mFontMetrics.AppendElement(do_AddRef(fm.get()).take()); + mFontMetrics.AppendElement(do_AddRef(fm).take()); return fm.forget(); } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 52395d2a75ec..8371b7b23632 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -12296,7 +12296,7 @@ nsCSSFrameConstructor::CreateListBoxContent(nsContainerFrame* aParentFrame, GetAbsoluteContainingBlock(aParentFrame, FIXED_POS), GetAbsoluteContainingBlock(aParentFrame, ABS_POS), GetFloatContainingBlock(aParentFrame), - do_AddRef(mTempFrameTreeState.get())); + do_AddRef(mTempFrameTreeState)); // If we ever initialize the ancestor filter on |state|, make sure // to push the right parent! diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 8276ee5464f7..63f7be137868 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -3494,7 +3494,7 @@ nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable) if (!mWillPaintFallbackEvent.IsPending()) { mWillPaintFallbackEvent = new RunWillPaintObservers(this); Document()->Dispatch(TaskCategory::Other, - do_AddRef(mWillPaintFallbackEvent.get())); + do_AddRef(mWillPaintFallbackEvent)); } mWillPaintObservers.AppendElement(aRunnable); } diff --git a/netwerk/protocol/res/ExtensionProtocolHandler.cpp b/netwerk/protocol/res/ExtensionProtocolHandler.cpp index cbb04daf07e4..8d13b7135aae 100644 --- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp +++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp @@ -338,7 +338,7 @@ ExtensionProtocolHandler::GetSingleton() sSingleton = new ExtensionProtocolHandler(); ClearOnShutdown(&sSingleton); } - return do_AddRef(sSingleton.get()); + return do_AddRef(sSingleton); } ExtensionProtocolHandler::ExtensionProtocolHandler() diff --git a/toolkit/components/extensions/webrequest/StreamFilterParent.cpp b/toolkit/components/extensions/webrequest/StreamFilterParent.cpp index bef658e905c6..1b7b82a30697 100644 --- a/toolkit/components/extensions/webrequest/StreamFilterParent.cpp +++ b/toolkit/components/extensions/webrequest/StreamFilterParent.cpp @@ -45,7 +45,7 @@ public: already_AddRefed GetEventTarget() override { - return do_AddRef(mTarget.get()); + return do_AddRef(mTarget); } protected: diff --git a/xpcom/base/nsCOMPtr.h b/xpcom/base/nsCOMPtr.h index 8e3e556033d8..d953cda9c3d4 100644 --- a/xpcom/base/nsCOMPtr.h +++ b/xpcom/base/nsCOMPtr.h @@ -1549,4 +1549,12 @@ RefPtr::operator=(const nsCOMPtr_helper& aHelper) return *this; } +template +inline already_AddRefed +do_AddRef(const nsCOMPtr& aObj) +{ + nsCOMPtr ref(aObj); + return ref.forget(); +} + #endif // !defined(nsCOMPtr_h___) diff --git a/xpcom/threads/Scheduler.cpp b/xpcom/threads/Scheduler.cpp index 57f94f5c265b..264f22d4e517 100644 --- a/xpcom/threads/Scheduler.cpp +++ b/xpcom/threads/Scheduler.cpp @@ -327,14 +327,14 @@ already_AddRefed SchedulerEventQueue::GetObserver() { MutexAutoLock lock(mLock); - return do_AddRef(mObserver.get()); + return do_AddRef(mObserver); } already_AddRefed SchedulerEventQueue::GetObserverOnThread() { MOZ_ASSERT(NS_IsMainThread()); - return do_AddRef(mObserver.get()); + return do_AddRef(mObserver); } void diff --git a/xpcom/threads/ThreadEventQueue.cpp b/xpcom/threads/ThreadEventQueue.cpp index 6836d9c70cfc..febb1ae1d49c 100644 --- a/xpcom/threads/ThreadEventQueue.cpp +++ b/xpcom/threads/ThreadEventQueue.cpp @@ -249,14 +249,14 @@ already_AddRefed ThreadEventQueue::GetObserver() { MutexAutoLock lock(mLock); - return do_AddRef(mObserver.get()); + return do_AddRef(mObserver); } template already_AddRefed ThreadEventQueue::GetObserverOnThread() { - return do_AddRef(mObserver.get()); + return do_AddRef(mObserver); } template diff --git a/xpcom/threads/nsThreadUtils.h b/xpcom/threads/nsThreadUtils.h index f3ff827ebf66..c2c72021bd18 100644 --- a/xpcom/threads/nsThreadUtils.h +++ b/xpcom/threads/nsThreadUtils.h @@ -1632,6 +1632,13 @@ private: RefPtr mEvent; }; +template +inline already_AddRefed +do_AddRef(nsRevocableEventPtr& aObj) +{ + return do_AddRef(aObj.get()); +} + /** * A simple helper to suffix thread pool name * with incremental numbers.