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.
This commit is contained in:
Shannon Booth 2023-12-27 13:37:32 +13:00 committed by Andreas Kling
parent 462f97b28a
commit 1f9942fede
Notes: sideshowbarker 2024-07-16 18:03:21 +09:00

View file

@ -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@);