1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-17 19:32:06 +00:00
serenity/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h
davidot 8da6c01d8f LibJS: Remove the JS_TRACK_ZOMBIE_CELLS option
This feature had bitrotted somewhat and would trigger errors because
PrimitiveStrings were "destroyed" but because of this mode they were not
removed from the string cache. Even fixing that case running test-js
with the options still failed in more places.
2022-02-05 11:52:51 +01:00

48 lines
1.3 KiB
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/SinglyLinkedList.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/WeakContainer.h>
namespace JS {
class FinalizationRegistry final
: public Object
, public WeakContainer {
JS_OBJECT(FinalizationRegistry, Object);
public:
static FinalizationRegistry* create(GlobalObject&, FunctionObject&);
explicit FinalizationRegistry(FunctionObject&, Object& prototype);
virtual ~FinalizationRegistry() override;
void add_finalization_record(Cell& target, Value held_value, Object* unregister_token);
bool remove_by_token(Object& unregister_token);
void cleanup(FunctionObject* callback = nullptr);
virtual void remove_dead_cells(Badge<Heap>) override;
private:
virtual void visit_edges(Visitor& visitor) override;
FunctionObject* m_cleanup_callback { nullptr };
struct FinalizationRecord {
Cell* target { nullptr };
Value held_value;
Object* unregister_token { nullptr };
};
SinglyLinkedList<FinalizationRecord> m_records;
};
}