Don't register unconnected shadow roots with their owner document (#34361)

* Don't falsely register Shadow Roots as connected

Previously, a shadowroot would be registered as connected
during the shadow hosts bind_to_tree call, even if the host
was being bound to an element that was not itself
connected to a document.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move bind/unbind methods into a VirtualMethod impl

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Add DocumentFragment/Shadowroot to vtable_for

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2024-12-02 19:33:25 +01:00 committed by GitHub
parent 888a93af47
commit f1e89c58a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 161 additions and 27 deletions

View file

@ -5,14 +5,14 @@
use html5ever::LocalName;
use style::attr::AttrValue;
use super::htmltablecolelement::HTMLTableColElement;
use crate::dom::attr::Attr;
use crate::dom::bindings::inheritance::{
Castable, ElementTypeId, HTMLElementTypeId, HTMLMediaElementTypeId, NodeTypeId,
SVGElementTypeId, SVGGraphicsElementTypeId,
Castable, DocumentFragmentTypeId, ElementTypeId, HTMLElementTypeId, HTMLMediaElementTypeId,
NodeTypeId, SVGElementTypeId, SVGGraphicsElementTypeId,
};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::event::Event;
use crate::dom::htmlanchorelement::HTMLAnchorElement;
@ -46,6 +46,7 @@ use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::htmlsourceelement::HTMLSourceElement;
use crate::dom::htmlstyleelement::HTMLStyleElement;
use crate::dom::htmltablecellelement::HTMLTableCellElement;
use crate::dom::htmltablecolelement::HTMLTableColElement;
use crate::dom::htmltableelement::HTMLTableElement;
use crate::dom::htmltablerowelement::HTMLTableRowElement;
use crate::dom::htmltablesectionelement::HTMLTableSectionElement;
@ -54,6 +55,7 @@ use crate::dom::htmltextareaelement::HTMLTextAreaElement;
use crate::dom::htmltitleelement::HTMLTitleElement;
use crate::dom::htmlvideoelement::HTMLVideoElement;
use crate::dom::node::{BindContext, ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
use crate::dom::shadowroot::ShadowRoot;
use crate::dom::svgelement::SVGElement;
use crate::dom::svgsvgelement::SVGSVGElement;
@ -283,6 +285,12 @@ pub fn vtable_for(node: &Node) -> &dyn VirtualMethods {
node.downcast::<Element>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::Element(_) => node.downcast::<HTMLElement>().unwrap() as &dyn VirtualMethods,
NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot) => {
node.downcast::<ShadowRoot>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::DocumentFragment(_) => {
node.downcast::<DocumentFragment>().unwrap() as &dyn VirtualMethods
},
_ => node as &dyn VirtualMethods,
}
}