1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +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

@ -41,15 +41,15 @@ namespace Web::HTML {
RefPtr<DOM::Document> parse_html_document(StringView, const AK::URL&, const String& encoding);
class HTMLParser {
class HTMLParser : public RefCounted<HTMLParser> {
friend class HTMLTokenizer;
public:
HTMLParser(DOM::Document&, StringView input, const String& encoding);
HTMLParser(DOM::Document&);
~HTMLParser();
static NonnullOwnPtr<HTMLParser> create_with_uncertain_encoding(DOM::Document&, const ByteBuffer& input);
static NonnullRefPtr<HTMLParser> create_for_scripting(DOM::Document&);
static NonnullRefPtr<HTMLParser> create_with_uncertain_encoding(DOM::Document&, ByteBuffer const& input);
static NonnullRefPtr<HTMLParser> create(DOM::Document&, StringView input, String const& encoding);
void run();
void run(const AK::URL&);
@ -76,6 +76,9 @@ public:
size_t script_nesting_level() const { return m_script_nesting_level; }
private:
HTMLParser(DOM::Document&, StringView input, const String& encoding);
HTMLParser(DOM::Document&);
const char* insertion_mode_name() const;
DOM::QuirksMode which_quirks_mode(const HTMLToken&) const;