2021-06-09 16:23:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashTable.h>
|
2024-11-14 15:01:23 +00:00
|
|
|
#include <LibGC/WeakContainer.h>
|
2021-06-09 16:23:04 +00:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2021-06-12 02:23:33 +00:00
|
|
|
class WeakSet final
|
|
|
|
: public Object
|
2024-11-14 15:01:23 +00:00
|
|
|
, public GC::WeakContainer {
|
2021-06-09 16:23:04 +00:00
|
|
|
JS_OBJECT(WeakSet, Object);
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DECLARE_ALLOCATOR(WeakSet);
|
2021-06-09 16:23:04 +00:00
|
|
|
|
|
|
|
public:
|
2024-11-14 15:01:23 +00:00
|
|
|
static GC::Ref<WeakSet> create(Realm&);
|
2021-06-09 16:23:04 +00:00
|
|
|
|
2022-03-14 16:25:06 +00:00
|
|
|
virtual ~WeakSet() override = default;
|
2021-06-09 16:23:04 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
HashTable<GC::Ptr<Cell>> const& values() const { return m_values; }
|
|
|
|
HashTable<GC::Ptr<Cell>>& values() { return m_values; }
|
2021-06-09 17:10:47 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
virtual void remove_dead_cells(Badge<GC::Heap>) override;
|
2021-06-09 16:23:04 +00:00
|
|
|
|
|
|
|
private:
|
2022-08-28 21:51:28 +00:00
|
|
|
explicit WeakSet(Object& prototype);
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
HashTable<GC::RawPtr<Cell>> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
|
2021-06-09 16:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|