script: Implement trusted types for DOMParser.parseFromString (#38872)

Part of #36258

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe 2025-08-27 08:10:16 +02:00 committed by GitHub
parent 4e85353472
commit d94929dbed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 25 deletions

View file

@ -165,12 +165,18 @@ impl ServoParser {
self.can_write()
}
/// <https://html.spec.whatwg.org/multipage/#parse-html-from-a-string>
pub(crate) fn parse_html_document(
document: &Document,
input: Option<DOMString>,
url: ServoUrl,
can_gc: CanGc,
) {
// Step 1. Set document's type to "html".
//
// Set by callers of this function and asserted here
assert!(document.is_html_document());
// Step 2. Create an HTML parser parser, associated with document.
let parser = if pref!(dom_servoparser_async_html_tokenizer_enabled) {
ServoParser::new(
document,
@ -191,7 +197,10 @@ impl ServoParser {
can_gc,
)
};
// Step 3. Place html into the input stream for parser. The encoding confidence is irrelevant.
// Step 4. Start parser and let it run until it has consumed all the
// characters just inserted into the input stream.
//
// Set as the document's current parser and initialize with `input`, if given.
if let Some(input) = input {
parser.parse_complete_string_chunk(String::from(input), can_gc);