diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-24 13:23:47 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-24 13:23:47 +0200 |
commit | 8f31331e685db26a85b01cf3d0d12c7939b2370a (patch) | |
tree | 1531aa4bddf2e95d7f49357d150d75569a77122f /Libraries/LibWeb | |
parent | cb35a8ea8397d96ac9760153446fe2759037c5b9 (diff) | |
download | serenity-8f31331e685db26a85b01cf3d0d12c7939b2370a.zip |
LibWeb: Allow specifying a custom attribute name for [Reflect]
Sometimes the IDL attribute and the DOM attribute don't have the same
exact name. In those cases, we can now do this:
[Reflect=foobar] attribute DOMString fooBar;
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 4e5da81a23..f414c0e85a 100644 --- a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -50,6 +50,17 @@ static String snake_name(const StringView& title_name) return builder.to_string(); } +static String add_underscore_to_cpp_keywords(const String& input) +{ + if (input == "class" || input == "template") { + StringBuilder builder; + builder.append(input); + builder.append('_'); + return builder.to_string(); + } + return input; +} + namespace IDL { struct Type { @@ -598,7 +609,11 @@ void generate_implementation(const IDL::Interface& interface) out() << " return {};"; if (attribute.extended_attributes.contains("Reflect")) { - out() << " auto retval = impl->attribute(HTML::AttributeNames::" << attribute.name << ");"; + auto attribute_name = attribute.extended_attributes.get("Reflect").value(); + if (attribute_name.is_null()) + attribute_name = attribute.name; + attribute_name = add_underscore_to_cpp_keywords(attribute_name); + out() << " auto retval = impl->attribute(HTML::AttributeNames::" << attribute_name << ");"; } else { out() << " auto retval = impl->" << snake_name(attribute.name) << "();"; } @@ -616,7 +631,11 @@ void generate_implementation(const IDL::Interface& interface) generate_to_cpp(attribute, "value", "", "cpp_value", true); if (attribute.extended_attributes.contains("Reflect")) { - out() << " impl->set_attribute(HTML::AttributeNames::" << attribute.name << ", cpp_value);"; + auto attribute_name = attribute.extended_attributes.get("Reflect").value(); + if (attribute_name.is_null()) + attribute_name = attribute.name; + attribute_name = add_underscore_to_cpp_keywords(attribute_name); + out() << " impl->set_attribute(HTML::AttributeNames::" << attribute_name << ", cpp_value);"; } else { out() << " impl->set_" << snake_name(attribute.name) << "(cpp_value);"; } |