ladybird/Libraries/LibJS/Runtime/WeakMap.h

41 lines
947 B
C
Raw Normal View History

2021-06-12 02:28:30 +00:00
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <LibGC/WeakContainer.h>
2021-06-12 02:28:30 +00:00
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
namespace JS {
class WeakMap final
: public Object
, public GC::WeakContainer {
2021-06-12 02:28:30 +00:00
JS_OBJECT(WeakMap, Object);
GC_DECLARE_ALLOCATOR(WeakMap);
2021-06-12 02:28:30 +00:00
public:
static GC::Ref<WeakMap> create(Realm&);
2021-06-12 02:28:30 +00:00
virtual ~WeakMap() override = default;
2021-06-12 02:28:30 +00:00
HashMap<GC::Ptr<Cell>, Value> const& values() const { return m_values; }
HashMap<GC::Ptr<Cell>, Value>& values() { return m_values; }
2021-06-12 02:28:30 +00:00
virtual void remove_dead_cells(Badge<GC::Heap>) override;
2021-06-12 02:28:30 +00:00
private:
explicit WeakMap(Object& prototype);
void visit_edges(Visitor&) override;
HashMap<GC::Ptr<Cell>, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
2021-06-12 02:28:30 +00:00
};
}