Support HTML parser reentrancy (#32820)

* Update parser interface for reentrancy.

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

* Remove assertions around invoking scripts with active parser.

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

* Add regression test.

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

* Run test with normal and async html parser.

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

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-08-16 12:25:50 -04:00 committed by GitHub
parent d44c0f7e5d
commit 4df7a1af25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 248 additions and 211 deletions

View file

@ -4,6 +4,7 @@
#![allow(crown::unrooted_must_root)]
use std::cell::Cell;
use std::io;
use html5ever::buffer_queue::BufferQueue;
@ -47,7 +48,7 @@ impl Tokenizer {
let sink = Sink {
base_url: url,
document: Dom::from_ref(document),
current_line: 1,
current_line: Cell::new(1),
script: Default::default(),
parsing_algorithm,
};
@ -78,7 +79,7 @@ impl Tokenizer {
Tokenizer { inner }
}
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
pub fn feed(&self, input: &BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
match self.inner.feed(input) {
TokenizerResult::Done => TokenizerResult::Done,
TokenizerResult::Script(script) => {
@ -87,7 +88,7 @@ impl Tokenizer {
}
}
pub fn end(&mut self) {
pub fn end(&self) {
self.inner.end();
}
@ -95,7 +96,7 @@ impl Tokenizer {
&self.inner.sink.sink.base_url
}
pub fn set_plaintext_state(&mut self) {
pub fn set_plaintext_state(&self) {
self.inner.set_plaintext_state();
}
}