mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 07:38:10 +00:00
LibWeb: Implement Element.getAttributeNS
This commit is contained in:
parent
8cf783b260
commit
785fa60cca
5 changed files with 36 additions and 0 deletions
|
@ -0,0 +1,4 @@
|
|||
xlink:ref getAttribute = 'null'
|
||||
xlink:ref getAttributeNS = 'test'
|
||||
href getAttribute = 'test'
|
||||
href getAttributeNS = 'null'
|
16
Tests/LibWeb/Text/input/DOM/Element-getAttributeNS.html
Normal file
16
Tests/LibWeb/Text/input/DOM/Element-getAttributeNS.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<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">
|
||||
test(() => {
|
||||
const xlinkNS = document.getElementById("with-xlink-href");
|
||||
println(`xlink:ref getAttribute = '${xlinkNS.getAttribute("href")}'`);
|
||||
println(`xlink:ref getAttributeNS = '${xlinkNS.getAttributeNS("http://www.w3.org/1999/xlink", "href")}'`);
|
||||
|
||||
const noNS = document.getElementById("no-xlink-href");
|
||||
println(`href getAttribute = '${noNS.getAttribute("href")}'`);
|
||||
println(`href getAttributeNS = '${noNS.getAttributeNS("http://www.w3.org/1999/xlink", "href")}'`);
|
||||
});
|
||||
</script>
|
|
@ -120,6 +120,20 @@ Optional<String> Element::get_attribute(FlyString const& name) const
|
|||
return attribute->value();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattributens
|
||||
Optional<String> Element::get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& name) const
|
||||
{
|
||||
// 1. Let attr be the result of getting an attribute given namespace, localName, and this.
|
||||
auto const* attribute = m_attributes->get_attribute_ns(namespace_, name);
|
||||
|
||||
// 2. If attr is null, return null.
|
||||
if (!attribute)
|
||||
return {};
|
||||
|
||||
// 3. Return attr’s value.
|
||||
return attribute->value();
|
||||
}
|
||||
|
||||
ByteString Element::deprecated_get_attribute(FlyString const& name) const
|
||||
{
|
||||
auto maybe_attribute = get_attribute(name);
|
||||
|
|
|
@ -99,6 +99,7 @@ public:
|
|||
Optional<String> attribute(FlyString const& name) const { return get_attribute(name); }
|
||||
|
||||
Optional<String> get_attribute(FlyString const& name) const;
|
||||
Optional<String> get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& name) const;
|
||||
ByteString deprecated_get_attribute(FlyString const& name) const;
|
||||
String get_attribute_value(FlyString const& local_name, Optional<FlyString> const& namespace_ = {}) const;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ interface Element : Node {
|
|||
readonly attribute DOMString tagName;
|
||||
|
||||
DOMString? getAttribute(DOMString qualifiedName);
|
||||
DOMString? getAttributeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName);
|
||||
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
|
||||
[CEReactions] undefined setAttributeNS([FlyString] DOMString? namespace , [FlyString] DOMString qualifiedName , DOMString value);
|
||||
[CEReactions] Attr? setAttributeNode(Attr attr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue