Bug 1299515 - Make `const nsMainThreadPtrHandle<T>` usable. r?erahm
This enables having a const nsMainThreadPtrHandle<T> member which we want to
ensure doesn't get assigned to, but whose (the `T`'s) non-const methods are
still usable on main thread. Similar to how RefPtr<T> works.
MozReview-Commit-ID: 8CG0MwIZmLc
--- a/xpcom/threads/nsProxyRelease.h
+++ b/xpcom/threads/nsProxyRelease.h
@@ -365,33 +365,26 @@ public:
{
mPtr = aHolder;
return *this;
}
// These all call through to nsMainThreadPtrHolder, and thus implicitly
// assert that we're on the main thread. Off-main-thread consumers must treat
// these handles as opaque.
- T* get()
- {
- if (mPtr) {
- return mPtr.get()->get();
- }
- return nullptr;
- }
- const T* get() const
+ T* get() const
{
if (mPtr) {
return mPtr.get()->get();
}
return nullptr;
}
- operator T*() { return get(); }
- T* operator->() MOZ_NO_ADDREF_RELEASE_ON_RETURN { return get(); }
+ operator T*() const { return get(); }
+ T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN { return get(); }
// These are safe to call on other threads with appropriate external locking.
bool operator==(const nsMainThreadPtrHandle<T>& aOther) const
{
if (!mPtr || !aOther.mPtr) {
return mPtr == aOther.mPtr;
}
return *mPtr == *aOther.mPtr;