mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
LibWeb: Track whether HTMLParser is script-created
Add a ScriptCreatedParser flag plumbed through HTMLParser's constructor and create_for_scripting(). Only document.open()'s parser sets it to Yes. Document::close() step 3 now checks is_script_created() so it correctly skips parsers that weren't created via document.open(), matching the spec. Previously the check was just `if (!m_parser)`, which incorrectly let document.close() insert an EOF into a network-driven parser. The bug was mostly latent because the network parser used to finish quickly, but it matters once the network parser stays alive for the duration of a streamed parse.
This commit is contained in:
committed by
Andreas Kling
parent
c8368882b8
commit
f499edefae
Notes:
github-actions[bot]
2026-04-29 02:13:54 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/f499edefae5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/9151
@@ -173,8 +173,9 @@ HTMLParser::HTMLParser(DOM::Document& document, ParserScriptingMode scripting_mo
|
||||
m_document->set_encoding(MUST(String::from_utf8(standardized_encoding.value())));
|
||||
}
|
||||
|
||||
HTMLParser::HTMLParser(DOM::Document& document, ParserScriptingMode scripting_mode)
|
||||
HTMLParser::HTMLParser(DOM::Document& document, ParserScriptingMode scripting_mode, ScriptCreatedParser script_created)
|
||||
: m_scripting_mode(scripting_mode)
|
||||
, m_script_created(script_created == ScriptCreatedParser::Yes)
|
||||
, m_document(document)
|
||||
{
|
||||
m_document->set_parser({}, *this);
|
||||
@@ -5169,7 +5170,13 @@ WebIDL::ExceptionOr<Vector<GC::Root<DOM::Node>>> HTMLParser::parse_html_fragment
|
||||
GC::Ref<HTMLParser> HTMLParser::create_for_scripting(DOM::Document& document)
|
||||
{
|
||||
auto scripting_mode = document.is_scripting_enabled() ? ParserScriptingMode::Normal : ParserScriptingMode::Disabled;
|
||||
return document.realm().create<HTMLParser>(document, scripting_mode);
|
||||
return document.realm().create<HTMLParser>(document, scripting_mode, ScriptCreatedParser::Yes);
|
||||
}
|
||||
|
||||
GC::Ref<HTMLParser> HTMLParser::create_with_open_input_stream(DOM::Document& document)
|
||||
{
|
||||
auto scripting_mode = document.is_scripting_enabled() ? ParserScriptingMode::Normal : ParserScriptingMode::Disabled;
|
||||
return document.realm().create<HTMLParser>(document, scripting_mode, ScriptCreatedParser::No);
|
||||
}
|
||||
|
||||
GC::Ref<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional<MimeSniff::MimeType> maybe_mime_type)
|
||||
|
||||
Reference in New Issue
Block a user