LibWeb: Add a custom extended attribute for namespace-level finalization

This change adds the `WithFinalizer` extended attribute, which allows
namespaces to call a custom function at the point they are finalized.
This commit is contained in:
Tim Ledbetter 2024-04-25 19:09:34 +01:00 committed by Ali Mohammad Pur
parent 6d4b8bde55
commit ddd1ac1e36

View file

@ -3703,6 +3703,12 @@ private:
)~~~");
}
if (interface.extended_attributes.contains("WithFinalizer"sv)) {
generator.append(R"~~~(
virtual void finalize() override;
)~~~");
}
for (auto const& overload_set : interface.overload_sets) {
auto function_generator = generator.fork();
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
@ -3835,6 +3841,15 @@ void @namespace_class@::visit_edges(JS::Cell::Visitor& visitor)
)~~~");
}
if (interface.extended_attributes.contains("WithFinalizer"sv)) {
generator.append(R"~~~(
void @namespace_class@::finalize()
{
@name@::finalize(*this);
}
)~~~");
}
for (auto const& function : interface.functions)
generate_function(generator, function, StaticFunction::Yes, interface.namespace_class, interface.name, interface);
for (auto const& overload_set : interface.overload_sets) {