From 0d515dea5d318b56a39525129689e4c89e9f8bc6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Mar 2021 11:16:06 +0100 Subject: [PATCH] LibWeb: Allow specifying a custom C++ implementation for IDL attributes The "ImplementedAs" extended attribute can now be specified on IDL attributes to provide the name of a custom C++ implementation instead of assuming it will have the same name as the attribute. --- .../Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 8db678edd1..0b7b167d9f 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -1300,6 +1300,13 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name); attribute_generator.set("attribute.name:snakecase", attribute.name.to_snakecase()); + if (attribute.extended_attributes.contains("ImplementedAs")) { + auto implemented_as = attribute.extended_attributes.get("ImplementedAs").value(); + attribute_generator.set("attribute.cpp_getter_name", implemented_as); + } else { + attribute_generator.set("attribute.cpp_getter_name", attribute.name.to_snakecase()); + } + if (attribute.extended_attributes.contains("Reflect")) { auto attribute_name = attribute.extended_attributes.get("Reflect").value(); if (attribute_name.is_null()) @@ -1338,7 +1345,7 @@ JS_DEFINE_NATIVE_GETTER(@prototype_class@::@attribute.getter_callback@) } } else { attribute_generator.append(R"~~~( - auto retval = impl->@attribute.name:snakecase@(); + auto retval = impl->@attribute.cpp_getter_name@(); )~~~"); }