diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-12-18 09:03:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-18 08:03:50 +0000 |
commit | 9d986a8ab3cf180e966bed0bc7c20f5f66c6711a (patch) | |
tree | 8976cbbf6275b9fedb76a685f46da7cfa86eadd0 /components/script/dom/htmltableelement.rs | |
parent | d54b68bc96eab9d90b2d9d9f42bde33d33123cfd (diff) | |
download | servo-9d986a8ab3cf180e966bed0bc7c20f5f66c6711a.tar.gz servo-9d986a8ab3cf180e966bed0bc7c20f5f66c6711a.zip |
script: Expose a constructor on `HTMLCollection` that takes a static function (#34667)
Expose a new constructor on `HTMLCollection`, `new_with_filter_fn`, that
filters elements using a simple static function -- a common pattern.
This allows more easily creating this `HTMLCollection` without having to
create a new data structure. Since the constructor takes a static
function, no data should be captured preventing garbage collection
issues.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/htmltableelement.rs')
-rw-r--r-- | components/script/dom/htmltableelement.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index b4b3fceed9d..6699bc5975a 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -300,20 +300,16 @@ impl HTMLTableElementMethods<crate::DomTypeHolder> for HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-tbodies fn TBodies(&self) -> DomRoot<HTMLCollection> { - #[derive(JSTraceable)] - struct TBodiesFilter; - impl CollectionFilter for TBodiesFilter { - fn filter(&self, elem: &Element, root: &Node) -> bool { - elem.is::<HTMLTableSectionElement>() && - elem.local_name() == &local_name!("tbody") && - elem.upcast::<Node>().GetParentNode().as_deref() == Some(root) - } - } - self.tbodies.or_init(|| { - let window = window_from_node(self); - let filter = Box::new(TBodiesFilter); - HTMLCollection::create(&window, self.upcast(), filter) + HTMLCollection::new_with_filter_fn( + &window_from_node(self), + self.upcast(), + |element, root| { + element.is::<HTMLTableSectionElement>() && + element.local_name() == &local_name!("tbody") && + element.upcast::<Node>().GetParentNode().as_deref() == Some(root) + }, + ) }) } |