diff --git a/Libraries/LibWeb/DOM/Attr.cpp b/Libraries/LibWeb/DOM/Attr.cpp index 8f6fbdcdabe..2010c6f7e67 100644 --- a/Libraries/LibWeb/DOM/Attr.cpp +++ b/Libraries/LibWeb/DOM/Attr.cpp @@ -70,42 +70,35 @@ void Attr::set_owner_element(Element* owner_element) m_owner_element = owner_element; } -// FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 -// https://whatpr.org/dom/1268.html#set-an-existing-attribute-value +// https://dom.spec.whatwg.org/#set-an-existing-attribute-value WebIDL::ExceptionOr Attr::set_value(String value) { - // 1. If attribute’s element is null, then set attribute’s value to value. + // 1. If attribute’s element is null, then set attribute’s value to value and return. if (!owner_element()) { m_value = move(value); + return {}; } - // 2. Otherwise: - else { - // 1. Let element be attribute’s element. - auto const* element = owner_element(); - // 2. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with - // attribute’s local name, attribute’s namespace, element, and value. - auto const verified_value = TRY(TrustedTypes::get_trusted_types_compliant_attribute_value( - local_name(), - namespace_uri().has_value() ? Utf16String::from_utf8(namespace_uri().value()) : Optional(), - *element, - Utf16String::from_utf8(value))); + // 2. Let element be attribute’s element. + auto const& element = *owner_element(); - // 3. If attribute’s element is null, then set attribute’s value to verifiedValue, and return. - if (!owner_element()) { - m_value = verified_value.to_utf8_but_should_be_ported_to_utf16(); - return {}; - } + // 3. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with + // attribute’s local name, attribute’s namespace, element, and value. + auto const verified_value = TRY(TrustedTypes::get_trusted_types_compliant_attribute_value( + local_name(), + namespace_uri().has_value() ? Utf16String::from_utf8(namespace_uri().value()) : Optional(), + element, + Utf16String::from_utf8(value))); - // 4. If attribute’s element is not element, then return. - if (owner_element() != element) { - return {}; - } - - // 5. Change attribute to verifiedValue. - change_attribute(verified_value.to_utf8_but_should_be_ported_to_utf16()); + // 4. If attribute’s element is null, then set attribute’s value to verifiedValue, and return. + if (!owner_element()) { + m_value = verified_value.to_utf8_but_should_be_ported_to_utf16(); + return {}; } + // 5. Change attribute to verifiedValue. + change_attribute(verified_value.to_utf8_but_should_be_ported_to_utf16()); + return {}; } diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 57568a6f0c0..bbb4fd4e38a 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -210,8 +210,7 @@ GC::Ptr Element::get_attribute_node_ns(Optional const& namespac return m_attributes->get_attribute_ns(namespace_, name); } -// FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 -// https://whatpr.org/dom/1268.html#dom-element-setattribute +// https://dom.spec.whatwg.org/#dom-element-setattribute WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) { // 1. If qualifiedName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException. @@ -230,23 +229,23 @@ WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualifie // 4. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise. auto* attribute = attributes()->get_attribute(qualified_name); - // 5. If attribute is null, create an attribute whose local name is qualifiedName, value is verifiedValue, and node document - // is this’s node document, then append this attribute to this, and then return. - if (!attribute) { - auto new_attribute = Attr::create(document(), qualified_name, verified_value.to_utf8_but_should_be_ported_to_utf16()); - m_attributes->append_attribute(new_attribute); - + // 5. If attribute is non-null, then change attribute to verifiedValue and return. + if (attribute) { + attribute->change_attribute(verified_value.to_utf8_but_should_be_ported_to_utf16()); return {}; } - // 6. Change attribute to verifiedValue. - attribute->change_attribute(verified_value.to_utf8_but_should_be_ported_to_utf16()); + // 6. Set attribute to a new attribute whose local name is qualifiedName, value is verifiedValue, + // and node document is this’s node document. + attribute = Attr::create(document(), qualified_name, verified_value.to_utf8_but_should_be_ported_to_utf16()); + + // 7. Append attribute to this. + m_attributes->append_attribute(*attribute); return {}; } -// FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 -// https://whatpr.org/dom/1268.html#dom-element-setattribute +// https://dom.spec.whatwg.org/#dom-element-setattribute WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value) { return set_attribute_for_bindings(move(qualified_name), @@ -365,8 +364,7 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option return QualifiedName { local_name, prefix, namespace_ }; } -// FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 -// https://whatpr.org/dom/1268.html#dom-element-setattributens +// https://dom.spec.whatwg.org/#dom-element-setattributens WebIDL::ExceptionOr Element::set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) { // 1. Let (namespace, prefix, localName) be the result of validating and extracting namespace and qualifiedName given "element". @@ -378,9 +376,7 @@ WebIDL::ExceptionOr Element::set_attribute_ns_for_bindings(Optional(), *this, - value.visit( - [](auto const& trusted_type) -> Variant, GC::Root, GC::Root, Utf16String> { return trusted_type; }, - [](String const& string) -> Variant, GC::Root, GC::Root, Utf16String> { return Utf16String::from_utf8(string); }))); + value)); // 3. Set an attribute value for this using localName, verifiedValue, and also prefix and namespace. set_attribute_value(extracted_qualified_name.local_name(), verified_value.to_utf8_but_should_be_ported_to_utf16(), extracted_qualified_name.prefix(), extracted_qualified_name.namespace_()); diff --git a/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Libraries/LibWeb/DOM/NamedNodeMap.cpp index bef2f9cf0a7..df7f6591e20 100644 --- a/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -195,8 +195,7 @@ Attr const* NamedNodeMap::get_attribute_ns(Optional const& namespace_ return nullptr; } -// FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 -// https://whatpr.org/dom/1268.html#concept-element-attributes-set +// https://dom.spec.whatwg.org/#concept-element-attributes-set WebIDL::ExceptionOr> NamedNodeMap::set_attribute(Attr& attribute) { // 1. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value