/src/serenity/Userland/Libraries/LibJS/Runtime/WeakSet.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/HashTable.h> |
10 | | #include <LibJS/Runtime/GlobalObject.h> |
11 | | #include <LibJS/Runtime/Object.h> |
12 | | #include <LibJS/Runtime/WeakContainer.h> |
13 | | |
14 | | namespace JS { |
15 | | |
16 | | class WeakSet final |
17 | | : public Object |
18 | | , public WeakContainer { |
19 | | JS_OBJECT(WeakSet, Object); |
20 | | JS_DECLARE_ALLOCATOR(WeakSet); |
21 | | |
22 | | public: |
23 | | static NonnullGCPtr<WeakSet> create(Realm&); |
24 | | |
25 | 0 | virtual ~WeakSet() override = default; |
26 | | |
27 | 0 | HashTable<GCPtr<Cell>> const& values() const { return m_values; } |
28 | 0 | HashTable<GCPtr<Cell>>& values() { return m_values; } |
29 | | |
30 | | virtual void remove_dead_cells(Badge<Heap>) override; |
31 | | |
32 | | private: |
33 | | explicit WeakSet(Object& prototype); |
34 | | |
35 | | HashTable<RawGCPtr<Cell>> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping |
36 | | }; |
37 | | |
38 | | } |