mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibWeb: Make HTMLDocumentParser take an existing document
We shouldn't really be creating the document objects inside the parser, since that makes it hard to hook up e.g JavaScript bindings early on.
This commit is contained in:
parent
4dbecf0b65
commit
22c582a887
4 changed files with 14 additions and 19 deletions
|
@ -112,21 +112,15 @@ static Vector<FlyString> s_quirks_public_ids = {
|
||||||
|
|
||||||
RefPtr<DOM::Document> parse_html_document(const StringView& data, const URL& url, const String& encoding)
|
RefPtr<DOM::Document> parse_html_document(const StringView& data, const URL& url, const String& encoding)
|
||||||
{
|
{
|
||||||
HTMLDocumentParser parser(data, TextCodec::get_standardized_encoding(encoding));
|
auto document = DOM::Document::create(url);
|
||||||
|
HTMLDocumentParser parser(document, data, TextCodec::get_standardized_encoding(encoding));
|
||||||
parser.run(url);
|
parser.run(url);
|
||||||
return parser.document();
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding)
|
HTMLDocumentParser::HTMLDocumentParser(DOM::Document& document, const StringView& input, const String& encoding)
|
||||||
: m_tokenizer(input, encoding)
|
: m_tokenizer(input, encoding)
|
||||||
{
|
, m_document(document)
|
||||||
m_document = DOM::Document::create();
|
|
||||||
m_document->set_encoding(encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding, DOM::Document& existing_document)
|
|
||||||
: m_tokenizer(input, encoding)
|
|
||||||
, m_document(existing_document)
|
|
||||||
{
|
{
|
||||||
m_document->set_encoding(encoding);
|
m_document->set_encoding(encoding);
|
||||||
}
|
}
|
||||||
|
@ -2975,7 +2969,8 @@ DOM::Document& HTMLDocumentParser::document()
|
||||||
|
|
||||||
NonnullRefPtrVector<DOM::Node> HTMLDocumentParser::parse_html_fragment(DOM::Element& context_element, const StringView& markup)
|
NonnullRefPtrVector<DOM::Node> HTMLDocumentParser::parse_html_fragment(DOM::Element& context_element, const StringView& markup)
|
||||||
{
|
{
|
||||||
HTMLDocumentParser parser(markup, "utf-8");
|
auto temp_document = DOM::Document::create();
|
||||||
|
HTMLDocumentParser parser(*temp_document, markup, "utf-8");
|
||||||
parser.m_context_element = context_element;
|
parser.m_context_element = context_element;
|
||||||
parser.m_parsing_fragment = true;
|
parser.m_parsing_fragment = true;
|
||||||
parser.document().set_quirks_mode(context_element.document().mode());
|
parser.document().set_quirks_mode(context_element.document().mode());
|
||||||
|
@ -3022,5 +3017,4 @@ NonnullRefPtrVector<DOM::Node> HTMLDocumentParser::parse_html_fragment(DOM::Elem
|
||||||
}
|
}
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,7 @@ RefPtr<DOM::Document> parse_html_document(const StringView&, const URL&, const S
|
||||||
|
|
||||||
class HTMLDocumentParser {
|
class HTMLDocumentParser {
|
||||||
public:
|
public:
|
||||||
HTMLDocumentParser(const StringView& input, const String& encoding);
|
HTMLDocumentParser(DOM::Document&, const StringView& input, const String& encoding);
|
||||||
HTMLDocumentParser(const StringView& input, const String& encoding, DOM::Document& existing_document);
|
|
||||||
~HTMLDocumentParser();
|
~HTMLDocumentParser();
|
||||||
|
|
||||||
void run(const URL&);
|
void run(const URL&);
|
||||||
|
@ -180,7 +179,7 @@ private:
|
||||||
bool m_stop_parsing { false };
|
bool m_stop_parsing { false };
|
||||||
size_t m_script_nesting_level { 0 };
|
size_t m_script_nesting_level { 0 };
|
||||||
|
|
||||||
RefPtr<DOM::Document> m_document;
|
NonnullRefPtr<DOM::Document> m_document;
|
||||||
RefPtr<HTMLHeadElement> m_head_element;
|
RefPtr<HTMLHeadElement> m_head_element;
|
||||||
RefPtr<HTMLFormElement> m_form_element;
|
RefPtr<HTMLFormElement> m_form_element;
|
||||||
RefPtr<DOM::Element> m_context_element;
|
RefPtr<DOM::Element> m_context_element;
|
||||||
|
|
|
@ -214,7 +214,8 @@ bool FrameLoader::load(const URL& url, Type type)
|
||||||
|
|
||||||
void FrameLoader::load_html(const StringView& html, const URL& url)
|
void FrameLoader::load_html(const StringView& html, const URL& url)
|
||||||
{
|
{
|
||||||
HTML::HTMLDocumentParser parser(html, "utf-8");
|
auto document = DOM::Document::create(url);
|
||||||
|
HTML::HTMLDocumentParser parser(document, html, "utf-8");
|
||||||
parser.run(url);
|
parser.run(url);
|
||||||
frame().set_document(&parser.document());
|
frame().set_document(&parser.document());
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ void TestRunner::run()
|
||||||
Web::ResourceLoader::the().load_sync(
|
Web::ResourceLoader::the().load_sync(
|
||||||
page_to_load,
|
page_to_load,
|
||||||
[&](auto data, auto&) {
|
[&](auto data, auto&) {
|
||||||
Web::HTML::HTMLDocumentParser parser(data, "utf-8", *m_page_view->document());
|
Web::HTML::HTMLDocumentParser parser(*m_page_view->document(), data, "utf-8");
|
||||||
parser.run(page_to_load);
|
parser.run(page_to_load);
|
||||||
},
|
},
|
||||||
[page_to_load](auto error) {
|
[page_to_load](auto error) {
|
||||||
|
@ -350,7 +350,8 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
||||||
page_to_load,
|
page_to_load,
|
||||||
[&](auto data, auto&) {
|
[&](auto data, auto&) {
|
||||||
// Create a new parser and immediately get its document to replace the old interpreter.
|
// Create a new parser and immediately get its document to replace the old interpreter.
|
||||||
Web::HTML::HTMLDocumentParser parser(data, "utf-8");
|
auto document = Web::DOM::Document::create();
|
||||||
|
Web::HTML::HTMLDocumentParser parser(document, data, "utf-8");
|
||||||
auto& new_interpreter = parser.document().interpreter();
|
auto& new_interpreter = parser.document().interpreter();
|
||||||
|
|
||||||
// Setup the test environment and call "__BeforeInitialPageLoad__"
|
// Setup the test environment and call "__BeforeInitialPageLoad__"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue