From d95ae629ee03b99d39930ee5806739622dc8cee6 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Thu, 14 Nov 2024 16:17:41 +0000 Subject: [PATCH] LibIDL: Allow overwriting the generated attribute callback name This will allow the CSSStyleDeclaration IDL attribute generator to implement it's own C++ acceptable identifier sanitization and deduplication. --- Libraries/LibIDL/IDLParser.cpp | 12 ++++++++++-- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Libraries/LibIDL/IDLParser.cpp b/Libraries/LibIDL/IDLParser.cpp index 937b1ed7440..40fea17b6eb 100644 --- a/Libraries/LibIDL/IDLParser.cpp +++ b/Libraries/LibIDL/IDLParser.cpp @@ -326,8 +326,16 @@ void Parser::parse_attribute(HashMap& extended_attribute assert_specific(';'); - auto getter_callback_name = ByteString::formatted("{}_getter", name.to_snakecase()); - auto setter_callback_name = ByteString::formatted("{}_setter", name.to_snakecase()); + ByteString attribute_callback_name; + auto custom_callback_name = extended_attributes.find("AttributeCallbackName"); + if (custom_callback_name != extended_attributes.end()) { + attribute_callback_name = custom_callback_name->value; + } else { + attribute_callback_name = name.to_snakecase().replace("-"sv, "_"sv, ReplaceMode::All); + } + + auto getter_callback_name = ByteString::formatted("{}_getter", attribute_callback_name); + auto setter_callback_name = ByteString::formatted("{}_setter", attribute_callback_name); Attribute attribute { inherit, diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 88c18c4411f..b31fc1d1ee9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2810,14 +2810,15 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const if (attribute.extended_attributes.contains("FIXME")) continue; auto attribute_generator = generator.fork(); - attribute_generator.set("attribute.name:snakecase", attribute.name.to_snakecase()); + attribute_generator.set("attribute.getter_callback", attribute.getter_callback_name); attribute_generator.append(R"~~~( - JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_getter); + JS_DECLARE_NATIVE_FUNCTION(@attribute.getter_callback@); )~~~"); if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv) || attribute.extended_attributes.contains("PutForwards"sv)) { + attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name); attribute_generator.append(R"~~~( - JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_setter); + JS_DECLARE_NATIVE_FUNCTION(@attribute.setter_callback@); )~~~"); } }