mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 14:57:34 +00:00
LibJS: Generify the garbage collector's weak container notifications
This will allow us to use the same interface for other JS weak containers like the WeakMap & WeakRef.
This commit is contained in:
parent
06fdc26656
commit
1a8ee5d8d7
6 changed files with 51 additions and 17 deletions
31
Userland/Libraries/LibJS/Runtime/WeakContainer.h
Normal file
31
Userland/Libraries/LibJS/Runtime/WeakContainer.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class WeakContainer {
|
||||
public:
|
||||
explicit WeakContainer(Heap& heap)
|
||||
: m_heap(heap)
|
||||
{
|
||||
m_heap.did_create_weak_container({}, *this);
|
||||
}
|
||||
virtual ~WeakContainer()
|
||||
{
|
||||
m_heap.did_destroy_weak_container({}, *this);
|
||||
}
|
||||
|
||||
virtual void remove_sweeped_cells(Badge<Heap>, Vector<Cell*>&) = 0;
|
||||
|
||||
private:
|
||||
Heap& m_heap;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue