Title: [233281] trunk
Revision
233281
Author
[email protected]
Date
2018-06-27 15:25:30 -0700 (Wed, 27 Jun 2018)

Log Message

Don't invoke post resolution callbacks when resolving computed style
https://bugs.webkit.org/show_bug.cgi?id=187113
<rdar://problem/41365766>

Reviewed by Geoff Garen.

Source/WebCore:

Post-resolution callbacks should only be invoked when we resolve the full document style,
not when resolving computed style for a single element.

Tests: fast/dom/object-computed-style-event.html

* dom/Document.cpp:
(WebCore::Document::styleForElementIgnoringPendingStylesheets):
* dom/Element.cpp:
(WebCore::Element::resolveComputedStyle):

Also ref the ancestor stack to be safe.

* style/StyleTreeResolver.cpp:
(WebCore::Style::PostResolutionCallbackDisabler::PostResolutionCallbackDisabler):
(WebCore::Style::PostResolutionCallbackDisabler::~PostResolutionCallbackDisabler):

Add an option to not drain the callback queue on destruction. In this mode we
just block network loads.

* style/StyleTreeResolver.h:

LayoutTests:

* fast/dom/object-computed-style-event-expected.txt: Added.
* fast/dom/object-computed-style-event.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (233280 => 233281)


--- trunk/LayoutTests/ChangeLog	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/LayoutTests/ChangeLog	2018-06-27 22:25:30 UTC (rev 233281)
@@ -1,3 +1,14 @@
+2018-06-27  Antti Koivisto  <[email protected]>
+
+        Don't invoke post resolution callbacks when resolving computed style
+        https://bugs.webkit.org/show_bug.cgi?id=187113
+        <rdar://problem/41365766>
+
+        Reviewed by Geoff Garen.
+
+        * fast/dom/object-computed-style-event-expected.txt: Added.
+        * fast/dom/object-computed-style-event.html: Added.
+
 2018-06-27  Timothy Hatcher  <[email protected]>
 
         Find on page selection color isn't adapted for dark mode.

Added: trunk/LayoutTests/fast/dom/object-computed-style-event-expected.txt (0 => 233281)


--- trunk/LayoutTests/fast/dom/object-computed-style-event-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/object-computed-style-event-expected.txt	2018-06-27 22:25:30 UTC (rev 233281)
@@ -0,0 +1 @@
+This test passes if there is no exception.

Added: trunk/LayoutTests/fast/dom/object-computed-style-event.html (0 => 233281)


--- trunk/LayoutTests/fast/dom/object-computed-style-event.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/object-computed-style-event.html	2018-06-27 22:25:30 UTC (rev 233281)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+</script>
+<style>
+.class1 { -webkit-mask-box-image-source: url(#nonexistentURL); }
+</style>
+<script>
+function freememory() {
+    var a;
+    for(var i=0;i<100;i++) {
+        a = new Uint8Array(1024*1024);
+    }
+    document.implementation.createHTMLDocument("doc");
+}
+
+function createTestRange() {
+    var testRange = document.createRange();
+    testRange.setEndAfter(testSelectOption);
+    testRange.deleteContents();
+}
+
+function eventhandler1() {
+    var testDataList = document.createElement("datalist");
+    testSelect.appendChild(testObjectParam);
+    document.title = "foo";
+    testDataList.addEventListener("DOMNodeInsertedIntoDocument", createTestRange);
+    testObject.appendChild(testDataList);
+    freememory();
+}
+
+function eventhandler2() {
+    testObject.setAttribute("onbeforeload", "eventhandler1()");
+    testSelect.addEventListener("DOMNodeRemovedFromDocument", eventhandler1);
+    testSelect.replaceWith("This test passes if there is no exception.");
+}
+
+function runTest() {
+    var testSource = document.createElement("source");
+    testSource.addEventListener("DOMSubtreeModified", eventhandler2);
+    testSource.setAttribute("onsubmit", "");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+</script>
+</head>
+<body _onload_=runTest()>
+    <li class="class1">Test List</li>
+    <object id="testObject">
+        <param id="testObjectParam"></param>
+    </object>
+    <select id="testSelect">
+        <option id="testSelectOption">Test Option</option>
+    </select>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (233280 => 233281)


--- trunk/Source/WebCore/ChangeLog	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/Source/WebCore/ChangeLog	2018-06-27 22:25:30 UTC (rev 233281)
@@ -1,3 +1,32 @@
+2018-06-27  Antti Koivisto  <[email protected]>
+
+        Don't invoke post resolution callbacks when resolving computed style
+        https://bugs.webkit.org/show_bug.cgi?id=187113
+        <rdar://problem/41365766>
+
+        Reviewed by Geoff Garen.
+
+        Post-resolution callbacks should only be invoked when we resolve the full document style,
+        not when resolving computed style for a single element.
+
+        Tests: fast/dom/object-computed-style-event.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::styleForElementIgnoringPendingStylesheets):
+        * dom/Element.cpp:
+        (WebCore::Element::resolveComputedStyle):
+
+        Also ref the ancestor stack to be safe.
+
+        * style/StyleTreeResolver.cpp:
+        (WebCore::Style::PostResolutionCallbackDisabler::PostResolutionCallbackDisabler):
+        (WebCore::Style::PostResolutionCallbackDisabler::~PostResolutionCallbackDisabler):
+
+        Add an option to not drain the callback queue on destruction. In this mode we
+        just block network loads.
+
+        * style/StyleTreeResolver.h:
+
 2018-06-27  Timothy Hatcher  <[email protected]>
 
         Find on page selection color isn't adapted for dark mode.

Modified: trunk/Source/WebCore/dom/Document.cpp (233280 => 233281)


--- trunk/Source/WebCore/dom/Document.cpp	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/Source/WebCore/dom/Document.cpp	2018-06-27 22:25:30 UTC (rev 233281)
@@ -2021,7 +2021,7 @@
     ASSERT(pseudoElementSpecifier == PseudoId::None || parentStyle);
 
     // On iOS request delegates called during styleForElement may result in re-entering WebKit and killing the style resolver.
-    Style::PostResolutionCallbackDisabler disabler(*this);
+    Style::PostResolutionCallbackDisabler disabler(*this, Style::PostResolutionCallbackDisabler::DrainCallbacks::No);
 
     SetForScope<bool> change(m_ignorePendingStylesheets, true);
     auto& resolver = element.styleResolver();

Modified: trunk/Source/WebCore/dom/Element.cpp (233280 => 233281)


--- trunk/Source/WebCore/dom/Element.cpp	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/Source/WebCore/dom/Element.cpp	2018-06-27 22:25:30 UTC (rev 233281)
@@ -2746,7 +2746,7 @@
     ASSERT(isConnected());
     ASSERT(!existingComputedStyle());
 
-    Deque<Element*, 32> elementsRequiringComputedStyle({ this });
+    Deque<RefPtr<Element>, 32> elementsRequiringComputedStyle({ this });
     const RenderStyle* computedStyle = nullptr;
 
     // Collect ancestors until we find one that has style.
@@ -2760,7 +2760,7 @@
     }
 
     // Resolve and cache styles starting from the most distant ancestor.
-    for (auto* element : elementsRequiringComputedStyle) {
+    for (auto& element : elementsRequiringComputedStyle) {
         auto style = document().styleForElementIgnoringPendingStylesheets(*element, computedStyle);
         computedStyle = style.get();
         ElementRareData& rareData = element->ensureElementRareData();

Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (233280 => 233281)


--- trunk/Source/WebCore/style/StyleTreeResolver.cpp	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp	2018-06-27 22:25:30 UTC (rev 233281)
@@ -600,7 +600,8 @@
 
 static unsigned resolutionNestingDepth;
 
-PostResolutionCallbackDisabler::PostResolutionCallbackDisabler(Document& document)
+PostResolutionCallbackDisabler::PostResolutionCallbackDisabler(Document& document, DrainCallbacks drainCallbacks)
+    : m_drainCallbacks(drainCallbacks)
 {
     ++resolutionNestingDepth;
 
@@ -614,12 +615,13 @@
 PostResolutionCallbackDisabler::~PostResolutionCallbackDisabler()
 {
     if (resolutionNestingDepth == 1) {
-        // Get size each time through the loop because a callback can add more callbacks to the end of the queue.
-        auto& queue = postResolutionCallbackQueue();
-        for (size_t i = 0; i < queue.size(); ++i)
-            queue[i]();
-        queue.clear();
-
+        if (m_drainCallbacks == DrainCallbacks::Yes) {
+            // Get size each time through the loop because a callback can add more callbacks to the end of the queue.
+            auto& queue = postResolutionCallbackQueue();
+            for (size_t i = 0; i < queue.size(); ++i)
+                queue[i]();
+            queue.clear();
+        }
         platformStrategies()->loaderStrategy()->resumePendingRequests();
     }
 

Modified: trunk/Source/WebCore/style/StyleTreeResolver.h (233280 => 233281)


--- trunk/Source/WebCore/style/StyleTreeResolver.h	2018-06-27 22:14:53 UTC (rev 233280)
+++ trunk/Source/WebCore/style/StyleTreeResolver.h	2018-06-27 22:25:30 UTC (rev 233281)
@@ -112,8 +112,11 @@
 
 class PostResolutionCallbackDisabler {
 public:
-    explicit PostResolutionCallbackDisabler(Document&);
+    enum class DrainCallbacks { Yes, No };
+    explicit PostResolutionCallbackDisabler(Document&, DrainCallbacks = DrainCallbacks::Yes);
     ~PostResolutionCallbackDisabler();
+private:
+    DrainCallbacks m_drainCallbacks;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to