浏览代码

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
ronak69 9 月之前
父节点
当前提交
3ff6137121

+ 1 - 0
Tests/LibWeb/Text/expected/DOM/Document-svg-title-element-first-child.txt

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

+ 12 - 0
Tests/LibWeb/Text/input/DOM/Document-svg-title-element-first-child.html

@@ -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>

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -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.