Skip to content

Commit

Permalink
Bug 1611415 - Prefer using std::move over forget. r=froydnj
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D60980

--HG--
extra : moz-landing-system : lando
  • Loading branch information
sigiesec committed Feb 13, 2020
1 parent 9211d26 commit b50347f
Show file tree
Hide file tree
Showing 251 changed files with 512 additions and 500 deletions.
2 changes: 1 addition & 1 deletion accessible/base/nsAccessiblePivot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ bool nsAccessiblePivot::IsDescendantOf(Accessible* aAccessible,
bool nsAccessiblePivot::MovePivotInternal(Accessible* aPosition,
PivotMoveReason aReason,
bool aIsFromUserInput) {
RefPtr<Accessible> oldPosition = mPosition.forget();
RefPtr<Accessible> oldPosition = std::move(mPosition);
mPosition = aPosition;
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
mStartOffset = mEndOffset = -1;
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ bool IPDLParamTraits<dom::BrowsingContext*>::Read(
browsingContext.get()->Release();
}

*aResult = browsingContext.forget();
*aResult = std::move(browsingContext);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ CanonicalBrowsingContext::ChangeFrameRemoteness(const nsAString& aRemoteType,
change->Complete(aContentParent);
},
[change](nsresult aRv) { change->Cancel(aRv); });
return promise.forget();
return promise;
}

already_AddRefed<Promise> CanonicalBrowsingContext::ChangeFrameRemoteness(
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/WindowContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool IPDLParamTraits<dom::WindowContext*>::Read(
windowContext.get()->Release();
}

*aResult = windowContext.forget();
*aResult = std::move(windowContext);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion docshell/base/nsDefaultURIFixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword,
}

nsCOMPtr<nsIURI> temp = DeserializeURI(uri);
info->mPreferredURI = temp.forget();
info->mPreferredURI = std::move(temp);
return NS_OK;
}

Expand Down
6 changes: 3 additions & 3 deletions docshell/base/nsDocShellEditorData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ nsDocShellEditorData::~nsDocShellEditorData() { TearDownEditor(); }

void nsDocShellEditorData::TearDownEditor() {
if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
RefPtr<HTMLEditor> htmlEditor = std::move(mHTMLEditor);
htmlEditor->PreDestroy(false);
}
mEditingSession = nullptr;
Expand All @@ -43,7 +43,7 @@ nsresult nsDocShellEditorData::MakeEditable(bool aInWaitForUriLoad) {
if (mHTMLEditor) {
NS_WARNING("Destroying existing editor on frame");

RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
RefPtr<HTMLEditor> htmlEditor = std::move(mHTMLEditor);
htmlEditor->PreDestroy(false);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ nsresult nsDocShellEditorData::SetHTMLEditor(HTMLEditor* aHTMLEditor) {
}

if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
RefPtr<HTMLEditor> htmlEditor = std::move(mHTMLEditor);
htmlEditor->PreDestroy(false);
MOZ_ASSERT(!mHTMLEditor,
"Nested call of nsDocShellEditorData::SetHTMLEditor() detected");
Expand Down
2 changes: 1 addition & 1 deletion docshell/shistory/MaybeNewPSHEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool IPDLParamTraits<dom::CrossProcessSHEntry*>::Read(
newEntry.mSharedID);
dom::ContentChild::GetSingleton()->BindPSHEntryEndpoint(
std::move(newEntry.mEndpoint), do_AddRef(entry).take());
*aEntry = entry.forget();
*aEntry = std::move(entry);
return true;
});
}
Expand Down
2 changes: 1 addition & 1 deletion docshell/shistory/SHistoryParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ bool SHistoryParent::RecvFindEntryForBFCache(
*aEntry = nullptr;
*aIndex = -1;
} else {
*aEntry = shEntry.forget();
*aEntry = std::move(shEntry);
*aIndex = i;
}

Expand Down
2 changes: 1 addition & 1 deletion docshell/shistory/nsSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ nsresult nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
nsCOMPtr<nsIContentSecurityPolicy> csp = aFrameEntry->GetCsp();
loadState->SetCsp(csp);

aLoadResult.mLoadState = loadState.forget();
aLoadResult.mLoadState = std::move(loadState);

return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/animation/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ void Animation::DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag) {
} else if (!mFinishNotificationTask) {
RefPtr<MicroTaskRunnable> runnable = new AsyncFinishNotification(this);
context->DispatchToMicroTask(do_AddRef(runnable));
mFinishNotificationTask = runnable.forget();
mFinishNotificationTask = std::move(runnable);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/BodyConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
mBodyConsumed = true;

MOZ_ASSERT(mConsumePromise);
RefPtr<Promise> localPromise = mConsumePromise.forget();
RefPtr<Promise> localPromise = std::move(mConsumePromise);

RefPtr<BodyConsumer> self = this;
auto autoReleaseObject =
Expand Down Expand Up @@ -751,7 +751,7 @@ void BodyConsumer::ContinueConsumeBlobBody(BlobImpl* aBlobImpl,
mBodyConsumed = true;

MOZ_ASSERT(mConsumePromise);
RefPtr<Promise> localPromise = mConsumePromise.forget();
RefPtr<Promise> localPromise = std::move(mConsumePromise);

if (!aShuttingDown) {
RefPtr<dom::Blob> blob = dom::Blob::Create(mGlobal, aBlobImpl);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/BodyStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
// Note, this will create a ref-cycle between the holder and the stream.
// The cycle is broken when the stream is closed or the worker begins
// shutting down.
stream->mWorkerRef = workerRef.forget();
stream->mWorkerRef = std::move(workerRef);
}

aRv.MightThrowJSException();
Expand Down
2 changes: 1 addition & 1 deletion dom/base/ChromeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class IdleDispatchRunnable final : public IdleRunnable,
RefPtr<IdleDeadline> idleDeadline =
new IdleDeadline(mParent, mTimedOut, deadline.ToMilliseconds());

RefPtr<IdleRequestCallback> callback(mCallback.forget());
RefPtr<IdleRequestCallback> callback(std::move(mCallback));
MOZ_ASSERT(!mCallback);
callback->Call(*idleDeadline, "ChromeUtils::IdleDispatch handler");
mParent = nullptr;
Expand Down
26 changes: 13 additions & 13 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5987,7 +5987,7 @@ Result<nsCOMPtr<nsIURI>, nsresult> Document::ResolveWithBaseURI(
nsCOMPtr<nsIURI> resolvedURI;
MOZ_TRY(
NS_NewURI(getter_AddRefs(resolvedURI), aURI, nullptr, GetDocBaseURI()));
return std::move(resolvedURI);
return resolvedURI;
}

URLExtraData* Document::DefaultStyleAttrURLData() {
Expand Down Expand Up @@ -8708,7 +8708,7 @@ mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Document::Open(
if (!newBC) {
return nullptr;
}
return WindowProxyHolder(newBC.forget());
return WindowProxyHolder(std::move(newBC));
}

Document* Document::Open(const Optional<nsAString>& /* unused */,
Expand Down Expand Up @@ -8868,7 +8868,7 @@ Document* Document::Open(const Optional<nsAString>& /* unused */,
aError.Throw(rv);
return nullptr;
}
newURI = noFragmentURI.forget();
newURI = std::move(noFragmentURI);
}

// UpdateURLAndHistory might do various member-setting, so make sure we're
Expand Down Expand Up @@ -11696,7 +11696,7 @@ static already_AddRefed<nsPIDOMWindowOuter> FindTopWindowForElement(

// Trying to find the top window (equivalent to window.top).
if (nsCOMPtr<nsPIDOMWindowOuter> top = window->GetInProcessTop()) {
window = top.forget();
window = std::move(top);
}
return window.forget();
}
Expand All @@ -11707,11 +11707,11 @@ static already_AddRefed<nsPIDOMWindowOuter> FindTopWindowForElement(
*/
class nsAutoFocusEvent : public Runnable {
public:
explicit nsAutoFocusEvent(already_AddRefed<Element>&& aElement,
already_AddRefed<nsPIDOMWindowOuter>&& aTopWindow)
explicit nsAutoFocusEvent(nsCOMPtr<Element>&& aElement,
nsCOMPtr<nsPIDOMWindowOuter>&& aTopWindow)
: mozilla::Runnable("nsAutoFocusEvent"),
mElement(aElement),
mTopWindow(aTopWindow) {}
mElement(std::move(aElement)),
mTopWindow(std::move(aTopWindow)) {}

NS_IMETHOD Run() override {
nsCOMPtr<nsPIDOMWindowOuter> currentTopWindow =
Expand Down Expand Up @@ -11784,7 +11784,7 @@ void Document::TriggerAutoFocus() {
}

nsCOMPtr<nsIRunnable> event =
new nsAutoFocusEvent(autoFocusElement.forget(), topWindow.forget());
new nsAutoFocusEvent(std::move(autoFocusElement), topWindow.forget());
nsresult rv = NS_DispatchToCurrentThread(event.forget());
NS_ENSURE_SUCCESS_VOID(rv);
}
Expand Down Expand Up @@ -12876,7 +12876,7 @@ class PendingFullscreenChangeList {
nsCOMPtr<nsIDocShellTreeItem> root;
mRootShellForIteration->GetInProcessRootTreeItem(
getter_AddRefs(root));
mRootShellForIteration = root.forget();
mRootShellForIteration = std::move(root);
}
SkipToNextMatch();
}
Expand Down Expand Up @@ -12911,7 +12911,7 @@ class PendingFullscreenChangeList {
while (docShell && docShell != mRootShellForIteration) {
nsCOMPtr<nsIDocShellTreeItem> parent;
docShell->GetInProcessParent(getter_AddRefs(parent));
docShell = parent.forget();
docShell = std::move(parent);
}
if (docShell) {
break;
Expand Down Expand Up @@ -15690,7 +15690,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
ContentPermissionRequestBase::DelayedTaskType::Request);
});

return p.forget();
return std::move(p);
};
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(
NodePrincipal(), inner, AntiTrackingCommon::eStorageAccessAPI,
Expand Down Expand Up @@ -15986,7 +15986,7 @@ void Document::RecomputeLanguageFromCharset() {
}

mMayNeedFontPrefsUpdate = true;
mLanguageFromCharset = language.forget();
mLanguageFromCharset = std::move(language);
}

nsICookieSettings* Document::CookieSettings() {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/IdleRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void IdleRequest::IdleRun(nsPIDOMWindowInner* aWindow,

RefPtr<IdleDeadline> deadline =
new IdleDeadline(aWindow, aDidTimeout, aDeadline);
RefPtr<IdleRequestCallback> callback(mCallback.forget());
RefPtr<IdleRequestCallback> callback(std::move(mCallback));
MOZ_ASSERT(!mCallback);
callback->Call(*deadline, "requestIdleCallback handler");
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/ImageEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class EncodingCompleteEvent : public CancelableRunnable {
nsresult rv = NS_OK;

// We want to null out mEncodeCompleteCallback no matter what.
RefPtr<EncodeCompleteCallback> callback(mEncodeCompleteCallback.forget());
RefPtr<EncodeCompleteCallback> callback(std::move(mEncodeCompleteCallback));
if (!mFailed) {
RefPtr<BlobImpl> blobImpl = new MemoryBlobImpl(mImgData, mImgSize, mType);
rv = callback->ReceiveBlobImpl(blobImpl.forget());
Expand Down
2 changes: 1 addition & 1 deletion dom/base/PostMessageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ PostMessageEvent::Run() {
// The document URI is just used for the principal mismatch error message
// below. Use a stack variable so mCallerURI is not held onto after
// this method finishes, regardless of the method outcome.
nsCOMPtr<nsIURI> callerURI = mCallerURI.forget();
nsCOMPtr<nsIURI> callerURI = std::move(mCallerURI);

// If we bailed before this point we're going to leak mMessage, but
// that's probably better than crashing.
Expand Down
4 changes: 2 additions & 2 deletions dom/base/ResizeObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ already_AddRefed<ResizeObserver> ResizeObserver::Constructor(
return nullptr;
}

return do_AddRef(new ResizeObserver(window.forget(), doc, aCb));
return do_AddRef(new ResizeObserver(std::move(window), doc, aCb));
}

void ResizeObserver::Observe(Element& aTarget,
Expand Down Expand Up @@ -306,7 +306,7 @@ void ResizeObserverEntry::SetContentRectAndSize(const nsSize& aSize) {
nsRect rect(nsPoint(padding.left, padding.top), aSize);
RefPtr<DOMRect> contentRect = new DOMRect(this);
contentRect->SetLayoutRect(rect);
mContentRect = contentRect.forget();
mContentRect = std::move(contentRect);

// 2. Update mContentBoxSize.
const WritingMode wm = frame ? frame->GetWritingMode() : WritingMode();
Expand Down
6 changes: 3 additions & 3 deletions dom/base/ResizeObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class ResizeObserver final : public nsISupports, public nsWrapperCache {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ResizeObserver)

ResizeObserver(already_AddRefed<nsPIDOMWindowInner>&& aOwner,
Document* aDocument, ResizeObserverCallback& aCb)
: mOwner(aOwner), mDocument(aDocument), mCallback(&aCb) {
ResizeObserver(nsCOMPtr<nsPIDOMWindowInner>&& aOwner, Document* aDocument,
ResizeObserverCallback& aCb)
: mOwner(std::move(aOwner)), mDocument(aDocument), mCallback(&aCb) {
MOZ_ASSERT(mOwner, "Need a non-null owner window");
MOZ_ASSERT(mDocument, "Need a non-null doc");
MOZ_ASSERT(mDocument == mOwner->GetExtantDoc());
Expand Down
2 changes: 1 addition & 1 deletion dom/base/SelectionChangeEventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void SelectionChangeEventDispatcher::OnSelectionChange(Document* aDoc,
root = root->GetParent();
}

target = root.forget();
target = std::move(root);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/WindowNamedPropertiesHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
// global scope is still allowed, since |var| only looks up |own|
// properties. But unqualified shadowing will fail, per-spec.
JS::Rooted<JS::Value> v(aCx);
if (!ToJSValue(aCx, WindowProxyHolder(child.forget()), &v)) {
if (!ToJSValue(aCx, WindowProxyHolder(std::move(child)), &v)) {
return false;
}
FillPropertyDescriptor(aDesc, aProxy, 0, v);
Expand Down
4 changes: 2 additions & 2 deletions dom/base/WindowProxyHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WindowProxyHolder {
explicit WindowProxyHolder(BrowsingContext* aBC) : mBrowsingContext(aBC) {
MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null.");
}
explicit WindowProxyHolder(already_AddRefed<BrowsingContext>&& aBC)
explicit WindowProxyHolder(RefPtr<BrowsingContext>&& aBC)
: mBrowsingContext(std::move(aBC)) {
MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null.");
}
Expand All @@ -42,7 +42,7 @@ class WindowProxyHolder {
MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null.");
return *this;
}
WindowProxyHolder& operator=(already_AddRefed<BrowsingContext>&& aBC) {
WindowProxyHolder& operator=(RefPtr<BrowsingContext>&& aBC) {
mBrowsingContext = std::move(aBC);
MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null.");
return *this;
Expand Down
3 changes: 2 additions & 1 deletion dom/base/nsContentSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ void nsContentSink::DropParserAndPerfHint(void) {
// actually broken.
// Drop our reference to the parser to get rid of a circular
// reference.
RefPtr<nsParserBase> kungFuDeathGrip(mParser.forget());
RefPtr<nsParserBase> kungFuDeathGrip = std::move(mParser);
mozilla::Unused << kungFuDeathGrip;

if (mDynamicLowerValue) {
// Reset the performance hint which was set to FALSE
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMMutationObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ void nsDOMMutationObserver::TakeRecords(
current->mNext.swap(next);
if (!mMergeAttributeRecords ||
!MergeableAttributeRecord(aRetVal.SafeLastElement(nullptr), current)) {
*aRetVal.AppendElement() = current.forget();
*aRetVal.AppendElement() = std::move(current);
}
current.swap(next);
}
Expand Down Expand Up @@ -755,7 +755,7 @@ already_AddRefed<nsDOMMutationObserver> nsDOMMutationObserver::Constructor(
}
bool isChrome = nsContentUtils::IsChromeDoc(window->GetExtantDoc());
RefPtr<nsDOMMutationObserver> observer =
new nsDOMMutationObserver(window.forget(), aCb, isChrome);
new nsDOMMutationObserver(std::move(window), aCb, isChrome);
return observer.forget();
}

Expand Down
Loading

0 comments on commit b50347f

Please sign in to comment.