Title: [252820] trunk/Source/WebCore
Revision
252820
Author
[email protected]
Date
2019-11-22 17:53:19 -0800 (Fri, 22 Nov 2019)

Log Message

Associate each microtask with a task group and remove ActiveDOMCallbackMicrotask
https://bugs.webkit.org/show_bug.cgi?id=204491

Reviewed by Antti Koivisto.

This patch associates each microtask with a EventLoopTaskGroup by making MicrotaskQueue
use EventLoopTaskGroup in place of Microtask, eliminating the latter.

This allows microtasks associated with each script execution context's test group to be
suspsned or stopped along with the script execution context without having to wrap each
microtask in ActiveDOMCallbackMicrotask, which is now redundant and therefore deleted.

No new tests since there should be no observable behavioral change here.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::queueMicrotaskToEventLoop):
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::queueMicrotaskToEventLoop):
* dom/ActiveDOMCallbackMicrotask.cpp: Removed.
* dom/ActiveDOMCallbackMicrotask.h: Removed.
* dom/EventLoop.cpp:
(WebCore::EventLoop::queueTask):
(WebCore::EventLoop::queueMicrotask):
(WebCore::EventLoopTaskGroup::queueMicrotask):
(WebCore::EventLoopTaskGroup::queueMicrotaskCallback): Deleted.
* dom/EventLoop.h:
* dom/Microtasks.cpp:
(WebCore::Microtask::removeSelfFromQueue): Deleted.
(WebCore::MicrotaskQueue::append):
(WebCore::MicrotaskQueue::remove): Deleted.
(WebCore::MicrotaskQueue::performMicrotaskCheckpoint): Like EventLoop::run, skip any task
associated with a stopped group (script execution context) and add back any task associated
with a suspened group; these are tasks which used to return Microtask::Result::KeepInQueue.
* dom/Microtasks.h:
(WebCore::Microtask): Deleted.
(WebCore::Microtask::~Microtask): Deleted.
* dom/TaskSource.h:
(WebCore::TaskSource): Added Microtask as a new task source.
* inspector/agents/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::recordCanvasAction):
* testing/Internals.cpp:
(WebCore::Internals::queueMicroTask):

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252819 => 252820)


--- trunk/Source/WebCore/ChangeLog	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/ChangeLog	2019-11-23 01:53:19 UTC (rev 252820)
@@ -1,3 +1,50 @@
+2019-11-21  Ryosuke Niwa  <[email protected]>
+
+        Associate each microtask with a task group and remove ActiveDOMCallbackMicrotask
+        https://bugs.webkit.org/show_bug.cgi?id=204491
+
+        Reviewed by Antti Koivisto.
+
+        This patch associates each microtask with a EventLoopTaskGroup by making MicrotaskQueue
+        use EventLoopTaskGroup in place of Microtask, eliminating the latter.
+
+        This allows microtasks associated with each script execution context's test group to be
+        suspsned or stopped along with the script execution context without having to wrap each
+        microtask in ActiveDOMCallbackMicrotask, which is now redundant and therefore deleted.
+
+        No new tests since there should be no observable behavioral change here.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::queueMicrotaskToEventLoop):
+        * bindings/js/JSWorkerGlobalScopeBase.cpp:
+        (WebCore::JSWorkerGlobalScopeBase::queueMicrotaskToEventLoop):
+        * dom/ActiveDOMCallbackMicrotask.cpp: Removed.
+        * dom/ActiveDOMCallbackMicrotask.h: Removed.
+        * dom/EventLoop.cpp:
+        (WebCore::EventLoop::queueTask):
+        (WebCore::EventLoop::queueMicrotask):
+        (WebCore::EventLoopTaskGroup::queueMicrotask):
+        (WebCore::EventLoopTaskGroup::queueMicrotaskCallback): Deleted.
+        * dom/EventLoop.h:
+        * dom/Microtasks.cpp:
+        (WebCore::Microtask::removeSelfFromQueue): Deleted.
+        (WebCore::MicrotaskQueue::append):
+        (WebCore::MicrotaskQueue::remove): Deleted.
+        (WebCore::MicrotaskQueue::performMicrotaskCheckpoint): Like EventLoop::run, skip any task
+        associated with a stopped group (script execution context) and add back any task associated
+        with a suspened group; these are tasks which used to return Microtask::Result::KeepInQueue.
+        * dom/Microtasks.h:
+        (WebCore::Microtask): Deleted.
+        (WebCore::Microtask::~Microtask): Deleted.
+        * dom/TaskSource.h:
+        (WebCore::TaskSource): Added Microtask as a new task source.
+        * inspector/agents/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::recordCanvasAction):
+        * testing/Internals.cpp:
+        (WebCore::Internals::queueMicroTask):
+
 2019-11-22  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Text content is not exactly rare data.

Modified: trunk/Source/WebCore/Sources.txt (252819 => 252820)


--- trunk/Source/WebCore/Sources.txt	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/Sources.txt	2019-11-23 01:53:19 UTC (rev 252820)
@@ -818,7 +818,6 @@
 dom/AbortController.cpp
 dom/AbortSignal.cpp
 dom/ActiveDOMCallback.cpp
-dom/ActiveDOMCallbackMicrotask.cpp
 dom/ActiveDOMObject.cpp
 dom/AllDescendantsCollection.cpp
 dom/AnimationEvent.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (252819 => 252820)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-11-23 01:53:19 UTC (rev 252820)
@@ -2307,7 +2307,6 @@
 		7CC69941191EC5F500AF2270 /* JSWebKitNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */; };
 		7CC9722E1F93E3360004D4CF /* SettingsBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC660991F93057800D500E9 /* SettingsBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CCEBFC01DD8F6AB002C40B8 /* SVGLengthValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE58D531DD7B09300128552 /* SVGLengthValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		7CD0BA051B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0BA031B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.h */; };
 		7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0E2B51F80A4820016A4CE /* AbortController.h */; };
 		7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0E2BC1F80A56E0016A4CE /* AbortSignal.h */; };
 		7CD494CD1A86EB1D000A87EC /* RenderAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD494CB1A86EB1D000A87EC /* RenderAttachment.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9959,8 +9958,6 @@
 		7CC6609B1F93057900D500E9 /* SettingsBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SettingsBase.cpp; sourceTree = "<group>"; };
 		7CC6993E191EC5F500AF2270 /* JSWebKitNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebKitNamespace.cpp; sourceTree = "<group>"; };
 		7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitNamespace.h; sourceTree = "<group>"; };
-		7CD0BA021B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActiveDOMCallbackMicrotask.cpp; sourceTree = "<group>"; };
-		7CD0BA031B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActiveDOMCallbackMicrotask.h; sourceTree = "<group>"; };
 		7CD0E2B51F80A4820016A4CE /* AbortController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AbortController.h; sourceTree = "<group>"; };
 		7CD0E2B61F80A4820016A4CE /* AbortController.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AbortController.cpp; sourceTree = "<group>"; };
 		7CD0E2B71F80A4820016A4CE /* AbortController.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AbortController.idl; sourceTree = "<group>"; };
@@ -27815,8 +27812,6 @@
 				7CD0E2BE1F80A56E0016A4CE /* AbortSignal.idl */,
 				7C5222971E1DAE16002CB8F7 /* ActiveDOMCallback.cpp */,
 				7C5222981E1DAE16002CB8F7 /* ActiveDOMCallback.h */,
-				7CD0BA021B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.cpp */,
-				7CD0BA031B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.h */,
 				E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */,
 				E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */,
 				E3AE6CD12252F27000C70B50 /* AllDescendantsCollection.cpp */,
@@ -28822,7 +28817,6 @@
 				A91C9FBF1B6586DE00AFFD54 /* AccessibilityTree.h in Headers */,
 				A91C9FC31B659A6700AFFD54 /* AccessibilityTreeItem.h in Headers */,
 				7C5222991E1DAE1C002CB8F7 /* ActiveDOMCallback.h in Headers */,
-				7CD0BA051B8F79C9005CEBBE /* ActiveDOMCallbackMicrotask.h in Headers */,
 				E1C4DE690EA75C1E0023CCD6 /* ActiveDOMObject.h in Headers */,
 				724EE5501DC80D7F00A91FFB /* ActivityState.h in Headers */,
 				724EE5511DC80D8400A91FFB /* ActivityStateChangeObserver.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (252819 => 252820)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -24,7 +24,6 @@
 #include "config.h"
 #include "JSDOMWindowBase.h"
 
-#include "ActiveDOMCallbackMicrotask.h"
 #include "Chrome.h"
 #include "CommonVM.h"
 #include "DOMWindow.h"
@@ -211,10 +210,9 @@
 
     auto callback = JSMicrotaskCallback::create(thisObject, WTFMove(task));
     auto& eventLoop = thisObject.scriptExecutionContext()->eventLoop();
-    auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *thisObject.scriptExecutionContext(), [callback = WTFMove(callback)]() mutable {
+    eventLoop.queueMicrotask([callback = WTFMove(callback)]() mutable {
         callback->call();
     });
-    eventLoop.queueMicrotaskCallback(WTFMove(microtask));
 }
 
 void JSDOMWindowBase::willRemoveFromWindowProxy()

Modified: trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp (252819 => 252820)


--- trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -28,7 +28,6 @@
 #include "config.h"
 #include "JSWorkerGlobalScopeBase.h"
 
-#include "ActiveDOMCallbackMicrotask.h"
 #include "DOMWrapperWorld.h"
 #include "EventLoop.h"
 #include "JSDOMGlobalObjectTask.h"
@@ -137,10 +136,9 @@
 
     auto callback = JSMicrotaskCallback::create(thisObject, WTFMove(task));
     auto& context = thisObject.wrapped();
-    auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(context.eventLoop().microtaskQueue(), context, [callback = WTFMove(callback)]() mutable {
+    context.eventLoop().queueMicrotask([callback = WTFMove(callback)]() mutable {
         callback->call();
     });
-    context.eventLoop().queueMicrotaskCallback(WTFMove(microtask));
 }
 
 JSValue toJS(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject*, WorkerGlobalScope& workerGlobalScope)

Deleted: trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp (252819 => 252820)


--- trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2015 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 "ActiveDOMCallbackMicrotask.h"
-
-namespace WebCore {
-
-ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask(MicrotaskQueue& queue, ScriptExecutionContext& scriptExecutionContext, Function<void()>&& task)
-    : ActiveDOMCallback(&scriptExecutionContext)
-    , m_queue(queue)
-    , m_task(WTFMove(task))
-{
-}
-
-ActiveDOMCallbackMicrotask::~ActiveDOMCallbackMicrotask() = default;
-
-Microtask::Result ActiveDOMCallbackMicrotask::run()
-{
-    if (!canInvokeCallback())
-        return Result::KeepInQueue;
-
-    m_task();
-    return Result::Done;
-}
-
-void ActiveDOMCallbackMicrotask::contextDestroyed()
-{
-    // NOTE: Calling the function below will cause this to be destroyed.
-    removeSelfFromQueue(m_queue);
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h (252819 => 252820)


--- trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h	2019-11-23 01:53:19 UTC (rev 252820)
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2015, 2016 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.
- */
-
-#pragma once
-
-#include "ActiveDOMCallback.h"
-#include "Microtasks.h"
-#include <wtf/Function.h>
-
-namespace WebCore {
-
-class ActiveDOMCallbackMicrotask final : public Microtask, public ActiveDOMCallback {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    WEBCORE_EXPORT ActiveDOMCallbackMicrotask(MicrotaskQueue&, ScriptExecutionContext&, WTF::Function<void ()>&&);
-    WEBCORE_EXPORT virtual ~ActiveDOMCallbackMicrotask();
-
-    Result run() override;
-
-private:
-    void contextDestroyed() override;
-
-    // FIXME: It should not be necessary to have the queue as a member. Instead, it should
-    // be accessed via the ScriptExecutionContext, which should hold a reference to the relevent
-    // queue.
-    MicrotaskQueue& m_queue;
-    WTF::Function<void ()> m_task;
-};
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/dom/EventLoop.cpp (252819 => 252820)


--- trunk/Source/WebCore/dom/EventLoop.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/EventLoop.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "EventLoop.h"
 
-#include "ActiveDOMCallbackMicrotask.h"
 #include "Microtasks.h"
 
 namespace WebCore {
@@ -33,6 +32,7 @@
 
 void EventLoop::queueTask(std::unique_ptr<EventLoopTask>&& task)
 {
+    ASSERT(task->taskSource() != TaskSource::Microtask);
     ASSERT(task->group());
     ASSERT(isContextThread());
     scheduleToRunIfNeeded();
@@ -39,8 +39,9 @@
     m_tasks.append(WTFMove(task));
 }
 
-void EventLoop::queueMicrotask(std::unique_ptr<Microtask>&& microtask)
+void EventLoop::queueMicrotask(std::unique_ptr<EventLoopTask>&& microtask)
 {
+    ASSERT(microtask->taskSource() == TaskSource::Microtask);
     microtaskQueue().append(WTFMove(microtask));
 }
 
@@ -133,35 +134,11 @@
     return queueTask(makeUnique<EventLoopFunctionDispatchTask>(source, *this, WTFMove(function)));
 }
 
-void EventLoopTaskGroup::queueMicrotaskCallback(std::unique_ptr<ActiveDOMCallbackMicrotask>&& microtask)
-{
-    if (m_state == State::Stopped || !m_eventLoop)
-        return;
-    m_eventLoop->queueMicrotask(WTFMove(microtask));
-}
-
-class VoidMicrotask final : public Microtask {
-public:
-    explicit VoidMicrotask(Function<void()>&& function)
-        : m_function(WTFMove(function))
-    {
-    }
-
-private:
-    Result run() final
-    {
-        m_function();
-        return Result::Done;
-    }
-
-    Function<void()> m_function;
-};
-
 void EventLoopTaskGroup::queueMicrotask(EventLoop::TaskFunction&& function)
 {
     if (m_state == State::Stopped || !m_eventLoop)
         return;
-    m_eventLoop->queueMicrotask(makeUnique<VoidMicrotask>(WTFMove(function)));
+    m_eventLoop->queueMicrotask(makeUnique<EventLoopFunctionDispatchTask>(TaskSource::Microtask, *this, WTFMove(function)));
 }
 
 void EventLoopTaskGroup::performMicrotaskCheckpoint()

Modified: trunk/Source/WebCore/dom/EventLoop.h (252819 => 252820)


--- trunk/Source/WebCore/dom/EventLoop.h	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/EventLoop.h	2019-11-23 01:53:19 UTC (rev 252820)
@@ -70,7 +70,7 @@
     void queueTask(std::unique_ptr<EventLoopTask>&&);
 
     // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask
-    void queueMicrotask(std::unique_ptr<Microtask>&&);
+    void queueMicrotask(std::unique_ptr<EventLoopTask>&&);
 
     // https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
     void performMicrotaskCheckpoint();
@@ -141,12 +141,9 @@
     WEBCORE_EXPORT void queueTask(TaskSource, EventLoop::TaskFunction&&);
 
     // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask
-    void queueMicrotask(EventLoop::TaskFunction&&);
+    WEBCORE_EXPORT void queueMicrotask(EventLoop::TaskFunction&&);
     MicrotaskQueue& microtaskQueue() { return m_eventLoop->microtaskQueue(); }
 
-    // FIXME: This function and ActiveDOMCallbackMicrotask should go away.
-    WEBCORE_EXPORT void queueMicrotaskCallback(std::unique_ptr<ActiveDOMCallbackMicrotask>&&);
-
     // https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
     void performMicrotaskCheckpoint();
 

Modified: trunk/Source/WebCore/dom/Microtasks.cpp (252819 => 252820)


--- trunk/Source/WebCore/dom/Microtasks.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/Microtasks.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -23,6 +23,7 @@
 #include "Microtasks.h"
 
 #include "CommonVM.h"
+#include "EventLoop.h"
 #include "WorkerGlobalScope.h"
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
@@ -30,11 +31,6 @@
 
 namespace WebCore {
 
-void Microtask::removeSelfFromQueue(MicrotaskQueue& queue)
-{
-    queue.remove(*this);
-}
-
 MicrotaskQueue::MicrotaskQueue(JSC::VM& vm)
     : m_vm(makeRef(vm))
     , m_timer(*this, &MicrotaskQueue::timerFired)
@@ -43,7 +39,7 @@
 
 MicrotaskQueue::~MicrotaskQueue() = default;
 
-void MicrotaskQueue::append(std::unique_ptr<Microtask>&& task)
+void MicrotaskQueue::append(std::unique_ptr<EventLoopTask>&& task)
 {
     m_microtaskQueue.append(WTFMove(task));
 
@@ -50,16 +46,6 @@
     m_timer.startOneShot(0_s);
 }
 
-void MicrotaskQueue::remove(const Microtask& task)
-{
-    for (size_t i = 0; i < m_microtaskQueue.size(); ++i) {
-        if (m_microtaskQueue[i].get() == &task) {
-            m_microtaskQueue.remove(i);
-            return;
-        }
-    }
-}
-
 void MicrotaskQueue::timerFired()
 {
     performMicrotaskCheckpoint();
@@ -73,18 +59,17 @@
     SetForScope<bool> change(m_performingMicrotaskCheckpoint, true);
     JSC::JSLockHolder locker(vm());
 
-    Vector<std::unique_ptr<Microtask>> toKeep;
+    Vector<std::unique_ptr<EventLoopTask>> toKeep;
     while (!m_microtaskQueue.isEmpty()) {
-        Vector<std::unique_ptr<Microtask>> queue = WTFMove(m_microtaskQueue);
+        Vector<std::unique_ptr<EventLoopTask>> queue = WTFMove(m_microtaskQueue);
         for (auto& task : queue) {
-            auto result = task->run();
-            switch (result) {
-            case Microtask::Result::Done:
-                break;
-            case Microtask::Result::KeepInQueue:
+            auto* group = task->group();
+            if (!group || group->isStoppedPermanently())
+                continue;
+            if (group->isSuspended())
                 toKeep.append(WTFMove(task));
-                break;
-            }
+            else
+                task->execute();
         }
     }
 

Modified: trunk/Source/WebCore/dom/Microtasks.h (252819 => 252820)


--- trunk/Source/WebCore/dom/Microtasks.h	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/Microtasks.h	2019-11-23 01:53:19 UTC (rev 252820)
@@ -31,47 +31,25 @@
 
 namespace WebCore {
 
-class MicrotaskQueue;
+class EventLoopTask;
 class ScriptExecutionContext;
 
-class Microtask {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    virtual ~Microtask()
-    {
-    }
-
-    enum class Result {
-        Done,
-        KeepInQueue
-    };
-
-    virtual Result run() = 0;
-
-protected:
-    void removeSelfFromQueue(MicrotaskQueue&);
-};
-
 class MicrotaskQueue final {
     WTF_MAKE_FAST_ALLOCATED;
-    friend NeverDestroyed<MicrotaskQueue>;
-    friend class Microtask;
 public:
     WEBCORE_EXPORT MicrotaskQueue(JSC::VM&);
     WEBCORE_EXPORT ~MicrotaskQueue();
 
-    WEBCORE_EXPORT void append(std::unique_ptr<Microtask>&&);
+    WEBCORE_EXPORT void append(std::unique_ptr<EventLoopTask>&&);
     WEBCORE_EXPORT void performMicrotaskCheckpoint();
 
     JSC::VM& vm() const { return m_vm.get(); }
 
 private:
-    WEBCORE_EXPORT void remove(const Microtask&);
-
     void timerFired();
 
     bool m_performingMicrotaskCheckpoint { false };
-    Vector<std::unique_ptr<Microtask>> m_microtaskQueue;
+    Vector<std::unique_ptr<EventLoopTask>> m_microtaskQueue;
     // For the main thread the VM lives forever. For workers it's lifetime is tied to our owning WorkerGlobalScope. Regardless, we retain the VM here to be safe.
     Ref<JSC::VM> m_vm;
 

Modified: trunk/Source/WebCore/dom/TaskSource.h (252819 => 252820)


--- trunk/Source/WebCore/dom/TaskSource.h	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/dom/TaskSource.h	2019-11-23 01:53:19 UTC (rev 252820)
@@ -32,6 +32,7 @@
     FileReading,
     FontLoading,
     IdleTask,
+    Microtask,
     Networking,
     PostedMessageQueue,
     UserInteraction

Modified: trunk/Source/WebCore/testing/Internals.cpp (252819 => 252820)


--- trunk/Source/WebCore/testing/Internals.cpp	2019-11-23 01:13:18 UTC (rev 252819)
+++ trunk/Source/WebCore/testing/Internals.cpp	2019-11-23 01:53:19 UTC (rev 252820)
@@ -28,7 +28,6 @@
 #include "Internals.h"
 
 #include "AXObjectCache.h"
-#include "ActiveDOMCallbackMicrotask.h"
 #include "ActivityState.h"
 #include "AnimationTimeline.h"
 #include "ApplicationCacheStorage.h"
@@ -4329,10 +4328,9 @@
 
     ScriptExecutionContext* context = document;
     auto& eventLoop = context->eventLoop();
-    auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *document, [document, testNumber]() {
+    eventLoop.queueMicrotask([document = makeRef(*document), testNumber]() {
         document->addConsoleMessage(MessageSource::JS, MessageLevel::Debug, makeString("MicroTask #", testNumber, " has run."));
     });
-    eventLoop.queueMicrotaskCallback(WTFMove(microtask));
 }
 
 #if ENABLE(CONTENT_FILTERING)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to