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