LibWeb: Add [CustomVisit] IDL interface extended attribute

This custom attribute will be used for objects that hold onto arbitrary
JS::Value's. This is needed as JS::Handle can only be constructed for
objects that implement JS::Cell, which JS::Value doesn't.

This works by overriding the `visit_edges` function in the wrapper.
This overridden function calls the base `visit_edges` and then forwards
it to the underlying implementation.

This will be used for CustomEvent, which must hold onto an arbitrary
JS::Value for it's entire lifespan.
This commit is contained in:
Luke Wilde 2021-09-27 16:01:19 +01:00 committed by Andreas Kling
parent 8da21583db
commit d30ec4d790
Notes: sideshowbarker 2024-07-18 03:24:07 +09:00

View file

@ -1164,6 +1164,12 @@ public:
)~~~");
}
if (interface.extended_attributes.contains("CustomVisit")) {
generator.append(R"~~~(
virtual void visit_edges(JS::Cell::Visitor&) override;
)~~~");
}
if (interface.is_legacy_platform_object()) {
generator.append(R"~~~(
virtual Optional<JS::PropertyDescriptor> internal_get_own_property(JS::PropertyName const&) const override;
@ -1326,6 +1332,16 @@ void @wrapper_class@::initialize(JS::GlobalObject& global_object)
)~~~");
}
if (interface.extended_attributes.contains("CustomVisit")) {
generator.append(R"~~~(
void @wrapper_class@::visit_edges(JS::Cell::Visitor& visitor)
{
@wrapper_base_class@::visit_edges(visitor);
impl().visit_edges(visitor);
}
)~~~");
}
if (interface.is_legacy_platform_object()) {
auto scoped_generator = generator.fork();
scoped_generator.set("class_name", interface.wrapper_class);