1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:37:34 +00:00

LibWeb: Handle attribute changes after actually changing the attribute

This is a normative change in the DOM spec. See:
3fb0aa6
This commit is contained in:
Timothy Flynn 2023-09-02 10:54:56 -04:00 committed by Tim Flynn
parent 2d97dd019e
commit 9aae50a9c3

View file

@ -223,32 +223,33 @@ WebIDL::ExceptionOr<JS::GCPtr<Attr>> NamedNodeMap::set_attribute(Attr& attribute
// https://dom.spec.whatwg.org/#concept-element-attributes-replace
void NamedNodeMap::replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index)
{
// 1. Handle attribute changes for oldAttr with oldAttrs element, oldAttrs value, and newAttrs value.
VERIFY(old_attribute.owner_element());
old_attribute.handle_attribute_changes(*old_attribute.owner_element(), old_attribute.value(), new_attribute.value());
// 2. Replace oldAttr by newAttr in oldAttrs elements attribute list.
// 1. Replace oldAttr by newAttr in oldAttrs elements attribute list.
m_attributes.remove(old_attribute_index);
m_attributes.insert(old_attribute_index, new_attribute);
// 3. Set newAttrs element to oldAttrs element.
// 2. Set newAttrs element to oldAttrs element.
new_attribute.set_owner_element(old_attribute.owner_element());
// 4 .Set oldAttrs element to null.
// 3. Set oldAttrs element to null.
old_attribute.set_owner_element(nullptr);
// 4. Handle attribute changes for oldAttr with newAttrs element, oldAttrs value, and newAttrs value.
old_attribute.handle_attribute_changes(*new_attribute.owner_element(), old_attribute.value(), new_attribute.value());
}
// https://dom.spec.whatwg.org/#concept-element-attributes-append
void NamedNodeMap::append_attribute(Attr& attribute)
{
// 1. Handle attribute changes for attribute with element, null, and attributes value.
attribute.handle_attribute_changes(associated_element(), {}, attribute.value());
// 2. Append attribute to elements attribute list.
// 1. Append attribute to elements attribute list.
m_attributes.append(attribute);
// 3. Set attributes element to element.
// 2. Set attributes element to element.
attribute.set_owner_element(&associated_element());
// 3. Handle attribute changes for attribute with element, null, and attributes value.
attribute.handle_attribute_changes(associated_element(), {}, attribute.value());
}
// https://dom.spec.whatwg.org/#concept-element-attributes-remove
@ -256,15 +257,18 @@ void NamedNodeMap::remove_attribute_at_index(size_t attribute_index)
{
JS::NonnullGCPtr<Attr> attribute = m_attributes.at(attribute_index);
// 1. Handle attribute changes for attribute with attributes element, attributes value, and null.
VERIFY(attribute->owner_element());
attribute->handle_attribute_changes(*attribute->owner_element(), attribute->value(), {});
// 1. Let element be attributes element.
auto* element = attribute->owner_element();
VERIFY(element);
// 2. Remove attribute from attributes elements attribute list.
// 2. Remove attribute from elements attribute list.
m_attributes.remove(attribute_index);
// 3. Set attributes element to null.
attribute->set_owner_element(nullptr);
// 4. Handle attribute changes for attribute with element, attributes value, and null.
attribute->handle_attribute_changes(*element, attribute->value(), {});
}
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-name