mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 01:32:14 -05:00
LibWeb: Only return HTML elements from getElementsByName()
Fixes two WPT tests: document.getElementsByName-namespace-xhtml.xhtml and document.getElementsByName-namespace.html
This commit is contained in:
parent
d5fd29adb7
commit
917a2a3c86
Notes:
github-actions[bot]
2024-10-14 16:00:15 +00:00
Author: https://github.com/ronak69 Commit: https://github.com/LadybirdBrowser/ladybird/commit/917a2a3c862 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1791
3 changed files with 25 additions and 2 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
1 == 1
|
||||||
|
P == P
|
||||||
|
1 == 1
|
||||||
|
P == P
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<p name="math"><math name="math">
|
||||||
|
<mi>a</mi>
|
||||||
|
<mo>+</mo>
|
||||||
|
<mi>b</mi>
|
||||||
|
</math>
|
||||||
|
<p name="svg"><svg width="300" height="100" name="svg">
|
||||||
|
<rect width="300" height="100" fill="rgb(0,0,255)"/>
|
||||||
|
</svg>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
println(`${document.getElementsByName("math").length} == 1`);
|
||||||
|
println(`${document.getElementsByName("math")[0].tagName} == P`);
|
||||||
|
println(`${document.getElementsByName("svg").length} == 1`);
|
||||||
|
println(`${document.getElementsByName("svg")[0].tagName} == P`);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1488,12 +1488,13 @@ void Document::set_hovered_node(Node* node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-getelementsbyname
|
||||||
JS::NonnullGCPtr<NodeList> Document::get_elements_by_name(FlyString const& name)
|
JS::NonnullGCPtr<NodeList> Document::get_elements_by_name(FlyString const& name)
|
||||||
{
|
{
|
||||||
return LiveNodeList::create(realm(), *this, LiveNodeList::Scope::Descendants, [name](auto const& node) {
|
return LiveNodeList::create(realm(), *this, LiveNodeList::Scope::Descendants, [name](auto const& node) {
|
||||||
if (!is<Element>(node))
|
if (!is<HTML::HTMLElement>(node))
|
||||||
return false;
|
return false;
|
||||||
return verify_cast<Element>(node).name() == name;
|
return verify_cast<HTML::HTMLElement>(node).name() == name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue