Skip to content

Commit

Permalink
Bug 1463299: Add RefPtr::forget special case for ambiguous nsISupport…
Browse files Browse the repository at this point in the history
…s casts. r=bz

When we use RefPtr with nsISupports sub-classes, it's usually because the type
cannot be unambiguously cast to nsISupports. We already have a ToSupports
generic function to resolve ambiguity in these cases, so we may as well use
it here.

MozReview-Commit-ID: FaHhPKAPn6j

--HG--
extra : rebase_source : dd8f3707bdebedfe559aed0caf2c3b0c49163735
extra : histedit_source : 9805787a169329b9c739dfa456cfe6a61a22b7d7
  • Loading branch information
kmaglione committed May 22, 2018
1 parent 8340513 commit d92e63a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mfbt/RefPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class nsQueryReferent;
class nsCOMPtr_helper;
class nsISupports;

namespace mozilla {
template<class T> class OwningNonNull;
Expand Down Expand Up @@ -277,6 +278,14 @@ class MOZ_IS_REFPTR RefPtr
mRawPtr = nullptr;
}

void
forget(nsISupports** aRhs)
{
MOZ_ASSERT(aRhs, "Null pointer passed to forget!");
*aRhs = ToSupports(mRawPtr);
mRawPtr = nullptr;
}

T*
get() const
/*
Expand Down
3 changes: 2 additions & 1 deletion widget/nsBaseFilePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
return NS_OK;
}

*aResult = ToSupports(File::CreateFromFile(aWindow, aFile).take());
RefPtr<File> file = File::CreateFromFile(aWindow, aFile);
file.forget(aResult);
return NS_OK;
}

Expand Down

0 comments on commit d92e63a

Please sign in to comment.