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

LibWeb: Implement Element.getAttributeNodeNS

This commit is contained in:
Shannon Booth 2024-01-14 18:04:18 +13:00 committed by Andrew Kaster
parent a7316d3641
commit 7a26a889cb
5 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,4 @@
xlink:href getAttributeNode = 'null'
xlink:href getAttributeNodeNS = 'Attr': name = xlink:href value = test
href getAttributeNode = 'Attr': name = href value = test
href getAttributeNodeNS = 'null'

View file

@ -0,0 +1,23 @@
<script src="../include.js"></script>
<svg xmlns="http://www.w3.org/2000/svg">
<script id="with-xlink-href" xlink:href="test"></script>
<script id="no-xlink-href" href="test"></script>
</svg>
<script id="svg-script-element">
function dumpAttr(description, attr) {
if (attr === null) {
println(`${description} = 'null'`);
return;
}
println(`${description} = '${attr.constructor.name}': name = ${attr.name} value = ${attr.value}`);
}
test(() => {
const xlinkNS = document.getElementById("with-xlink-href");
dumpAttr('xlink:href getAttributeNode', xlinkNS.getAttributeNode("href"));
dumpAttr('xlink:href getAttributeNodeNS', xlinkNS.getAttributeNodeNS("http://www.w3.org/1999/xlink", "href"));
const noNS = document.getElementById("no-xlink-href");
dumpAttr('href getAttributeNode', noNS.getAttributeNode("href"));
dumpAttr('href getAttributeNodeNS', noNS.getAttributeNodeNS("http://www.w3.org/1999/xlink", "href"));
});
</script>

View file

@ -164,6 +164,13 @@ JS::GCPtr<Attr> Element::get_attribute_node(FlyString const& name) const
return m_attributes->get_attribute(name);
}
// https://dom.spec.whatwg.org/#dom-element-getattributenodens
JS::GCPtr<Attr> Element::get_attribute_node_ns(Optional<FlyString> const& namespace_, FlyString const& name) const
{
// The getAttributeNodeNS(namespace, localName) method steps are to return the result of getting an attribute given namespace, localName, and this.
return m_attributes->get_attribute_ns(namespace_, name);
}
// https://dom.spec.whatwg.org/#dom-element-setattribute
WebIDL::ExceptionOr<void> Element::set_attribute(FlyString const& name, String const& value)
{

View file

@ -119,6 +119,7 @@ public:
Vector<String> get_attribute_names() const;
JS::GCPtr<Attr> get_attribute_node(FlyString const& name) const;
JS::GCPtr<Attr> get_attribute_node_ns(Optional<FlyString> const& namespace_, FlyString const& name) const;
DOMTokenList* class_list();

View file

@ -43,7 +43,8 @@ interface Element : Node {
[SameObject] readonly attribute NamedNodeMap attributes;
sequence<DOMString> getAttributeNames();
Attr? getAttributeNode(DOMString qualifiedName);
Attr? getAttributeNode([FlyString] DOMString qualifiedName);
Attr? getAttributeNodeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName);
HTMLCollection getElementsByTagName(DOMString tagName);
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);