Pārlūkot izejas kodu

LibWeb: Skip select element internal shadow tree update unless it exists

This fixes a crash seen on https://www.gaslightanthem.com/
Andreas Kling 1 gadu atpakaļ
vecāks
revīzija
58b5181364

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/select-setValue-after-construction.txt

@@ -0,0 +1 @@
+PASS

+ 12 - 0
Tests/LibWeb/Text/input/HTML/select-setValue-after-construction.html

@@ -0,0 +1,12 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        let select = document.createElement("select");
+        let option = document.createElement("option");
+        option.setAttribute("selected", "selected");
+        option.setAttribute("value", "foo");
+        select.appendChild(option);
+        select.value = "foo";
+        println("PASS"); // Didn't crash
+    });
+</script>

+ 3 - 0
Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp

@@ -383,6 +383,9 @@ void HTMLSelectElement::create_shadow_tree_if_needed()
 
 void HTMLSelectElement::update_inner_text_element()
 {
+    if (!m_inner_text_element)
+        return;
+
     // Update inner text element to text content of selected option
     for (auto const& option_element : list_of_options()) {
         if (option_element->selected()) {