diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-09 20:10:47 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-09 21:52:25 +0100 |
commit | a00d154522eeed0b2976827be5dd91500e5a45cf (patch) | |
tree | 08f3fdc376dda75c9a83a4a082e8b31f769472c5 /Userland/Libraries/LibJS/Runtime | |
parent | fb63aeae4d7c2b18833837cc54509f6627792af9 (diff) | |
download | serenity-a00d154522eeed0b2976827be5dd91500e5a45cf.zip |
LibJS: Notify WeakSets when heap cells are sweeped
This is an implementation of the following optional optimization:
https://tc39.es/ecma262/#sec-weakref-execution
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakSet.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakSet.h | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp index 50bf41c0ba..ff64c0858d 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp @@ -16,10 +16,18 @@ WeakSet* WeakSet::create(GlobalObject& global_object) WeakSet::WeakSet(Object& prototype) : Object(prototype) { + heap().did_create_weak_set({}, *this); } WeakSet::~WeakSet() { + heap().did_destroy_weak_set({}, *this); +} + +void WeakSet::remove_sweeped_cells(Badge<Heap>, Vector<Cell*>& cells) +{ + for (auto* cell : cells) + m_values.remove(cell); } } diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.h b/Userland/Libraries/LibJS/Runtime/WeakSet.h index f8c06ad017..0062d4eef4 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.h +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.h @@ -21,11 +21,13 @@ public: explicit WeakSet(Object& prototype); virtual ~WeakSet() override; - HashTable<Object*> const& values() const { return m_values; }; - HashTable<Object*>& values() { return m_values; }; + HashTable<Cell*> const& values() const { return m_values; }; + HashTable<Cell*>& values() { return m_values; }; + + void remove_sweeped_cells(Badge<Heap>, Vector<Cell*>&); private: - HashTable<Object*> m_values; + HashTable<Cell*> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping }; } |