1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +00:00

LibWeb: Make document.write() work while document is parsing

This necessitated making HTMLParser ref-counted, and having it register
itself with Document when created. That makes it possible for scripts to
add new input at the current parser insertion point.

There is now a reference cycle between Document and HTMLParser. This
cycle is explicitly broken by calling Document::detach_parser() at the
end of HTMLParser::run().

This is a huge progression on ACID3, from 31% to 49%! :^)
This commit is contained in:
Andreas Kling 2022-02-21 21:54:21 +01:00
parent bb1f26c149
commit 8b2499b112
7 changed files with 67 additions and 38 deletions

View file

@ -256,7 +256,7 @@ ExceptionOr<Document*> Document::open(String const&, String const&)
set_quirks_mode(QuirksMode::No);
// 16. Create a new HTML parser and associate it with document. This is a script-created parser (meaning that it can be closed by the document.open() and document.close() methods, and that the tokenizer will wait for an explicit call to document.close() before emitting an end-of-file token). The encoding confidence is irrelevant.
m_parser = make<HTML::HTMLParser>(*this);
m_parser = HTML::HTMLParser::create_for_scripting(*this);
// 17. Set the insertion point to point at just before the end of the input stream (which at this point will be empty).
m_parser->tokenizer().update_insertion_point();
@ -1324,4 +1324,14 @@ bool Document::has_focus() const
return true;
}
void Document::set_parser(Badge<HTML::HTMLParser>, HTML::HTMLParser& parser)
{
m_parser = parser;
}
void Document::detach_parser(Badge<HTML::HTMLParser>)
{
m_parser = nullptr;
}
}