Title: [239786] trunk
Revision
239786
Author
[email protected]
Date
2019-01-09 14:25:41 -0800 (Wed, 09 Jan 2019)

Log Message

[Datalist] Crash when input with datalist is dynamically added.
https://bugs.webkit.org/show_bug.cgi?id=193012
<rdar://problem/45923457>

Reviewed by Brent Fulgham.

Source/WebCore:

In certain cases (cloning, setAttribute), it's too early to check for the list attribute in createShadowSubtree
to see whether the input needs datalist related items. The list attribute is simply not set yet.
This patch only addresses the obvious crash. m_dataListDropdownIndicator clearly lacks proper lifecycle management (see webkit.org/b/193032).

Test: fast/forms/datalist/datalist-crash-when-dynamic.html

* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::createShadowSubtree):
(WebCore::TextFieldInputType::attributeChanged):
(WebCore::TextFieldInputType::createDataListDropdownIndicator):
* html/TextFieldInputType.h:

LayoutTests:

* fast/forms/datalist/datalist-crash-when-dynamic-expected.txt: Added.
* fast/forms/datalist/datalist-crash-when-dynamic.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (239785 => 239786)


--- trunk/LayoutTests/ChangeLog	2019-01-09 22:24:22 UTC (rev 239785)
+++ trunk/LayoutTests/ChangeLog	2019-01-09 22:25:41 UTC (rev 239786)
@@ -1,3 +1,14 @@
+2019-01-09  Zalan Bujtas  <[email protected]>
+
+        [Datalist] Crash when input with datalist is dynamically added.
+        https://bugs.webkit.org/show_bug.cgi?id=193012
+        <rdar://problem/45923457>
+
+        Reviewed by Brent Fulgham.
+
+        * fast/forms/datalist/datalist-crash-when-dynamic-expected.txt: Added.
+        * fast/forms/datalist/datalist-crash-when-dynamic.html: Added.
+
 2019-01-09  Justin Fan  <[email protected]>
 
         [WebGPU] Fix vertex-buffer-triangle-strip test and small update to GPURenderPipeline

Added: trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic-expected.txt (0 => 239786)


--- trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic-expected.txt	2019-01-09 22:25:41 UTC (rev 239786)
@@ -0,0 +1,2 @@
+Pass if no crash or assert
+  

Added: trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic.html (0 => 239786)


--- trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-crash-when-dynamic.html	2019-01-09 22:25:41 UTC (rev 239786)
@@ -0,0 +1,16 @@
+<div>Pass if no crash or assert</div>
+<input id="ice" name="ice-cream-choice">
+<datalist id="ice-cream-flavors">
+    <option value="Chocolate">
+    </option><option value="Coconut">
+    </option><option value="Mint">
+	</option>
+</datalist>
+
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+document.body.offsetHeight;
+ice.setAttribute("list", "ice-cream-flavors");
+document.body.appendChild(ice.cloneNode());
+</script>

Modified: trunk/Source/WebCore/ChangeLog (239785 => 239786)


--- trunk/Source/WebCore/ChangeLog	2019-01-09 22:24:22 UTC (rev 239785)
+++ trunk/Source/WebCore/ChangeLog	2019-01-09 22:25:41 UTC (rev 239786)
@@ -1,3 +1,23 @@
+2019-01-09  Zalan Bujtas  <[email protected]>
+
+        [Datalist] Crash when input with datalist is dynamically added.
+        https://bugs.webkit.org/show_bug.cgi?id=193012
+        <rdar://problem/45923457>
+
+        Reviewed by Brent Fulgham.
+
+        In certain cases (cloning, setAttribute), it's too early to check for the list attribute in createShadowSubtree
+        to see whether the input needs datalist related items. The list attribute is simply not set yet.
+        This patch only addresses the obvious crash. m_dataListDropdownIndicator clearly lacks proper lifecycle management (see webkit.org/b/193032). 
+
+        Test: fast/forms/datalist/datalist-crash-when-dynamic.html
+
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::createShadowSubtree):
+        (WebCore::TextFieldInputType::attributeChanged):
+        (WebCore::TextFieldInputType::createDataListDropdownIndicator):
+        * html/TextFieldInputType.h:
+
 2019-01-09  Justin Fan  <[email protected]>
 
         [WebGPU] Fix vertex-buffer-triangle-strip test and small update to GPURenderPipeline

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (239785 => 239786)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2019-01-09 22:24:22 UTC (rev 239785)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2019-01-09 22:25:41 UTC (rev 239786)
@@ -299,9 +299,6 @@
 
 bool TextFieldInputType::needsContainer() const
 {
-#if ENABLE(DATALIST_ELEMENT)
-    return element()->hasAttributeWithoutSynchronization(listAttr);
-#endif
     return false;
 }
 
@@ -358,14 +355,7 @@
 
         m_container->appendChild(*m_capsLockIndicator);
     }
-
     updateAutoFillButton();
-
-#if ENABLE(DATALIST_ELEMENT)
-    m_dataListDropdownIndicator = DataListButtonElement::create(element()->document(), *this);
-    m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);
-    m_container->appendChild(*m_dataListDropdownIndicator);
-#endif
 }
 
 HTMLElement* TextFieldInputType::containerElement() const
@@ -456,6 +446,18 @@
     return true;
 }
 
+#if ENABLE(DATALIST_ELEMENT)
+void TextFieldInputType::createDataListDropdownIndicator()
+{
+    ASSERT(!m_dataListDropdownIndicator);
+    if (!m_container)
+        createContainer();
+    m_dataListDropdownIndicator = DataListButtonElement::create(element()->document(), *this);
+    m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);
+    m_container->appendChild(*m_dataListDropdownIndicator);
+}
+#endif
+
 // FIXME: The name of this function doesn't make clear the two jobs it does:
 // 1) Limits the string to a particular number of grapheme clusters.
 // 2) Truncates the string at the first character which is a control character other than tab.
@@ -832,7 +834,7 @@
     m_cachedSuggestions = std::make_pair(String(), Vector<String>());
 
     if (!m_dataListDropdownIndicator)
-        return;
+        createDataListDropdownIndicator();
 
 #if !PLATFORM(IOS_FAMILY)
     m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, true);

Modified: trunk/Source/WebCore/html/TextFieldInputType.h (239785 => 239786)


--- trunk/Source/WebCore/html/TextFieldInputType.h	2019-01-09 22:24:22 UTC (rev 239785)
+++ trunk/Source/WebCore/html/TextFieldInputType.h	2019-01-09 22:25:41 UTC (rev 239786)
@@ -124,6 +124,7 @@
     void createAutoFillButton(AutoFillButtonType);
 
 #if ENABLE(DATALIST_ELEMENT)
+    void createDataListDropdownIndicator();
     bool isPresentingAttachedView() const final;
     void listAttributeTargetChanged() final;
     void displaySuggestions(DataListSuggestionActivationType);

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (239785 => 239786)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2019-01-09 22:24:22 UTC (rev 239785)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2019-01-09 22:25:41 UTC (rev 239786)
@@ -1145,8 +1145,11 @@
         [listButton setUserInterfaceLayoutDirection:NSUserInterfaceLayoutDirectionLeftToRight];
 
     [listButton setHighlighted:input.isPresentingAttachedView()];
-    if (!input.isPresentingAttachedView())
-        updatePressedState(listButton, *(input.dataListButtonElement()->renderer()));
+    if (!input.isPresentingAttachedView()) {
+        ASSERT(input.dataListButtonElement());
+        if (auto* buttonElement = input.dataListButtonElement())
+            updatePressedState(listButton, *buttonElement->renderer());
+    }
 
     [listButton drawWithFrame:listButtonFrame inView:documentViewFor(o)];
     [listButton setControlView:nil];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to