summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/WeakContainer.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-21 19:57:41 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-21 20:17:55 +0200
commitcdc1315dc851b2b1f820eb7fe0dc973c78c71caa (patch)
tree23c4d52c6fd260d2872c37c2762d7ddd4a1aefbc /Userland/Libraries/LibJS/Runtime/WeakContainer.cpp
parent3fe1be20b7ec04542947159f996b62c620dd5171 (diff)
downloadserenity-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.cpp31
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;
+}
+
+}