diff --git a/Userland/Libraries/LibJS/Heap/Handle.h b/Userland/Libraries/LibJS/Heap/Handle.h index 5df24c7d03..e68b1d59f1 100644 --- a/Userland/Libraries/LibJS/Heap/Handle.h +++ b/Userland/Libraries/LibJS/Heap/Handle.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace JS { @@ -77,4 +78,42 @@ inline Handle make_handle(T& cell) return Handle::create(&cell); } +template<> +class Handle { +public: + Handle() = default; + + static Handle create(Value value) + { + if (value.is_cell()) + return Handle(value, &value.as_cell()); + return Handle(value); + } + + auto cell() { return m_handle.cell(); } + auto cell() const { return m_handle.cell(); } + auto value() const { return m_value; } + bool is_null() const { return m_handle.is_null(); } + +private: + explicit Handle(Value value) + : m_value(value) + { + } + + explicit Handle(Value value, Cell* cell) + : m_value(value) + , m_handle(Handle::create(cell)) + { + } + + Value m_value; + Handle m_handle; +}; + +inline Handle make_handle(Value value) +{ + return Handle::create(value); +} + }