Bug 1605130. Make it harder to misuse OwningNonNull::forget. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D57805

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-12-19 15:38:21 +00:00
Родитель e649934e9f
Коммит 0e01c0c207
1 изменённых файлов: 11 добавлений и 15 удалений

Просмотреть файл

@ -68,21 +68,6 @@ class MOZ_IS_SMARTPTR_TO_REFCOUNTED OwningNonNull {
// Don't allow assigning nullptr, it makes no sense
void operator=(decltype(nullptr)) = delete;
already_AddRefed<T> forget() {
#ifdef DEBUG
mInited = false;
#endif
return mPtr.forget();
}
template <class U>
void forget(U** aOther) {
#ifdef DEBUG
mInited = false;
#endif
mPtr.forget(aOther);
}
T& ref() const {
MOZ_ASSERT(mInited);
MOZ_ASSERT(mPtr, "OwningNonNull<T> was set to null");
@ -112,6 +97,17 @@ class MOZ_IS_SMARTPTR_TO_REFCOUNTED OwningNonNull {
return mPtr;
}
private:
already_AddRefed<T> forget() {
#ifdef DEBUG
mInited = false;
#endif
return mPtr.forget();
}
// Allow ImplCycleCollectionUnlink to call forget().
friend void ImplCycleCollectionUnlink(OwningNonNull<T>& aField);
protected:
template <typename U>
void init(U&& aValue) {