LibJS: Make MarkedValueList copyable and move assignable

This is required to store a MarkedValueList as the value of a HashMap.
This commit is contained in:
Luke Wilde 2022-01-03 20:26:38 +00:00 committed by Linus Groh
parent c97244d3a5
commit 4a14455dff
Notes: sideshowbarker 2024-07-17 21:38:00 +09:00
3 changed files with 29 additions and 16 deletions

View File

@ -24,7 +24,7 @@ struct ExecutionContext {
[[nodiscard]] ExecutionContext copy() const
{
ExecutionContext copy { arguments.copy() };
ExecutionContext copy { arguments };
copy.function = function;
copy.realm = realm;

View File

@ -10,21 +10,42 @@
namespace JS {
MarkedValueList::MarkedValueList(Heap& heap)
: m_heap(heap)
: m_heap(&heap)
{
m_heap.did_create_marked_value_list({}, *this);
m_heap->did_create_marked_value_list({}, *this);
}
MarkedValueList::MarkedValueList(MarkedValueList const& other)
: Vector<Value, 32>(other)
, m_heap(other.m_heap)
{
m_heap->did_create_marked_value_list({}, *this);
}
MarkedValueList::MarkedValueList(MarkedValueList&& other)
: Vector<Value, 32>(move(static_cast<Vector<Value, 32>&>(other)))
, m_heap(other.m_heap)
{
m_heap.did_create_marked_value_list({}, *this);
m_heap->did_create_marked_value_list({}, *this);
}
MarkedValueList::~MarkedValueList()
{
m_heap.did_destroy_marked_value_list({}, *this);
m_heap->did_destroy_marked_value_list({}, *this);
}
MarkedValueList& MarkedValueList::operator=(JS::MarkedValueList const& other)
{
Vector<Value, 32>::operator=(other);
if (m_heap != other.m_heap) {
m_heap = other.m_heap;
// NOTE: IntrusiveList will remove this MarkedValueList from the old heap it was part of.
m_heap->did_create_marked_value_list({}, *this);
}
return *this;
}
}

View File

@ -15,26 +15,18 @@
namespace JS {
class MarkedValueList : public Vector<Value, 32> {
AK_MAKE_NONCOPYABLE(MarkedValueList);
public:
explicit MarkedValueList(Heap&);
MarkedValueList(MarkedValueList const&);
MarkedValueList(MarkedValueList&&);
~MarkedValueList();
MarkedValueList& operator=(MarkedValueList&&) = delete;
Vector<Value, 32>& values() { return *this; }
MarkedValueList copy() const
{
MarkedValueList copy { m_heap };
copy.extend(*this);
return copy;
}
MarkedValueList& operator=(JS::MarkedValueList const& other);
private:
Heap& m_heap;
Heap* m_heap;
IntrusiveListNode<MarkedValueList> m_list_node;