diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 009014546b1..8cb4f51e44f 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -49,6 +49,10 @@ #include #include +#ifdef LIBWEB_USE_SWIFT +# include +#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::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> HTMLParser::parse_html_fragment(DOM::Element& contex GC::Ref HTMLParser::create_for_scripting(DOM::Document& document) { - return document.heap().allocate(document); + return document.realm().create(document); } GC::Ref HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional maybe_mime_type) { if (document.has_encoding()) - return document.heap().allocate(document, input, document.encoding().value().to_byte_string()); + return document.realm().create(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(document, input, encoding); + return document.realm().create(document, input, encoding); } GC::Ref HTMLParser::create(DOM::Document& document, StringView input, StringView encoding) { - return document.heap().allocate(document, input, encoding); + return document.realm().create(document, input, encoding); } enum class AttributeMode { diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.h b/Libraries/LibWeb/HTML/Parser/HTMLParser.h index 16902a40c76..66e6916c73a 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.h +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.h @@ -14,6 +14,14 @@ #include #include +#ifdef LIBWEB_USE_SWIFT +# include + +namespace Web { +class SpeculativeHTMLParser; +} +#endif + namespace Web::HTML { #define ENUMERATE_INSERTION_MODES \ @@ -96,6 +104,7 @@ private: HTMLParser(DOM::Document&); virtual void visit_edges(Cell::Visitor&) override; + virtual void initialize(JS::Realm&) override; char const* insertion_mode_name() const; @@ -210,6 +219,10 @@ private: GC::Ptr m_form_element; GC::Ptr m_context_element; +#ifdef LIBWEB_USE_SWIFT + GC::ForeignPtr m_speculative_parser; +#endif + Vector m_pending_table_character_tokens; GC::Ptr m_character_insertion_node; diff --git a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.swift b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.swift index fae5d34d124..aa5e38b942c 100644 --- a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.swift +++ b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.swift @@ -57,4 +57,8 @@ public final class SpeculativeHTMLParser: HeapAllocatable { public func visitEdges(_ visitor: GC.Cell.Visitor) { visitor.visit(parser) } + + public func poke() { + print("Hello from SpeculativeHTMLParser") + } }