Rename AbstractEventLoop to EventLoop and move to its own cpp file
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Nov 2019 21:57:52 +0000 (21:57 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Nov 2019 21:57:52 +0000 (21:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204335

Reviewed by Antti Koivisto.

This patch renames AbstractEventLoop to EventLoop and move to its own cpp file since
r252607 consolidated the event loop implementations in WindowEventLoop and WorkerEventLoop.

* Modules/cache/DOMCache.cpp:
* Modules/cache/DOMCacheStorage.cpp:
* Modules/encryptedmedia/MediaKeySession.cpp:
* Modules/encryptedmedia/MediaKeys.cpp:
* Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* animation/WebAnimation.cpp:
* bindings/js/JSDOMPromiseDeferred.h:
* css/FontFaceSet.cpp:
* dom/ActiveDOMObject.cpp:
* dom/Document.h:
* dom/ScriptExecutionContext.h:
* dom/WindowEventLoop.cpp:
(WebCore::AbstractEventLoop::queueTask): Deleted.
(WebCore::AbstractEventLoop::resumeGroup): Deleted.
(WebCore::AbstractEventLoop::stopGroup): Deleted.
(WebCore::AbstractEventLoop::scheduleToRunIfNeeded): Deleted.
(WebCore::AbstractEventLoop::run): Deleted.
(WebCore::AbstractEventLoop::clearAllTasks): Deleted.
(WebCore::EventLoopFunctionDispatchTask::EventLoopFunctionDispatchTask): Deleted.
(WebCore::EventLoopTaskGroup::queueTask): Deleted.
* dom/WindowEventLoop.h:
* fileapi/FileReader.cpp:
* testing/Internals.cpp:
* workers/WorkerEventLoop.h:
* workers/service/ServiceWorkerContainer.cpp:

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

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/Modules/cache/DOMCacheStorage.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp
Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/animation/WebAnimation.cpp
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h
Source/WebCore/css/FontFaceSet.cpp
Source/WebCore/dom/ActiveDOMObject.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/EventLoop.cpp [new file with mode: 0644]
Source/WebCore/dom/EventLoop.h [moved from Source/WebCore/dom/AbstractEventLoop.h with 85% similarity]
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/dom/WindowEventLoop.cpp
Source/WebCore/dom/WindowEventLoop.h
Source/WebCore/fileapi/FileReader.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/workers/WorkerEventLoop.h
Source/WebCore/workers/service/ServiceWorkerContainer.cpp

index e88deaa..ca58e61 100644 (file)
@@ -1,3 +1,41 @@
+2019-11-18  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Rename AbstractEventLoop to EventLoop and move to its own cpp file
+        https://bugs.webkit.org/show_bug.cgi?id=204335
+
+        Reviewed by Antti Koivisto.
+
+        This patch renames AbstractEventLoop to EventLoop and move to its own cpp file since
+        r252607 consolidated the event loop implementations in WindowEventLoop and WorkerEventLoop.
+
+        * Modules/cache/DOMCache.cpp:
+        * Modules/cache/DOMCacheStorage.cpp:
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        * Modules/encryptedmedia/MediaKeys.cpp:
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * animation/WebAnimation.cpp:
+        * bindings/js/JSDOMPromiseDeferred.h:
+        * css/FontFaceSet.cpp:
+        * dom/ActiveDOMObject.cpp:
+        * dom/Document.h:
+        * dom/ScriptExecutionContext.h:
+        * dom/WindowEventLoop.cpp:
+        (WebCore::AbstractEventLoop::queueTask): Deleted.
+        (WebCore::AbstractEventLoop::resumeGroup): Deleted.
+        (WebCore::AbstractEventLoop::stopGroup): Deleted.
+        (WebCore::AbstractEventLoop::scheduleToRunIfNeeded): Deleted.
+        (WebCore::AbstractEventLoop::run): Deleted.
+        (WebCore::AbstractEventLoop::clearAllTasks): Deleted.
+        (WebCore::EventLoopFunctionDispatchTask::EventLoopFunctionDispatchTask): Deleted.
+        (WebCore::EventLoopTaskGroup::queueTask): Deleted.
+        * dom/WindowEventLoop.h:
+        * fileapi/FileReader.cpp:
+        * testing/Internals.cpp:
+        * workers/WorkerEventLoop.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+
 2019-11-19  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [IndexedDB] IndexedDB's threading assertion should respect Web thread
index 96fe73e..8e66a3b 100644 (file)
@@ -26,8 +26,8 @@
 #include "config.h"
 #include "DOMCache.h"
 
-#include "AbstractEventLoop.h"
 #include "CacheQueryOptions.h"
+#include "EventLoop.h"
 #include "FetchResponse.h"
 #include "HTTPParsers.h"
 #include "JSFetchRequest.h"
index 603e93f..c3d7177 100644 (file)
@@ -26,9 +26,9 @@
 #include "config.h"
 #include "DOMCacheStorage.h"
 
-#include "AbstractEventLoop.h"
 #include "CacheQueryOptions.h"
 #include "ClientOrigin.h"
+#include "EventLoop.h"
 #include "JSDOMCache.h"
 #include "JSFetchResponse.h"
 #include "ScriptExecutionContext.h"
index 1d81b35..da19bbf 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
-#include "AbstractEventLoop.h"
 #include "CDM.h"
 #include "CDMInstance.h"
 #include "DOMPromiseProxy.h"
 #include "Document.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "Logging.h"
 #include "MediaKeyMessageEvent.h"
index 6b1fd35..c624e53 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
-#include "AbstractEventLoop.h"
 #include "CDM.h"
 #include "CDMClient.h"
 #include "CDMInstance.h"
+#include "EventLoop.h"
 #include "JSDOMPromiseDeferred.h"
 #include "Logging.h"
 #include "MediaKeySession.h"
index 5ba2eed..3b6f743 100644 (file)
@@ -28,8 +28,8 @@
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
-#include "AbstractEventLoop.h"
 #include "Document.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "Page.h"
 #include "SecurityOriginData.h"
index 892752a..585ff5e 100644 (file)
@@ -880,6 +880,7 @@ dom/Event.cpp
 dom/EventContext.cpp
 dom/EventDispatcher.cpp
 dom/EventListenerMap.cpp
+dom/EventLoop.cpp
 dom/EventNames.cpp
 dom/EventPath.cpp
 dom/EventTarget.cpp
index ac69613..840c2b0 100644 (file)
                46EF142C1F97B7D800C2A524 /* ServiceWorkerClients.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EF14221F97B7BA00C2A524 /* ServiceWorkerClients.h */; };
                46EF142D1F97B7D800C2A524 /* ServiceWorkerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EF14241F97B7BA00C2A524 /* ServiceWorkerClient.h */; };
                46EFAF121E5FB9F100E7F34B /* LowPowerModeNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EFAF101E5FB9E100E7F34B /* LowPowerModeNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               46F02A1A23737F8300106A64 /* AbstractEventLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B0ABCA123679AB300B45085 /* AbstractEventLoop.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46F02A1A23737F8300106A64 /* EventLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B0ABCA123679AB300B45085 /* EventLoop.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; };
                490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */; settings = {ATTRIBUTES = (Private, ); }; };
                49291E4B134172C800E753DE /* ImageRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 49291E4A134172C800E753DE /* ImageRenderingMode.h */; };
                9B098BE01F3D673D002DD562 /* JSDataTransferItemList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDataTransferItemList.h; sourceTree = "<group>"; };
                9B098BE61F3D6AF6002DD562 /* JSStringCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStringCallback.cpp; sourceTree = "<group>"; };
                9B098BE71F3D6AF6002DD562 /* JSStringCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringCallback.h; sourceTree = "<group>"; };
-               9B0ABCA123679AB300B45085 /* AbstractEventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractEventLoop.h; sourceTree = "<group>"; };
+               9B0ABCA123679AB300B45085 /* EventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventLoop.h; sourceTree = "<group>"; };
                9B0ABCA323679ACF00B45085 /* WorkerEventLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerEventLoop.cpp; sourceTree = "<group>"; };
                9B0ABCA423679ACF00B45085 /* WorkerEventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerEventLoop.h; sourceTree = "<group>"; };
                9B0ABCAC236BB40A00B45085 /* TaskSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TaskSource.h; sourceTree = "<group>"; };
                9B864F01234C028A006D10EB /* IdleRequestOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = IdleRequestOptions.idl; sourceTree = "<group>"; };
                9B864F05234C0893006D10EB /* IdleCallbackController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IdleCallbackController.h; sourceTree = "<group>"; };
                9B864F07234C08A3006D10EB /* IdleCallbackController.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IdleCallbackController.cpp; sourceTree = "<group>"; };
+               9B91DCCC2383792D000EEE0F /* EventLoop.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EventLoop.cpp; sourceTree = "<group>"; };
                9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderCocoa.mm; sourceTree = "<group>"; };
                9B9CADA72165DC7600E8D858 /* JSMutationRecordCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSMutationRecordCustom.cpp; sourceTree = "<group>"; };
                9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogicalSelectionOffsetCaches.h; sourceTree = "<group>"; };
                                7CD0E2BD1F80A56E0016A4CE /* AbortSignal.cpp */,
                                7CD0E2BC1F80A56E0016A4CE /* AbortSignal.h */,
                                7CD0E2BE1F80A56E0016A4CE /* AbortSignal.idl */,
-                               9B0ABCA123679AB300B45085 /* AbstractEventLoop.h */,
                                7C5222971E1DAE16002CB8F7 /* ActiveDOMCallback.cpp */,
                                7C5222981E1DAE16002CB8F7 /* ActiveDOMCallback.h */,
                                7CD0BA021B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.cpp */,
                                85AFA7410AAF298400E84305 /* EventListener.idl */,
                                AD4495F1141FC08900541EDF /* EventListenerMap.cpp */,
                                AD4495F2141FC08900541EDF /* EventListenerMap.h */,
+                               9B91DCCC2383792D000EEE0F /* EventLoop.cpp */,
+                               9B0ABCA123679AB300B45085 /* EventLoop.h */,
                                83FE7CA31DA9F1650037237C /* EventModifierInit.h */,
                                83FE7CA61DA9F1660037237C /* EventModifierInit.idl */,
                                939885C108B7E3D100E707C4 /* EventNames.cpp */,
                                7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */,
                                7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */,
                                46B95195207D633400A7D2DD /* AbstractDOMWindow.h in Headers */,
-                               46F02A1A23737F8300106A64 /* AbstractEventLoop.h in Headers */,
                                46B95196207D633A00A7D2DD /* AbstractFrame.h in Headers */,
                                F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */,
                                41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */,
                                CE057FA61220731100A476D5 /* DocumentMarkerController.h in Headers */,
                                BCCFBAE80B5152ED0001F1D7 /* DocumentParser.h in Headers */,
                                1D2F8E03234474EF00993B68 /* DocumentPictureInPicture.h in Headers */,
-                               4A4F48AA16B0DFC000EDBB29 /* StyleScopeRuleSets.h in Headers */,
                                AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */,
                                6BDB5DC2227BD3B800919770 /* DocumentStorageAccess.h in Headers */,
                                0B90561A0F2578BF0095FF6A /* DocumentThreadableLoader.h in Headers */,
                                970B728A144FFAC600F00A37 /* EventInterfaces.h in Headers */,
                                935FBC4509BA00B900E230B1 /* EventListener.h in Headers */,
                                AD4495F4141FC08900541EDF /* EventListenerMap.h in Headers */,
+                               46F02A1A23737F8300106A64 /* EventLoop.h in Headers */,
                                83FE7CA81DA9F1B60037237C /* EventModifierInit.h in Headers */,
                                939885C408B7E3D100E707C4 /* EventNames.h in Headers */,
                                9B714E211C91166900AC0E92 /* EventPath.h in Headers */,
                                E4946EAF156E64DD00D3297F /* StyleRuleImport.h in Headers */,
                                0F94F37E23661626003AA5C7 /* StyleRuleType.h in Headers */,
                                E461D65F1BB0C80D00CB5645 /* StyleScope.h in Headers */,
+                               4A4F48AA16B0DFC000EDBB29 /* StyleScopeRuleSets.h in Headers */,
                                F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */,
                                9D6380101AF173220031A15C /* StyleSelfAlignmentData.h in Headers */,
                                E47A3AC61C5EAC9D00CCBFA7 /* StyleSharingResolver.h in Headers */,
index b3f746d..cdcde36 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "WebAnimation.h"
 
-#include "AbstractEventLoop.h"
 #include "AnimationEffect.h"
 #include "AnimationPlaybackEvent.h"
 #include "AnimationTimeline.h"
@@ -34,6 +33,7 @@
 #include "DeclarativeAnimation.h"
 #include "Document.h"
 #include "DocumentTimeline.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "InspectorInstrumentation.h"
 #include "JSWebAnimation.h"
index c563a26..23a1a4c 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "AbstractEventLoop.h"
+#include "EventLoop.h"
 #include "ExceptionOr.h"
 #include "JSDOMConvert.h"
 #include "JSDOMGuardedObject.h"
index 27ff175..c005ff4 100644 (file)
@@ -26,9 +26,9 @@
 #include "config.h"
 #include "FontFaceSet.h"
 
-#include "AbstractEventLoop.h"
 #include "DOMPromiseProxy.h"
 #include "Document.h"
+#include "EventLoop.h"
 #include "FontFace.h"
 #include "FrameLoader.h"
 #include "JSDOMBinding.h"
index 82f3458..4b33039 100644 (file)
@@ -27,8 +27,8 @@
 #include "config.h"
 #include "ActiveDOMObject.h"
 
-#include "AbstractEventLoop.h"
 #include "Document.h"
+#include "EventLoop.h"
 #include "ScriptExecutionContext.h"
 
 namespace WebCore {
index 31436cb..47ddb9e 100644 (file)
@@ -88,7 +88,7 @@ class InputCursor;
 
 namespace WebCore {
 
-class AbstractEventLoop;
+class EventLoop;
 class ApplicationStateChangeListener;
 class AXObjectCache;
 class Attr;
diff --git a/Source/WebCore/dom/EventLoop.cpp b/Source/WebCore/dom/EventLoop.cpp
new file mode 100644 (file)
index 0000000..b22eb2a
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EventLoop.h"
+
+namespace WebCore {
+
+void EventLoop::queueTask(std::unique_ptr<EventLoopTask>&& task)
+{
+    ASSERT(task->group());
+    ASSERT(isContextThread());
+    scheduleToRunIfNeeded();
+    m_tasks.append(WTFMove(task));
+}
+
+void EventLoop::resumeGroup(EventLoopTaskGroup& group)
+{
+    ASSERT(isContextThread());
+    if (!m_groupsWithSuspenedTasks.contains(group))
+        return;
+    scheduleToRunIfNeeded();
+}
+
+void EventLoop::stopGroup(EventLoopTaskGroup& group)
+{
+    ASSERT(isContextThread());
+    m_tasks.removeAllMatching([&group] (auto& task) {
+        return group.matchesTask(*task);
+    });
+}
+
+void EventLoop::scheduleToRunIfNeeded()
+{
+    if (m_isScheduledToRun)
+        return;
+    m_isScheduledToRun = true;
+    scheduleToRun();
+}
+
+void EventLoop::run()
+{
+    m_isScheduledToRun = false;
+    if (m_tasks.isEmpty())
+        return;
+
+    auto tasks = std::exchange(m_tasks, { });
+    m_groupsWithSuspenedTasks.clear();
+    Vector<std::unique_ptr<EventLoopTask>> remainingTasks;
+    for (auto& task : tasks) {
+        auto* group = task->group();
+        if (!group || group->isStoppedPermanently())
+            continue;
+
+        if (group->isSuspended()) {
+            m_groupsWithSuspenedTasks.add(group);
+            remainingTasks.append(WTFMove(task));
+            continue;
+        }
+
+        task->execute();
+    }
+    for (auto& task : m_tasks)
+        remainingTasks.append(WTFMove(task));
+    m_tasks = WTFMove(remainingTasks);
+}
+
+void EventLoop::clearAllTasks()
+{
+    m_tasks.clear();
+    m_groupsWithSuspenedTasks.clear();
+}
+
+void EventLoopTaskGroup::queueTask(std::unique_ptr<EventLoopTask>&& task)
+{
+    if (m_state == State::Stopped || !m_eventLoop)
+        return;
+    ASSERT(task->group() == this);
+    m_eventLoop->queueTask(WTFMove(task));
+}
+
+class EventLoopFunctionDispatchTask : public EventLoopTask {
+public:
+    EventLoopFunctionDispatchTask(TaskSource source, EventLoopTaskGroup& group, EventLoop::TaskFunction&& function)
+        : EventLoopTask(source, group)
+        , m_function(WTFMove(function))
+    {
+    }
+
+    void execute() final { m_function(); }
+
+private:
+    EventLoop::TaskFunction m_function;
+};
+
+void EventLoopTaskGroup::queueTask(TaskSource source, EventLoop::TaskFunction&& function)
+{
+    return queueTask(makeUnique<EventLoopFunctionDispatchTask>(source, *this, WTFMove(function)));
+}
+
+} // namespace WebCore
similarity index 85%
rename from Source/WebCore/dom/AbstractEventLoop.h
rename to Source/WebCore/dom/EventLoop.h
index 157b819..52fade4 100644 (file)
@@ -59,9 +59,9 @@ private:
 };
 
 // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop
-class AbstractEventLoop : public RefCounted<AbstractEventLoop>, public CanMakeWeakPtr<AbstractEventLoop> {
+class EventLoop : public RefCounted<EventLoop>, public CanMakeWeakPtr<EventLoop> {
 public:
-    virtual ~AbstractEventLoop() = default;
+    virtual ~EventLoop() = default;
 
     typedef Function<void ()> TaskFunction;
     void queueTask(std::unique_ptr<EventLoopTask>&&);
@@ -70,7 +70,7 @@ public:
     void stopGroup(EventLoopTaskGroup&);
 
 protected:
-    AbstractEventLoop() = default;
+    EventLoop() = default;
     void run();
     void clearAllTasks();
 
@@ -90,7 +90,7 @@ class EventLoopTaskGroup : public CanMakeWeakPtr<EventLoopTaskGroup> {
     WTF_MAKE_FAST_ALLOCATED;
 
 public:
-    EventLoopTaskGroup(AbstractEventLoop& eventLoop)
+    EventLoopTaskGroup(EventLoop& eventLoop)
         : m_eventLoop(makeWeakPtr(eventLoop))
     {
     }
@@ -113,7 +113,7 @@ public:
         ASSERT(m_state != State::Stopped);
         m_state = State::Suspended;
         // We don't remove suspended tasks to preserve the ordering.
-        // AbstractEventLoop::run checks whether each task's group is suspended or not.
+        // EventLoop::run checks whether each task's group is suspended or not.
     }
 
     void resume()
@@ -127,20 +127,13 @@ public:
     bool isStoppedPermanently() { return m_state == State::Stopped; }
     bool isSuspended() { return m_state == State::Suspended; }
 
-    void queueTask(std::unique_ptr<EventLoopTask>&& task)
-    {
-        if (m_state == State::Stopped || !m_eventLoop)
-            return;
-        ASSERT(task->group() == this);
-        m_eventLoop->queueTask(WTFMove(task));
-    }
-
-    WEBCORE_EXPORT void queueTask(TaskSource, AbstractEventLoop::TaskFunction&&);
+    void queueTask(std::unique_ptr<EventLoopTask>&&);
+    WEBCORE_EXPORT void queueTask(TaskSource, EventLoop::TaskFunction&&);
 
 private:
     enum class State : uint8_t { Running, Suspended, Stopped };
 
-    WeakPtr<AbstractEventLoop> m_eventLoop;
+    WeakPtr<EventLoop> m_eventLoop;
     State m_state { State::Running };
 };
 
index 9cce2c6..fbbacd5 100644 (file)
@@ -53,7 +53,7 @@ class ScriptCallStack;
 
 namespace WebCore {
 
-class AbstractEventLoop;
+class EventLoop;
 class CachedScript;
 class DatabaseContext;
 class EventQueue;
index 314662d..90fe346 100644 (file)
@@ -59,38 +59,6 @@ WindowEventLoop::~WindowEventLoop()
     RELEASE_ASSERT(didRemove);
 }
 
-void AbstractEventLoop::queueTask(std::unique_ptr<EventLoopTask>&& task)
-{
-    ASSERT(task->group());
-    ASSERT(isContextThread());
-    scheduleToRunIfNeeded();
-    m_tasks.append(WTFMove(task));
-}
-
-void AbstractEventLoop::resumeGroup(EventLoopTaskGroup& group)
-{
-    ASSERT(isContextThread());
-    if (!m_groupsWithSuspenedTasks.contains(group))
-        return;
-    scheduleToRunIfNeeded();
-}
-
-void AbstractEventLoop::stopGroup(EventLoopTaskGroup& group)
-{
-    ASSERT(isContextThread());
-    m_tasks.removeAllMatching([&group] (auto& task) {
-        return group.matchesTask(*task);
-    });
-}
-
-void AbstractEventLoop::scheduleToRunIfNeeded()
-{
-    if (m_isScheduledToRun)
-        return;
-    m_isScheduledToRun = true;
-    scheduleToRun();
-}
-
 void WindowEventLoop::scheduleToRun()
 {
     callOnMainThread([eventLoop = makeRef(*this)] () {
@@ -103,56 +71,4 @@ bool WindowEventLoop::isContextThread() const
     return isMainThread();
 }
 
-void AbstractEventLoop::run()
-{
-    m_isScheduledToRun = false;
-    if (m_tasks.isEmpty())
-        return;
-
-    auto tasks = std::exchange(m_tasks, { });
-    m_groupsWithSuspenedTasks.clear();
-    Vector<std::unique_ptr<EventLoopTask>> remainingTasks;
-    for (auto& task : tasks) {
-        auto* group = task->group();
-        if (!group || group->isStoppedPermanently())
-            continue;
-
-        if (group->isSuspended()) {
-            m_groupsWithSuspenedTasks.add(group);
-            remainingTasks.append(WTFMove(task));
-            continue;
-        }
-
-        task->execute();
-    }
-    for (auto& task : m_tasks)
-        remainingTasks.append(WTFMove(task));
-    m_tasks = WTFMove(remainingTasks);
-}
-
-void AbstractEventLoop::clearAllTasks()
-{
-    m_tasks.clear();
-    m_groupsWithSuspenedTasks.clear();
-}
-
-class EventLoopFunctionDispatchTask : public EventLoopTask {
-public:
-    EventLoopFunctionDispatchTask(TaskSource source, EventLoopTaskGroup& group, AbstractEventLoop::TaskFunction&& function)
-        : EventLoopTask(source, group)
-        , m_function(WTFMove(function))
-    {
-    }
-
-    void execute() final { m_function(); }
-
-private:
-    AbstractEventLoop::TaskFunction m_function;
-};
-
-void EventLoopTaskGroup::queueTask(TaskSource source, AbstractEventLoop::TaskFunction&& function)
-{
-    return queueTask(makeUnique<EventLoopFunctionDispatchTask>(source, *this, WTFMove(function)));
-}
-
 } // namespace WebCore
index 7343ea0..f633464 100644 (file)
@@ -25,8 +25,8 @@
 
 #pragma once
 
-#include "AbstractEventLoop.h"
 #include "DocumentIdentifier.h"
+#include "EventLoop.h"
 #include "RegistrableDomain.h"
 #include <wtf/HashSet.h>
 
@@ -35,7 +35,7 @@ namespace WebCore {
 class Document;
 
 // https://html.spec.whatwg.org/multipage/webappapis.html#window-event-loop
-class WindowEventLoop final : public AbstractEventLoop {
+class WindowEventLoop final : public EventLoop {
 public:
     static Ref<WindowEventLoop> ensureForRegistrableDomain(const RegistrableDomain&);
 
index 53f5b3d..02925c3 100644 (file)
@@ -31,7 +31,7 @@
 #include "config.h"
 #include "FileReader.h"
 
-#include "AbstractEventLoop.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "File.h"
 #include "Logging.h"
index 382e47d..244d191 100644 (file)
@@ -28,7 +28,6 @@
 #include "Internals.h"
 
 #include "AXObjectCache.h"
-#include "AbstractEventLoop.h"
 #include "ActiveDOMCallbackMicrotask.h"
 #include "ActivityState.h"
 #include "AnimationTimeline.h"
@@ -71,6 +70,7 @@
 #include "Element.h"
 #include "EventHandler.h"
 #include "EventListener.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "ExtendableEvent.h"
 #include "ExtensionStyleSheets.h"
index fac0fff..9063f94 100644 (file)
 
 #pragma once
 
-#include "AbstractEventLoop.h"
 #include "ActiveDOMObject.h"
+#include "EventLoop.h"
 
 namespace WebCore {
 
 class WorkerGlobalScope;
 class WorkletGlobalScope;
 
-class WorkerEventLoop final : public AbstractEventLoop, private ContextDestructionObserver {
+class WorkerEventLoop final : public EventLoop, private ContextDestructionObserver {
 public:
     // Explicitly take WorkerGlobalScope and WorkletGlobalScope for documentation purposes.
     static Ref<WorkerEventLoop> create(WorkerGlobalScope&);
index 39a71d8..d4c6324 100644 (file)
 
 #if ENABLE(SERVICE_WORKER)
 
-#include "AbstractEventLoop.h"
 #include "DOMPromiseProxy.h"
 #include "Document.h"
 #include "Event.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "Exception.h"
 #include "IDLTypes.h"