ladybird/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h
Linus Groh e5753443ae LibJS: Consistently make prototype the last argument in Object ctors
This is so that we can reliably allocate them in a template function,
e.g. in ordinary_create_from_constructor():

    global_object.heap().allocate<T>(
        global_object, forward<Args>(args)..., *prototype);

The majority of objects already take the prototype as the last argument,
so I updated the ones that didn't.
2021-06-20 12:12:39 +02:00

48 lines
1.2 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/Function.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&, Function&);
explicit FinalizationRegistry(Function&, 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(Function* callback = nullptr);
virtual void remove_sweeped_cells(Badge<Heap>, Vector<Cell*>&) override;
private:
virtual void visit_edges(Visitor& visitor) override;
Function* m_cleanup_callback { nullptr };
struct FinalizationRecord {
Cell* target { nullptr };
Value held_value;
Object* unregister_token { nullptr };
};
SinglyLinkedList<FinalizationRecord> m_records;
};
}