mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Update Dom spec now that TrustedTypes integration is merged
This commit is contained in:
parent
42284f8006
commit
6a95506bb1
Notes:
github-actions[bot]
2025-12-01 08:55:35 +00:00
Author: https://github.com/tete17
Commit: 6a95506bb1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6630
Reviewed-by: https://github.com/gmta ✅
3 changed files with 33 additions and 45 deletions
|
|
@ -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<void> 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<Utf16String>(),
|
||||
*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<Utf16String>(),
|
||||
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 {};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -210,8 +210,7 @@ GC::Ptr<Attr> Element::get_attribute_node_ns(Optional<FlyString> 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<void> Element::set_attribute_for_bindings(FlyString qualified_name, Variant<GC::Root<TrustedTypes::TrustedHTML>, GC::Root<TrustedTypes::TrustedScript>, GC::Root<TrustedTypes::TrustedScriptURL>, Utf16String> const& value)
|
||||
{
|
||||
// 1. If qualifiedName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException.
|
||||
|
|
@ -230,23 +229,23 @@ WebIDL::ExceptionOr<void> 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<void> Element::set_attribute_for_bindings(FlyString qualified_name, Variant<GC::Root<TrustedTypes::TrustedHTML>, GC::Root<TrustedTypes::TrustedScript>, GC::Root<TrustedTypes::TrustedScriptURL>, String> const& value)
|
||||
{
|
||||
return set_attribute_for_bindings(move(qualified_name),
|
||||
|
|
@ -365,8 +364,7 @@ WebIDL::ExceptionOr<QualifiedName> 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<void> Element::set_attribute_ns_for_bindings(Optional<FlyString> const& namespace_, FlyString const& qualified_name, Variant<GC::Root<TrustedTypes::TrustedHTML>, GC::Root<TrustedTypes::TrustedScript>, GC::Root<TrustedTypes::TrustedScriptURL>, 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<void> Element::set_attribute_ns_for_bindings(Optional<FlyStr
|
|||
extracted_qualified_name.local_name(),
|
||||
extracted_qualified_name.namespace_().has_value() ? Utf16String::from_utf8(extracted_qualified_name.namespace_().value()) : Optional<Utf16String>(),
|
||||
*this,
|
||||
value.visit(
|
||||
[](auto const& trusted_type) -> Variant<GC::Root<TrustedTypes::TrustedHTML>, GC::Root<TrustedTypes::TrustedScript>, GC::Root<TrustedTypes::TrustedScriptURL>, Utf16String> { return trusted_type; },
|
||||
[](String const& string) -> Variant<GC::Root<TrustedTypes::TrustedHTML>, GC::Root<TrustedTypes::TrustedScript>, GC::Root<TrustedTypes::TrustedScriptURL>, 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_());
|
||||
|
|
|
|||
|
|
@ -195,8 +195,7 @@ Attr const* NamedNodeMap::get_attribute_ns(Optional<FlyString> 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<GC::Ptr<Attr>> NamedNodeMap::set_attribute(Attr& attribute)
|
||||
{
|
||||
// 1. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue