diff --git a/Libraries/LibJS/Bytecode/Executable.cpp b/Libraries/LibJS/Bytecode/Executable.cpp index 094c9d9edc8..c0110a3735b 100644 --- a/Libraries/LibJS/Bytecode/Executable.cpp +++ b/Libraries/LibJS/Bytecode/Executable.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include diff --git a/Libraries/LibJS/Heap/Handle.h b/Libraries/LibJS/Heap/Handle.h index b9d579cf8d6..2b95c3370a2 100644 --- a/Libraries/LibJS/Heap/Handle.h +++ b/Libraries/LibJS/Heap/Handle.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace JS { @@ -149,47 +149,6 @@ inline Handle make_handle(NonnullGCPtr cell, SourceLocation location = Sou return Handle::create(cell.ptr(), location); } -template<> -class Handle { -public: - Handle() = default; - - static Handle create(Value value, SourceLocation location) - { - if (value.is_cell()) - return Handle(value, &value.as_cell(), location); - 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() && !m_value.has_value(); } - - bool operator==(Value const& value) const { return value == m_value; } - bool operator==(Handle const& other) const { return other.m_value == this->m_value; } - -private: - explicit Handle(Value value) - : m_value(value) - { - } - - explicit Handle(Value value, Cell* cell, SourceLocation location) - : m_value(value) - , m_handle(Handle::create(cell, location)) - { - } - - Optional m_value; - Handle m_handle; -}; - -inline Handle make_handle(Value value, SourceLocation location = SourceLocation::current()) -{ - return Handle::create(value, location); -} - } namespace AK { @@ -199,11 +158,6 @@ struct Traits> : public DefaultTraits> { static unsigned hash(JS::Handle const& handle) { return Traits::hash(handle); } }; -template<> -struct Traits> : public DefaultTraits> { - static unsigned hash(JS::Handle const& handle) { return Traits::hash(handle.value()); } -}; - namespace Detail { template inline constexpr bool IsHashCompatible, T> = true; diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index 11e0fa6ff12..288f46a2685 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -15,10 +15,12 @@ #include #include #include +#include #include #include #include #include +#include #include namespace JS { @@ -725,6 +727,55 @@ private: JS::Value m_value; }; +} + +namespace JS { + +template<> +class Handle { +public: + Handle() = default; + + static Handle create(Value value, SourceLocation location) + { + if (value.is_cell()) + return Handle(value, &value.as_cell(), location); + 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() && !m_value.has_value(); } + + bool operator==(Value const& value) const { return value == m_value; } + bool operator==(Handle const& other) const { return other.m_value == this->m_value; } + +private: + explicit Handle(Value value) + : m_value(value) + { + } + + explicit Handle(Value value, Cell* cell, SourceLocation location) + : m_value(value) + , m_handle(Handle::create(cell, location)) + { + } + + Optional m_value; + Handle m_handle; +}; + +inline Handle make_handle(Value value, SourceLocation location = SourceLocation::current()) +{ + return Handle::create(value, location); +} + +} + +namespace AK { + template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, JS::Value value) @@ -741,4 +792,9 @@ struct Traits : DefaultTraits { static constexpr bool is_trivial() { return true; } }; +template<> +struct Traits> : public DefaultTraits> { + static unsigned hash(JS::Handle const& handle) { return Traits::hash(handle.value()); } +}; + }