mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibWeb: Append only one line feed character in Document.writeln
There were a couple issues here: 1. The line feed should only be appended once, rather than one per string. 2. The new_strings list of strings was unused (we were creating the new list, then passing the old list to Document.write).
This commit is contained in:
parent
d94db1900e
commit
21bd3a21bd
Notes:
sideshowbarker
2024-07-17 18:19:19 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/21bd3a21bd Pull-request: https://github.com/SerenityOS/serenity/pull/12709 Reviewed-by: https://github.com/awesomekling
2 changed files with 22 additions and 16 deletions
|
@ -150,6 +150,25 @@ void Document::removed_last_ref()
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write
|
||||
ExceptionOr<void> Document::write(Vector<String> const& strings)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.join(""sv, strings);
|
||||
|
||||
return run_the_document_write_steps(builder.build());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln
|
||||
ExceptionOr<void> Document::writeln(Vector<String> const& strings)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.join(""sv, strings);
|
||||
builder.append("\n"sv);
|
||||
|
||||
return run_the_document_write_steps(builder.build());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document-write-steps
|
||||
ExceptionOr<void> Document::run_the_document_write_steps(String input)
|
||||
{
|
||||
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException.
|
||||
if (doctype() && doctype()->name() == "xml")
|
||||
|
@ -174,9 +193,7 @@ ExceptionOr<void> Document::write(Vector<String> const& strings)
|
|||
}
|
||||
|
||||
// 5. Insert input into the input stream just before the insertion point.
|
||||
StringBuilder builder;
|
||||
builder.join("", strings);
|
||||
m_parser->tokenizer().insert_input_at_insertion_point(builder.build());
|
||||
m_parser->tokenizer().insert_input_at_insertion_point(input);
|
||||
|
||||
// 6. If there is no pending parsing-blocking script, have the HTML parser process input, one code point at a time, processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the insertion point or when the processing of the tokenizer is aborted by the tree construction stage (this can happen if a script end tag token is emitted by the tokenizer).
|
||||
if (!pending_parsing_blocking_script())
|
||||
|
@ -185,19 +202,6 @@ ExceptionOr<void> Document::write(Vector<String> const& strings)
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln
|
||||
ExceptionOr<void> Document::writeln(Vector<String> const& strings)
|
||||
{
|
||||
|
||||
// FIXME: No need to allocate a new vector
|
||||
Vector<String> new_strings;
|
||||
for (auto const& element : strings) {
|
||||
new_strings.append(String::formatted("{}\n", element));
|
||||
}
|
||||
|
||||
return write(strings);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open
|
||||
ExceptionOr<Document*> Document::open(String const&, String const&)
|
||||
{
|
||||
|
|
|
@ -324,6 +324,8 @@ private:
|
|||
|
||||
void tear_down_layout_tree();
|
||||
|
||||
ExceptionOr<void> run_the_document_write_steps(String);
|
||||
|
||||
void increment_referencing_node_count()
|
||||
{
|
||||
VERIFY(!m_deletion_has_begun);
|
||||
|
|
Loading…
Reference in a new issue