LibWeb: Store a SpeculativeHTMLParser on the HTML Parser

The parser was previously added, but unused. Actually attaching one to
the HTML Parser will let us test the limits of Swift interop.
This commit is contained in:
Andrew Kaster 2025-04-04 09:20:27 -06:00 committed by Andrew Kaster
parent 3c45d155a6
commit 8cfac6ed71
Notes: github-actions[bot] 2025-04-16 15:03:28 +00:00
3 changed files with 39 additions and 4 deletions

View file

@ -49,6 +49,10 @@
#include <LibWeb/SVG/SVGScriptElement.h>
#include <LibWeb/SVG/TagNames.h>
#ifdef LIBWEB_USE_SWIFT
# include <LibWeb-Swift.h>
#endif
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(HTMLParser);
@ -189,10 +193,24 @@ void HTMLParser::visit_edges(Cell::Visitor& visitor)
m_list_of_active_formatting_elements.visit_edges(visitor);
}
void HTMLParser::initialize(JS::Realm& realm)
{
Base::initialize(realm);
#if defined(LIBWEB_USE_SWIFT)
m_speculative_parser = GC::ForeignRef<Web::SpeculativeHTMLParser>::allocate(realm.heap(), this);
#endif
}
void HTMLParser::run(HTMLTokenizer::StopAtInsertionPoint stop_at_insertion_point)
{
m_stop_parsing = false;
#if defined(LIBWEB_USE_SWIFT)
dbgln("Poking Swift Tokenizer");
m_speculative_parser->poke();
#endif
for (;;) {
auto optional_token = m_tokenizer.next_token(stop_at_insertion_point);
if (!optional_token.has_value())
@ -4642,21 +4660,21 @@ Vector<GC::Root<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& contex
GC::Ref<HTMLParser> HTMLParser::create_for_scripting(DOM::Document& document)
{
return document.heap().allocate<HTMLParser>(document);
return document.realm().create<HTMLParser>(document);
}
GC::Ref<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional<MimeSniff::MimeType> maybe_mime_type)
{
if (document.has_encoding())
return document.heap().allocate<HTMLParser>(document, input, document.encoding().value().to_byte_string());
return document.realm().create<HTMLParser>(document, input, document.encoding().value().to_byte_string());
auto encoding = run_encoding_sniffing_algorithm(document, input, maybe_mime_type);
dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding);
return document.heap().allocate<HTMLParser>(document, input, encoding);
return document.realm().create<HTMLParser>(document, input, encoding);
}
GC::Ref<HTMLParser> HTMLParser::create(DOM::Document& document, StringView input, StringView encoding)
{
return document.heap().allocate<HTMLParser>(document, input, encoding);
return document.realm().create<HTMLParser>(document, input, encoding);
}
enum class AttributeMode {