LibJS: Explictly assert that a null GCPtr is not dereferenced

This commit is contained in:
Timothy Flynn 2022-12-13 18:39:25 -05:00 committed by Linus Groh
parent 8379b87d4e
commit 0ec433edce
Notes: sideshowbarker 2024-07-17 03:18:59 +09:00

View File

@ -52,6 +52,7 @@ public:
NonnullGCPtr& operator=(GCPtr<T> const& other)
{
m_ptr = const_cast<T*>(other.ptr());
VERIFY(m_ptr);
return *this;
}
@ -186,8 +187,18 @@ public:
return *this;
}
T* operator->() const { return m_ptr; }
T& operator*() const { return *m_ptr; }
T* operator->() const
{
VERIFY(m_ptr);
return m_ptr;
}
T& operator*() const
{
VERIFY(m_ptr);
return *m_ptr;
}
T* ptr() const { return m_ptr; }
operator bool() const { return !!m_ptr; }