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>
|
2024-11-14 15:01:23 +00:00
|
|
|
#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
|
2024-11-14 15:01:23 +00:00
|
|
|
, public GC::WeakContainer {
|
2021-06-12 02:28:30 +00:00
|
|
|
JS_OBJECT(WeakMap, Object);
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DECLARE_ALLOCATOR(WeakMap);
|
2021-06-12 02:28:30 +00:00
|
|
|
|
|
|
|
public:
|
2024-11-14 15:01:23 +00:00
|
|
|
static GC::Ref<WeakMap> create(Realm&);
|
2021-06-12 02:28:30 +00:00
|
|
|
|
2022-03-14 16:25:06 +00:00
|
|
|
virtual ~WeakMap() override = default;
|
2021-06-12 02:28:30 +00:00
|
|
|
|
2024-11-14 15:01:23 +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
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
virtual void remove_dead_cells(Badge<GC::Heap>) override;
|
2021-06-12 02:28:30 +00:00
|
|
|
|
|
|
|
private:
|
2022-08-28 21:51:28 +00:00
|
|
|
explicit WeakMap(Object& prototype);
|
|
|
|
|
2021-09-11 16:19:40 +00:00
|
|
|
void visit_edges(Visitor&) override;
|
2021-09-11 14:44:40 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|