From 1f9942fede81d70ebb93628dbdf5bbf0e7bc1d33 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 27 Dec 2023 13:37:32 +1300 Subject: [PATCH] BindingsGenerator: Use `get_attribute_value` for reflected strings Per: https://dom.spec.whatwg.org/#concept-reflect We should be calling `get_attribute_value` for reflected IDL strings. No functional change as nowhere is performing a reflect on a nullable type, and just ends up simplifying the code. --- .../BindingsGenerator/IDLGenerators.cpp | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index dc1e0a5d4d..a3f62d1df5 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2445,16 +2445,9 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu if (attribute.extended_attributes.contains("Reflect")) { if (attribute.type->name() != "boolean") { - // FIXME: This should be calling Element::get_attribute_value: https://dom.spec.whatwg.org/#concept-element-attributes-get-value - if (attribute.type->is_nullable()) { - attribute_generator.append(R"~~~( - auto @attribute.return_value_name@ = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@); + attribute_generator.append(R"~~~( + auto @attribute.return_value_name@ = impl->get_attribute_value(HTML::AttributeNames::@attribute.reflect_name@); )~~~"); - } else { - attribute_generator.append(R"~~~( - auto @attribute.return_value_name@ = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@).value_or(String {}); -)~~~"); - } } else { attribute_generator.append(R"~~~( auto @attribute.return_value_name@ = impl->has_attribute(HTML::AttributeNames::@attribute.reflect_name@); @@ -3044,16 +3037,9 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.getter_callback@) // FIXME: 7. If contentAttributeValue corresponds to a state of attributeDefinition with no associated keyword value, then return null. } } else if (attribute.type->name() != "boolean") { - // FIXME: This should be calling Element::get_attribute_value: https://dom.spec.whatwg.org/#concept-element-attributes-get-value - if (attribute.type->is_nullable()) { - attribute_generator.append(R"~~~( - auto retval = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@); + attribute_generator.append(R"~~~( + auto retval = impl->get_attribute_value(HTML::AttributeNames::@attribute.reflect_name@); )~~~"); - } else { - attribute_generator.append(R"~~~( - auto retval = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@).value_or(String {}); -)~~~"); - } } else { attribute_generator.append(R"~~~( auto retval = impl->has_attribute(HTML::AttributeNames::@attribute.reflect_name@);