LibWeb: Insert title as first child on setting title of svg document

Before, the new title element got appended instead of prepended, as
nullptr was passed as the "child" argument to the insert_before()
function.

This change makes two WPT tests pass in:
http://wpt.live/html/dom/documents/dom-tree-accessors/document.title-09.html
This commit is contained in:
ronak69 2024-10-13 17:35:35 +00:00 committed by Andreas Kling
parent 910f9c2c09
commit 3ff6137121
Notes: github-actions[bot] 2024-10-14 05:14:48 +00:00
3 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1 @@
title == title

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
var doc = document.implementation.createDocument(SVG_NAMESPACE, "svg", null);
var child = doc.createElementNS(SVG_NAMESPACE, "x-child");
doc.documentElement.appendChild(child);
doc.title = "foo";
println(`title == ${doc.documentElement.firstChild.tagName}`);
});
</script>

View file

@ -923,7 +923,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::SVG));
// 2. Insert element as the first child of the document element.
document_element->insert_before(*element, nullptr);
document_element->insert_before(*element, document_element->first_child());
}
// 3. String replace all with the given value within element.