Truly independent web browser
LibWeb: Use null namespaces in generated attribute reflection
Andreas Klinge7d96898009d
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 59561d2b482..7f634ba0859 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -1299,7 +1299,7 @@ GC::Ptr<DOM::Element> Element::get_the_attribute_associated_element(Utf16FlyStriauto const& element = *this;// 2. Let contentAttributeValue be the result of running reflectedTarget's get the content attribute.- auto content_attribute_value = element.get_attribute(content_attribute);+ auto content_attribute_value = element.get_attribute_ns({}, content_attribute);return DOM::get_the_attribute_associated_element(element, content_attribute_value, explicitly_set_attribute_element);}@@ -1360,7 +1360,7 @@ Optional<GC::RootVector<GC::Ref<DOM::Element>>> Element::get_the_attribute_assocauto const& element = *this;return DOM::get_the_attribute_associated_elements(- element, [&] { return element.get_attribute(content_attribute); }, explicitly_set_attribute_elements);+ element, [&] { return element.get_attribute_ns({}, content_attribute); }, explicitly_set_attribute_elements);}CSS::ElementBoxKind Element::box_kind() constdiff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cppindex 06f0eec6d94..1f0007dc2f7 100644--- a/Libraries/LibWeb/HTML/HTMLElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLElement.cpp@@ -1132,7 +1132,7 @@ void HTMLElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16StMUST(hide_popover(FocusPreviousElement::Yes, FireEvents::Yes, ThrowExceptions::No, IgnoreDomState::Yes, nullptr));}();- if (is_form_associated_element()) {+ if (!namespace_.has_value() && is_form_associated_element()) {form_node_attribute_changed(name, value);form_associated_element_attribute_changed(name, old_value, value, namespace_);if (name == HTML::AttributeNames::disabled) {diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cppindex 954c7a953a1..89337b0b270 100644--- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp@@ -52,6 +52,9 @@ void HTMLIFrameElement::attribute_changed(Utf16FlyString const& name, Optional<U{Base::attribute_changed(name, old_value, value, namespace_);+ if (namespace_.has_value())+ return;+if (name == HTML::AttributeNames::sandbox) {if (m_sandbox)m_sandbox->associated_attribute_changed(value.has_value() ? value->utf16_view() : u""sv);diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cppindex a8320631ecc..c4893c0667d 100644--- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp@@ -56,6 +56,9 @@ void HTMLOptionElement::attribute_changed(Utf16FlyString const& name, Optional<U{Base::attribute_changed(name, old_value, value, namespace_);+ if (namespace_.has_value())+ return;+if (name == HTML::AttributeNames::selected) {if (!value.has_value()) {// Whenever an option element's selected attribute is removed, if its dirtiness is false, its selectedness must be set to false.diff --git a/Meta/Generators/libweb_bindings/attributes.py b/Meta/Generators/libweb_bindings/attributes.pyindex 227e44ddea1..4188fd09dfe 100644--- a/Meta/Generators/libweb_bindings/attributes.py+++ b/Meta/Generators/libweb_bindings/attributes.py@@ -383,7 +383,7 @@ def write_attribute_getter(// If a reflected IDL attribute has the type boolean:// 1. Let contentAttributeValue be the result of running this's get the content attribute.// 2. If contentAttributeValue is null, then return false.- auto R = idl_object->has_attribute(content_attribute);"""+ auto R = idl_object->has_attribute_ns({{}}, content_attribute);"""elif is_non_nullable_reflected and attribute.type.name == "long":includes.add("LibWeb/HTML/Numbers.h")getter_steps = f"""{content_attribute_declaration}@@ -394,7 +394,7 @@ def write_attribute_getter(// 1. Let parsedValue be the result of integer parsing contentAttributeValue.// 2. If parsedValue is not an error and is within the long range, then return parsedValue.i32 R = 0;- auto content_attribute_value = idl_object->get_attribute(content_attribute);+ auto content_attribute_value = idl_object->get_attribute_ns({{}}, content_attribute);if (content_attribute_value.has_value()) {{auto maybe_parsed_value = Web::HTML::parse_integer(*content_attribute_value);if (maybe_parsed_value.has_value())@@ -414,7 +414,7 @@ def write_attribute_getter(// 1. Let parsedValue be the result of non-negative integer parsing contentAttributeValue.// 2. If parsedValue is not an error and is in the range minimum to maximum, inclusive, then return parsedValue.u32 R = 0;- auto content_attribute_value = idl_object->get_attribute(content_attribute);+ auto content_attribute_value = idl_object->get_attribute_ns({{}}, content_attribute);u32 minimum = 0;u32 maximum = 2147483647;if (content_attribute_value.has_value()) {{@@ -432,7 +432,7 @@ def write_attribute_getter(// If a reflected IDL attribute has the type USVString:// 1. Let element be the result of running this's get the element.// 2. Let contentAttributeValue be the result of running this's get the content attribute.- auto content_attribute_value = idl_object->attribute(content_attribute);+ auto content_attribute_value = idl_object->get_attribute_ns({{}}, content_attribute);// 3. Let attributeDefinition be the attribute definition of element's content attribute whose namespace is null and local name is the reflected content attribute name.@@ -447,7 +447,7 @@ def write_attribute_getter(// If a reflected IDL attribute has the type USVString:// 1. Let element be the result of running this's get the element.// 2. Let contentAttributeValue be the result of running this's get the content attribute.- auto content_attribute_value = idl_object->attribute(content_attribute);+ auto content_attribute_value = idl_object->get_attribute_ns({{}}, content_attribute);// 3. Let attributeDefinition be the attribute definition of element's content attribute whose namespace is null and local name is the reflected content attribute name.@@ -478,7 +478,7 @@ def write_attribute_getter(// If a reflected IDL attribute is an enumerated attribute:// 1. Let contentAttributeValue be the result of running this's get the content attribute.- auto R = idl_object->attribute(content_attribute);+ auto R = idl_object->get_attribute_ns({{}}, content_attribute);// 3. If contentAttributeValue is an ASCII case-insensitive match for one of the keywords, then return that keyword's canonical keyword.Array valid_values {{ {valid_values} }};@@ -501,7 +501,7 @@ def write_attribute_getter(// If a reflected IDL attribute is an enumerated attribute:// 1. Let contentAttributeValue be the result of running this's get the content attribute.- auto content_attribute_value = idl_object->attribute(content_attribute);+ auto content_attribute_value = idl_object->get_attribute_ns({{}}, content_attribute);// 2. If contentAttributeValue is null, then set contentAttributeValue to the missing value default.auto R = content_attribute_value.value_or("{missing_value_default}"_utf16);@@ -812,6 +812,13 @@ def write_attribute_setter(static_utf16_fly_string("content_attribute", reflected_attribute_name(attribute)) if is_reflected else "")+ # ElementInternals deletes entries from its internal content attribute map.+ delete_content_attribute = (+ "idl_object->remove_attribute(content_attribute);"+ if interface.name == "ElementInternals"+ else "idl_object->remove_attribute_ns({}, content_attribute);"+ )+def as_utf16_string_expression(value: str) -> str:return value@@ -819,7 +826,7 @@ def write_attribute_setter(setter_steps = f"""{content_attribute_declaration}if (!idl_value)- idl_object->remove_attribute(content_attribute);+ {delete_content_attribute}elseidl_object->set_attribute_value(content_attribute, Utf16String {{}});return {{}};"""@@ -849,7 +856,7 @@ def write_attribute_setter(setter_steps = f"""{content_attribute_declaration}if (!idl_value.has_value())- idl_object->remove_attribute(content_attribute);+ {delete_content_attribute}elseidl_object->set_attribute_value(content_attribute, {as_utf16_string_expression("*idl_value")});return {{}};"""@@ -859,7 +866,7 @@ def write_attribute_setter(if (!idl_value) {{idl_object->set_{idl_implementation_cpp_name(attribute)}({{}});- idl_object->remove_attribute(content_attribute);+ {delete_content_attribute}return {{}};}}@@ -879,7 +886,7 @@ def write_attribute_setter(if (!idl_value.has_value()) {{idl_object->set_{idl_implementation_cpp_name(attribute)}({{}});- idl_object->remove_attribute(content_attribute);+ {delete_content_attribute}return {{}};}}diff --git a/Meta/Generators/libweb_bindings/operations.py b/Meta/Generators/libweb_bindings/operations.pyindex 57cc9463329..21916964fed 100644--- a/Meta/Generators/libweb_bindings/operations.py+++ b/Meta/Generators/libweb_bindings/operations.py@@ -706,9 +706,7 @@ def default_to_json_getter_steps() -> str:is_reflected = "Reflect" in attribute.extended_attributesif is_reflected and attribute.type.name == "boolean":- return (- f'auto {value_name} = idl_object->has_attribute("{reflected_attribute_name(attribute)}"_utf16_fly_string);'- )+ return f'auto {value_name} = idl_object->has_attribute_ns({{}}, "{reflected_attribute_name(attribute)}"_utf16_fly_string);'return f"auto {value_name} = TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return idl_object->{idl_implementation_cpp_name(attribute)}(); }}));"diff --git a/Tests/LibWeb/Text/expected/DOM/reflected-attributes-namespaces.txt b/Tests/LibWeb/Text/expected/DOM/reflected-attributes-namespaces.txtindex be5b36fe5e9..4b831a38ba8 100644--- a/Tests/LibWeb/Text/expected/DOM/reflected-attributes-namespaces.txt+++ b/Tests/LibWeb/Text/expected/DOM/reflected-attributes-namespaces.txt@@ -1,16 +1,16 @@-Foreign boolean (false): false-Boolean setter preserves foreign attribute (false): false-Foreign integer (false): false-Integer setter uses null namespace (false): false-Foreign unsigned integer (false): false-Unsigned setter uses null namespace (false): false-Foreign enumerated reflection (false): false-Nullable setter preserves foreign attribute (false): false-Foreign URL (false): false-URL setter uses null namespace (false): false-Foreign enumerated attribute (false): false-Foreign element reflection (false): false-Foreign selected attribute (false): false+Foreign boolean (false): true+Boolean setter preserves foreign attribute (false): true+Foreign integer (false): true+Integer setter uses null namespace (false): true+Foreign unsigned integer (false): true+Unsigned setter uses null namespace (false): true+Foreign enumerated reflection (false): true+Nullable setter preserves foreign attribute (false): true+Foreign URL (false): true+URL setter uses null namespace (false): true+Foreign enumerated attribute (false): true+Foreign element reflection (false): true+Foreign selected attribute (false): trueForeign boolean (true): trueBoolean setter preserves foreign attribute (true): trueForeign integer (true): true@@ -21,6 +21,6 @@ Foreign enumerated reflection (true): trueNullable setter preserves foreign attribute (true): trueForeign URL (true): trueURL setter uses null namespace (true): true-Foreign enumerated attribute (true): false+Foreign enumerated attribute (true): trueForeign element reflection (true): true-Foreign selected attribute (true): false+Foreign selected attribute (true): truediff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/namespaced-attribute-mutations.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/namespaced-attribute-mutations.txtindex cd7436970cd..da82b4a9ede 100644--- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/namespaced-attribute-mutations.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/namespaced-attribute-mutations.txt@@ -2,8 +2,7 @@ Harness status: OKFound 24 tests-20 Pass-4 Fail+24 PassPass append a namespaced style attribute preserves HTML inline stylePass append a namespaced event handler attribute preserves an HTML event handlerPass change a namespaced style attribute preserves HTML inline style@@ -21,10 +20,10 @@ Pass remove a namespaced event handler attribute preserves an SVG event handlerPass replace a namespaced style attribute preserves SVG inline stylePass replace a namespaced event handler attribute preserves an SVG event handlerPass A namespaced slot attribute does not assign a slot-Fail A namespaced open attribute does not fire a toggle event-Fail A namespaced src attribute does not navigate an iframe+Pass A namespaced open attribute does not fire a toggle event+Pass A namespaced src attribute does not navigate an iframePass A namespaced src attribute does not prepare a script-Fail A namespaced type attribute does not change an input's state-Fail A namespaced selected attribute does not change an option's selectedness+Pass A namespaced type attribute does not change an input's state+Pass A namespaced selected attribute does not change an option's selectednessPass A namespaced multiple attribute does not reset a selectPass A namespaced size attribute does not reset a select\ No newline at end of file