Browse Source

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.
Luke Wilde 3 years ago
parent
commit
d30ec4d790
1 changed files with 16 additions and 0 deletions
  1. 16 0
      Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp

+ 16 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp

@@ -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);