Skip to content

Commit

Permalink
LibWeb: Return a NodeList from document.getElementsByName()
Browse files Browse the repository at this point in the history
This aligns our implementation with the specification.
  • Loading branch information
tcl3 authored and awesomekling committed Jul 23, 2024
1 parent e40352b commit bd1213d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/LiveNodeList.h>
#include <LibWeb/DOM/NodeIterator.h>
#include <LibWeb/DOM/ProcessingInstruction.h>
#include <LibWeb/DOM/Range.h>
Expand Down Expand Up @@ -1394,10 +1395,12 @@ void Document::set_hovered_node(Node* node)
}
}

JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(FlyString const& name)
JS::NonnullGCPtr<NodeList> Document::get_elements_by_name(FlyString const& name)
{
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [name](Element const& element) {
return element.name() == name;
return LiveNodeList::create(realm(), *this, LiveNodeList::Scope::Descendants, [name](auto const& node) {
if (!is<Element>(node))
return false;
return verify_cast<Element>(node).name() == name;
});
}

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Document
void schedule_style_update();
void schedule_layout_update();

JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(FlyString const&);
JS::NonnullGCPtr<NodeList> get_elements_by_name(FlyString const&);

JS::NonnullGCPtr<HTMLCollection> applets();
JS::NonnullGCPtr<HTMLCollection> anchors();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Document.idl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface Document : Node {
readonly attribute Element? activeElement;

Element? getElementById(DOMString id);
HTMLCollection getElementsByName([FlyString] DOMString name);
NodeList getElementsByName([FlyString] DOMString name);
HTMLCollection getElementsByTagName([FlyString] DOMString tagName);
HTMLCollection getElementsByTagNameNS([FlyString] DOMString? namespace, [FlyString] DOMString localName);
HTMLCollection getElementsByClassName(DOMString className);
Expand Down

0 comments on commit bd1213d

Please sign in to comment.