LibWeb: Change HTMLParser's factory to accept the encoding as StringView

No need to force an allocation. This makes a future patch a bit simpler,
where we will have the encoding as a String. With this patch, we won't
have to convert it to a ByteString.
This commit is contained in:
Timothy Flynn 2024-04-03 21:56:58 -04:00 committed by Andreas Kling
commit 48fb343230
Notes: sideshowbarker 2024-07-17 05:18:58 +09:00
5 changed files with 8 additions and 8 deletions

View file

@ -77,7 +77,7 @@ static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::Document>> load_markdown_docume
if (!markdown_document)
return;
auto parser = HTML::HTMLParser::create(document, markdown_document->render_to_html(extra_head_contents), "utf-8");
auto parser = HTML::HTMLParser::create(document, markdown_document->render_to_html(extra_head_contents), "utf-8"sv);
parser->run(url);
};

View file

@ -53,7 +53,7 @@ JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(StringView string,
// 2. Create an HTML parser parser, associated with document.
// 3. Place string into the input stream for parser. The encoding confidence is irrelevant.
// FIXME: We don't have the concept of encoding confidence yet.
auto parser = HTMLParser::create(*document, string, "UTF-8");
auto parser = HTMLParser::create(*document, string, "UTF-8"sv);
// 4. Start parser and let it run until it has consumed all the characters just inserted into the input stream.
// FIXME: This is to match the default URL. Instead, pass in this's relevant global object's associated Document's URL.

View file

@ -1127,7 +1127,7 @@ WebIDL::ExceptionOr<void> Navigable::populate_session_history_entry_document(
// FIXME: Add error message to generated error page
auto error_html = load_error_page(entry->url()).release_value_but_fixme_should_propagate_errors();
entry->document_state()->set_document(create_document_for_inline_content(this, navigation_id, [error_html](auto& document) {
auto parser = HTML::HTMLParser::create(document, error_html, "utf-8");
auto parser = HTML::HTMLParser::create(document, error_html, "utf-8"sv);
document.set_url(URL::URL("about:error"));
parser->run();
}));

View file

@ -132,7 +132,7 @@ static bool is_html_integration_point(DOM::Element const& element)
return false;
}
HTMLParser::HTMLParser(DOM::Document& document, StringView input, ByteString const& encoding)
HTMLParser::HTMLParser(DOM::Document& document, StringView input, StringView encoding)
: m_tokenizer(input, encoding)
, m_scripting_enabled(document.is_scripting_enabled())
, m_document(JS::make_handle(document))
@ -4144,7 +4144,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
temp_document->set_quirks_mode(context_element.document().mode());
// 3. Create a new HTML parser, and associate it with the just created Document node.
auto parser = HTMLParser::create(*temp_document, markup, "utf-8");
auto parser = HTMLParser::create(*temp_document, markup, "utf-8"sv);
parser->m_context_element = JS::make_handle(context_element);
parser->m_parsing_fragment = true;
@ -4239,7 +4239,7 @@ JS::NonnullGCPtr<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Doc
return document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
}
JS::NonnullGCPtr<HTMLParser> HTMLParser::create(DOM::Document& document, StringView input, ByteString const& encoding)
JS::NonnullGCPtr<HTMLParser> HTMLParser::create(DOM::Document& document, StringView input, StringView encoding)
{
return document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
}

View file

@ -51,7 +51,7 @@ public:
static JS::NonnullGCPtr<HTMLParser> create_for_scripting(DOM::Document&);
static JS::NonnullGCPtr<HTMLParser> create_with_uncertain_encoding(DOM::Document&, ByteBuffer const& input);
static JS::NonnullGCPtr<HTMLParser> create(DOM::Document&, StringView input, ByteString const& encoding);
static JS::NonnullGCPtr<HTMLParser> create(DOM::Document&, StringView input, StringView encoding);
void run(HTMLTokenizer::StopAtInsertionPoint = HTMLTokenizer::StopAtInsertionPoint::No);
void run(const URL::URL&, HTMLTokenizer::StopAtInsertionPoint = HTMLTokenizer::StopAtInsertionPoint::No);
@ -84,7 +84,7 @@ public:
size_t script_nesting_level() const { return m_script_nesting_level; }
private:
HTMLParser(DOM::Document&, StringView input, ByteString const& encoding);
HTMLParser(DOM::Document&, StringView input, StringView encoding);
HTMLParser(DOM::Document&);
virtual void visit_edges(Cell::Visitor&) override;