LibWeb: Implement Element.hasAttributeNS

Particularly needed by xkcd's Right Click comic. https://xkcd.com/1975/
This commit is contained in:
Luke Wilde 2023-08-09 21:31:35 +01:00 committed by Tim Flynn
commit 5694981352
Notes: sideshowbarker 2024-07-16 23:13:25 +09:00
3 changed files with 13 additions and 0 deletions

View file

@ -234,6 +234,17 @@ bool Element::has_attribute(DeprecatedFlyString const& name) const
return m_attributes->get_attribute(name) != nullptr;
}
// https://dom.spec.whatwg.org/#dom-element-hasattributens
bool Element::has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const
{
// 1. If namespace is the empty string, then set it to null.
if (namespace_.is_empty())
namespace_ = {};
// 2. Return true if this has an attribute whose namespace is namespace and local name is localName; otherwise false.
return m_attributes->get_attribute_ns(namespace_, name) != nullptr;
}
// https://dom.spec.whatwg.org/#dom-element-toggleattribute
WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force)
{