Make traverse_preorder follow shadow roots (#34503)

* script: Ensure shadow-inclusve preorder traversals follow hosted shadow roots.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Handle unregistering element id/name values inside of a shadow root.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Merge shadow root tree iteration logic.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-12-06 23:28:34 -05:00 committed by GitHub
parent ad48ab7ec3
commit 4242ff9626
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 20733 additions and 123 deletions

View file

@ -1744,9 +1744,14 @@ impl Iterator for TreeIterator {
fn next(&mut self) -> Option<DomRoot<Node>> {
let current = self.current.take()?;
if !self.shadow_including {
if let Some(element) = current.downcast::<Element>() {
if element.is_shadow_host() {
// Handle a potential shadow root on the element
if let Some(element) = current.downcast::<Element>() {
if let Some(shadow_root) = element.shadow_root() {
if self.shadow_including {
self.current = Some(DomRoot::from_ref(shadow_root.upcast::<Node>()));
self.depth += 1;
return Some(current);
} else {
return self.next_skipping_children_impl(current);
}
}