Kaynağa Gözat

LibWeb: Add a custom extended attribute for namespace-level GC visitors

Currently, the WebAssemblyObject implements a visitor to keep its static
objects alive. This custom attribute will be used to hook the generated
namespace object's visitor to one that we define in non-generated code.
Timothy Flynn 2 yıl önce
ebeveyn
işleme
2cd7159694

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

@@ -2706,6 +2706,12 @@ public:
 private:
 )~~~");
 
+    if (interface.extended_attributes.contains("WithGCVistor"sv)) {
+        generator.append(R"~~~(
+    virtual void visit_edges(JS::Cell::Visitor&) 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()));
@@ -2818,6 +2824,16 @@ JS::ThrowCompletionOr<void> @namespace_class@::initialize(JS::Realm& realm)
 }
 )~~~");
 
+    if (interface.extended_attributes.contains("WithGCVistor"sv)) {
+        generator.append(R"~~~(
+void @namespace_class@::visit_edges(JS::Cell::Visitor& visitor)
+{
+    Base::visit_edges(visitor);
+    @name@::visit_edges(visitor);
+}
+)~~~");
+    }
+
     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) {