diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-21 19:57:41 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-21 20:17:55 +0200 |
commit | cdc1315dc851b2b1f820eb7fe0dc973c78c71caa (patch) | |
tree | 23c4d52c6fd260d2872c37c2762d7ddd4a1aefbc /Userland/Libraries/LibJS/Runtime/WeakContainer.cpp | |
parent | 3fe1be20b7ec04542947159f996b62c620dd5171 (diff) | |
download | serenity-cdc1315dc851b2b1f820eb7fe0dc973c78c71caa.zip |
LibJS: Use IntrusiveList for keeping track of WeakContainers
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/WeakContainer.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakContainer.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakContainer.cpp b/Userland/Libraries/LibJS/Runtime/WeakContainer.cpp new file mode 100644 index 0000000000..387cbea5cc --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/WeakContainer.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibJS/Heap/Heap.h> +#include <LibJS/Runtime/WeakContainer.h> + +namespace JS { + +WeakContainer::WeakContainer(Heap& heap) + : m_heap(heap) +{ + m_heap.did_create_weak_container({}, *this); +} + +WeakContainer::~WeakContainer() +{ + deregister(); +} + +void WeakContainer::deregister() +{ + if (!m_registered) + return; + m_heap.did_destroy_weak_container({}, *this); + m_registered = false; +} + +} |