diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
index bbbdde381c..7d29ab0e8f 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
@@ -2450,9 +2450,22 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
if (attribute.extended_attributes.contains("Reflect")) {
if (attribute.type->name() != "boolean") {
- attribute_generator.append(R"~~~(
+ if (interface_in_chain.extended_attributes.contains("UseDeprecatedAKString")) {
+ attribute_generator.append(R"~~~(
auto @attribute.return_value_name@ = impl->deprecated_attribute(HTML::AttributeNames::@attribute.reflect_name@);
)~~~");
+ } else {
+ // 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@);
+)~~~");
+ } 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@);
@@ -2776,9 +2789,22 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.getter_callback@)
if (attribute.extended_attributes.contains("Reflect")) {
if (attribute.type->name() != "boolean") {
- attribute_generator.append(R"~~~(
+ if (interface.extended_attributes.contains("UseDeprecatedAKString")) {
+ attribute_generator.append(R"~~~(
auto retval = impl->deprecated_attribute(HTML::AttributeNames::@attribute.reflect_name@);
)~~~");
+ } else {
+ // 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@);
+)~~~");
+ } 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@);
diff --git a/Tests/LibWeb/Text/expected/idl-handling-of-null-attribute.txt b/Tests/LibWeb/Text/expected/idl-handling-of-null-attribute.txt
new file mode 100644
index 0000000000..82700290a8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/idl-handling-of-null-attribute.txt
@@ -0,0 +1,2 @@
+initial type = ''
+after setting to null = 'null'
diff --git a/Tests/LibWeb/Text/input/idl-handling-of-null-attribute.html b/Tests/LibWeb/Text/input/idl-handling-of-null-attribute.html
new file mode 100644
index 0000000000..8a1d3d3eaa
--- /dev/null
+++ b/Tests/LibWeb/Text/input/idl-handling-of-null-attribute.html
@@ -0,0 +1,9 @@
+
+