mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibJS: Make Handle<T> more user-friendly
Allow *handle, !handle, handle.ptr(), assignment from compatible pointer types, etc. This is in preparation for using Handles in more generated code.
This commit is contained in:
parent
01828edd37
commit
63cc2650e3
Notes:
sideshowbarker
2024-07-17 07:32:48 +09:00
Author: https://github.com/awesomekling
Commit: 63cc2650e3
2 changed files with 66 additions and 6 deletions
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include <LibJS/Heap/Cell.h>
|
#include <LibJS/Heap/Cell.h>
|
||||||
#include <LibJS/Heap/Handle.h>
|
#include <LibJS/Heap/Handle.h>
|
||||||
#include <LibJS/Heap/Heap.h>
|
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
|
@ -50,13 +50,74 @@ public:
|
||||||
return Handle(adopt_ref(*new HandleImpl(cell)));
|
return Handle(adopt_ref(*new HandleImpl(cell)));
|
||||||
}
|
}
|
||||||
|
|
||||||
T* cell() { return static_cast<T*>(m_impl->cell()); }
|
Handle(T* cell)
|
||||||
const T* cell() const { return static_cast<const T*>(m_impl->cell()); }
|
{
|
||||||
|
if (cell)
|
||||||
|
m_impl = adopt_ref(*new HandleImpl(cell));
|
||||||
|
}
|
||||||
|
|
||||||
bool is_null() const { return m_impl.is_null(); }
|
Handle(T& cell)
|
||||||
|
: m_impl(adopt_ref(*new HandleImpl(&cell)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
T* operator->() { return cell(); }
|
T* cell()
|
||||||
T const* operator->() const { return cell(); }
|
{
|
||||||
|
if (!m_impl)
|
||||||
|
return nullptr;
|
||||||
|
return static_cast<T*>(m_impl->cell());
|
||||||
|
}
|
||||||
|
|
||||||
|
T const* cell() const
|
||||||
|
{
|
||||||
|
if (!m_impl)
|
||||||
|
return nullptr;
|
||||||
|
return static_cast<T const*>(m_impl->cell());
|
||||||
|
}
|
||||||
|
|
||||||
|
T* ptr()
|
||||||
|
{
|
||||||
|
return cell();
|
||||||
|
}
|
||||||
|
T const* ptr() const
|
||||||
|
{
|
||||||
|
return cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_null() const
|
||||||
|
{
|
||||||
|
return m_impl.is_null();
|
||||||
|
}
|
||||||
|
|
||||||
|
T* operator->()
|
||||||
|
{
|
||||||
|
return cell();
|
||||||
|
}
|
||||||
|
T const* operator->() const
|
||||||
|
{
|
||||||
|
return cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator*()
|
||||||
|
{
|
||||||
|
return *cell();
|
||||||
|
}
|
||||||
|
T const& operator*() const
|
||||||
|
{
|
||||||
|
return *cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!() const
|
||||||
|
{
|
||||||
|
return !cell();
|
||||||
|
}
|
||||||
|
operator bool() const
|
||||||
|
{
|
||||||
|
return cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T*() { return cell(); }
|
||||||
|
operator T const*() const { return cell(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Handle(NonnullRefPtr<HandleImpl> impl)
|
explicit Handle(NonnullRefPtr<HandleImpl> impl)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue