script: Implement Element::GetHTML and ShadowRoot::GetHTML (#36106)

* Serialize html fragments without going through html5ever

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

* Implement ShadowRoot::GetHtml / Element::GetHtml

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

* Update WPT expectations

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

* Propagate CanGc annotations

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 2025-03-23 20:04:23 +01:00 committed by GitHub
parent 1c9f486f88
commit 19d5f5f06f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 286 additions and 15941 deletions

View file

@ -7,6 +7,7 @@ use std::collections::HashMap;
use std::collections::hash_map::Entry;
use dom_struct::dom_struct;
use html5ever::serialize::TraversalScope;
use servo_arc::Arc;
use style::author_styles::AuthorStyles;
use style::dom::TElement;
@ -17,6 +18,7 @@ use stylo_atoms::Atom;
use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::ElementBinding::GetHTMLOptions;
use crate::dom::bindings::codegen::Bindings::HTMLSlotElementBinding::HTMLSlotElement_Binding::HTMLSlotElementMethods;
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRoot_Binding::ShadowRootMethods;
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{
@ -405,11 +407,24 @@ impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
})
}
/// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-gethtml>
fn GetHTML(&self, options: &GetHTMLOptions, can_gc: CanGc) -> DOMString {
// > ShadowRoot's getHTML(options) method steps are to return the result of HTML fragment serialization
// > algorithm with this, options["serializableShadowRoots"], and options["shadowRoots"].
self.upcast::<Node>().html_serialize(
TraversalScope::ChildrenOnly(None),
options.serializableShadowRoots,
options.shadowRoots.clone(),
can_gc,
)
}
/// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-innerhtml>
fn InnerHTML(&self) -> DOMString {
fn InnerHTML(&self, can_gc: CanGc) -> DOMString {
// ShadowRoot's innerHTML getter steps are to return the result of running fragment serializing
// algorithm steps with this and true.
self.upcast::<Node>().fragment_serialization_algorithm(true)
self.upcast::<Node>()
.fragment_serialization_algorithm(true, can_gc)
}
/// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-innerhtml>