Move queue processing logic from CustomElementReactionStack to CustomElementReactionQueue
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 22:37:09 +0000 (22:37 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 22:37:09 +0000 (22:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188277

Reviewed by Wenson Hsieh.

Moved ensureCurrentQueue, processBackupQueue, ElementQueue, ensureBackupQueue, and backupElementQueue
from CustomElementReactionStack to CustomElementReactionQueue to simplify CustomElementReactionStack.

No new tests since there is no behavior change.

* dom/CustomElementReactionQueue.cpp:
(WebCore::CustomElementReactionQueue::enqueueElementUpgrade):
(WebCore::CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded):
(WebCore::CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded):
(WebCore::CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded):
(WebCore::CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded):
(WebCore::CustomElementReactionQueue::ElementQueue::add): Moved from CustomElementReactionStack.
(WebCore::CustomElementReactionQueue::ElementQueue::invokeAll): Ditto.
(WebCore::CustomElementReactionQueue::ensureCurrentQueue): Ditto.
(WebCore::CustomElementReactionQueue::ensureBackupQueue): Ditto.
(WebCore::CustomElementReactionQueue::processBackupQueue): Ditto.
(WebCore::CustomElementReactionQueue::backupElementQueue): Ditto.
* dom/CustomElementReactionQueue.h:
(WebCore::CustomElementReactionStack::hasCurrentProcessingStack): Deleted. It was never called.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234520 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/CustomElementReactionQueue.cpp
Source/WebCore/dom/CustomElementReactionQueue.h

index e680396..4ede1f5 100644 (file)
@@ -1,3 +1,30 @@
+2018-08-02  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Move queue processing logic from CustomElementReactionStack to CustomElementReactionQueue
+        https://bugs.webkit.org/show_bug.cgi?id=188277
+
+        Reviewed by Wenson Hsieh.
+
+        Moved ensureCurrentQueue, processBackupQueue, ElementQueue, ensureBackupQueue, and backupElementQueue
+        from CustomElementReactionStack to CustomElementReactionQueue to simplify CustomElementReactionStack.
+
+        No new tests since there is no behavior change.
+
+        * dom/CustomElementReactionQueue.cpp:
+        (WebCore::CustomElementReactionQueue::enqueueElementUpgrade):
+        (WebCore::CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded):
+        (WebCore::CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded):
+        (WebCore::CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded):
+        (WebCore::CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded):
+        (WebCore::CustomElementReactionQueue::ElementQueue::add): Moved from CustomElementReactionStack.
+        (WebCore::CustomElementReactionQueue::ElementQueue::invokeAll): Ditto.
+        (WebCore::CustomElementReactionQueue::ensureCurrentQueue): Ditto.
+        (WebCore::CustomElementReactionQueue::ensureBackupQueue): Ditto.
+        (WebCore::CustomElementReactionQueue::processBackupQueue): Ditto.
+        (WebCore::CustomElementReactionQueue::backupElementQueue): Ditto.
+        * dom/CustomElementReactionQueue.h:
+        (WebCore::CustomElementReactionStack::hasCurrentProcessingStack): Deleted. It was never called.
+
 2018-08-02  Timothy Hatcher  <timothy@apple.com>
 
         Text selection color is hard to see in dark mode web views.
index fc44007..c3f0989 100644 (file)
@@ -116,7 +116,7 @@ void CustomElementReactionQueue::clear()
 
 void CustomElementReactionQueue::enqueueElementUpgrade(Element& element)
 {
-    auto& queue = CustomElementReactionStack::ensureCurrentQueue(element);
+    auto& queue = ensureCurrentQueue(element);
     queue.m_items.append({CustomElementReactionQueueItem::Type::ElementUpgrade});
 }
 
@@ -142,7 +142,7 @@ void CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(Element& eleme
 {
     ASSERT(element.isDefinedCustomElement());
     ASSERT(element.document().refCount() > 0);
-    auto& queue = CustomElementReactionStack::ensureCurrentQueue(element);
+    auto& queue = ensureCurrentQueue(element);
     if (queue.m_interface->hasConnectedCallback())
         queue.m_items.append({CustomElementReactionQueueItem::Type::Connected});
 }
@@ -152,7 +152,7 @@ void CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded(Element& el
     ASSERT(element.isDefinedCustomElement());
     if (element.document().refCount() <= 0)
         return; // Don't enqueue disconnectedCallback if the entire document is getting destructed.
-    auto& queue = CustomElementReactionStack::ensureCurrentQueue(element);
+    auto& queue = ensureCurrentQueue(element);
     if (queue.m_interface->hasDisconnectedCallback())
         queue.m_items.append({CustomElementReactionQueueItem::Type::Disconnected});
 }
@@ -161,7 +161,7 @@ void CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(Element& element
 {
     ASSERT(element.isDefinedCustomElement());
     ASSERT(element.document().refCount() > 0);
-    auto& queue = CustomElementReactionStack::ensureCurrentQueue(element);
+    auto& queue = ensureCurrentQueue(element);
     if (queue.m_interface->hasAdoptedCallback())
         queue.m_items.append({oldDocument, newDocument});
 }
@@ -170,7 +170,7 @@ void CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(Element
 {
     ASSERT(element.isDefinedCustomElement());
     ASSERT(element.document().refCount() > 0);
-    auto& queue = CustomElementReactionStack::ensureCurrentQueue(element);
+    auto& queue = ensureCurrentQueue(element);
     if (queue.m_interface->observesAttribute(attributeName.localName()))
         queue.m_items.append({attributeName, oldValue, newValue});
 }
@@ -209,14 +209,14 @@ void CustomElementReactionQueue::invokeAll(Element& element)
     }
 }
 
-inline void CustomElementReactionStack::ElementQueue::add(Element& element)
+inline void CustomElementReactionQueue::ElementQueue::add(Element& element)
 {
     RELEASE_ASSERT(!m_invoking);
     // FIXME: Avoid inserting the same element multiple times.
     m_elements.append(element);
 }
 
-inline void CustomElementReactionStack::ElementQueue::invokeAll()
+inline void CustomElementReactionQueue::ElementQueue::invokeAll()
 {
     RELEASE_ASSERT(!m_invoking);
     SetForScope<bool> invoking(m_invoking, true);
@@ -231,16 +231,16 @@ inline void CustomElementReactionStack::ElementQueue::invokeAll()
     RELEASE_ASSERT(m_elements.isEmpty());
 }
 
-CustomElementReactionQueue& CustomElementReactionStack::ensureCurrentQueue(Element& element)
+CustomElementReactionQueue& CustomElementReactionQueue::ensureCurrentQueue(Element& element)
 {
     ASSERT(element.reactionQueue());
-    if (!s_currentProcessingStack) {
-        auto& queue = CustomElementReactionStack::ensureBackupQueue();
+    if (!CustomElementReactionStack::s_currentProcessingStack) {
+        auto& queue = ensureBackupQueue();
         queue.add(element);
         return *element.reactionQueue();
     }
 
-    auto*& queue = s_currentProcessingStack->m_queue;
+    auto*& queue = CustomElementReactionStack::s_currentProcessingStack->m_queue;
     if (!queue) // We use a raw pointer to avoid genearing code to delete it in ~CustomElementReactionStack.
         queue = new ElementQueue;
     queue->add(element);
@@ -262,14 +262,14 @@ class BackupElementQueueMicrotask final : public Microtask {
 private:
     Result run() final
     {
-        CustomElementReactionStack::processBackupQueue();
+        CustomElementReactionQueue::processBackupQueue();
         return Result::Done;
     }
 };
 
 static bool s_processingBackupElementQueue = false;
 
-CustomElementReactionStack::ElementQueue& CustomElementReactionStack::ensureBackupQueue()
+CustomElementReactionQueue::ElementQueue& CustomElementReactionQueue::ensureBackupQueue()
 {
     if (!s_processingBackupElementQueue) {
         s_processingBackupElementQueue = true;
@@ -278,13 +278,13 @@ CustomElementReactionStack::ElementQueue& CustomElementReactionStack::ensureBack
     return backupElementQueue();
 }
 
-void CustomElementReactionStack::processBackupQueue()
+void CustomElementReactionQueue::processBackupQueue()
 {
     backupElementQueue().invokeAll();
     s_processingBackupElementQueue = false;
 }
 
-CustomElementReactionStack::ElementQueue& CustomElementReactionStack::backupElementQueue()
+CustomElementReactionQueue::ElementQueue& CustomElementReactionQueue::backupElementQueue()
 {
     static NeverDestroyed<ElementQueue> queue;
     return queue.get();
index 0c9123d..f1ddbdf 100644 (file)
@@ -55,7 +55,23 @@ public:
     void invokeAll(Element&);
     void clear();
 
+    static void processBackupQueue();
+
+    class ElementQueue {
+    public:
+        void add(Element&);
+        void invokeAll();
+        
+    private:
+        Vector<Ref<Element>> m_elements;
+        bool m_invoking { false };
+    };
+
 private:
+    static CustomElementReactionQueue& ensureCurrentQueue(Element&);
+    static ElementQueue& ensureBackupQueue();
+    static ElementQueue& backupElementQueue();
+
     Ref<JSCustomElementInterface> m_interface;
     Vector<CustomElementReactionQueueItem> m_items;
 };
@@ -75,32 +91,15 @@ public:
         s_currentProcessingStack = m_previousProcessingStack;
     }
 
-    static CustomElementReactionQueue& ensureCurrentQueue(Element&);
-
-    static bool hasCurrentProcessingStack() { return s_currentProcessingStack; }
-
-    static void processBackupQueue();
-
 private:
-    class ElementQueue {
-    public:
-        void add(Element&);
-        void invokeAll();
-
-    private:
-        Vector<Ref<Element>> m_elements;
-        bool m_invoking { false };
-    };
-
     WEBCORE_EXPORT void processQueue();
 
-    static ElementQueue& ensureBackupQueue();
-    static ElementQueue& backupElementQueue();
-
-    ElementQueue* m_queue { nullptr };
+    CustomElementReactionQueue::ElementQueue* m_queue { nullptr }; // Use raw pointer to avoid generating delete in the destructor.
     CustomElementReactionStack* m_previousProcessingStack;
 
     WEBCORE_EXPORT static CustomElementReactionStack* s_currentProcessingStack;
+
+    friend CustomElementReactionQueue;
 };
 
 }