AK: Make WeakPtr<T>::value() return NonnullRefPtr<T>

This API is only used by Jakt to implement weak reference unwrapping.
By making it return a NonnullRefPtr, it can be assigned to anything
that accepts a NonnullRefPtr, unlike the previous T* return type (since
that can also be null).
This commit is contained in:
Andreas Kling 2023-02-04 18:34:35 +01:00
parent 675713ad8e
commit ed3420dc10

View file

@ -149,8 +149,11 @@ public:
return nullptr;
}
[[nodiscard]] T const* value() const { return unsafe_ptr(); }
[[nodiscard]] T* value() { return unsafe_ptr(); }
[[nodiscard]] NonnullRefPtr<T> value() const
{
VERIFY(has_value());
return *unsafe_ptr();
}
operator bool() const { return m_link ? !m_link->is_null() : false; }