mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
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:
committed by
Andrew Kaster
parent
3c45d155a6
commit
8cfac6ed71
Notes:
github-actions[bot]
2025-04-16 15:03:28 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/8cfac6ed710 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4373
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user