Title: [252212] trunk/Source/WebCore
Revision
252212
Author
[email protected]
Date
2019-11-07 15:24:35 -0800 (Thu, 07 Nov 2019)

Log Message

Port Worker to the HTML5 event loop
https://bugs.webkit.org/show_bug.cgi?id=203919

Reviewed by Ryosuke Niwa.

* dom/ActiveDOMObject.h:
* workers/Worker.cpp:
(WebCore::Worker::Worker):
(WebCore::Worker::terminate):
(WebCore::Worker::hasPendingActivity const):
(WebCore::Worker::notifyFinished):
(WebCore::Worker::dispatchEvent):
(WebCore::Worker::enqueueEvent): Deleted.
* workers/Worker.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252211 => 252212)


--- trunk/Source/WebCore/ChangeLog	2019-11-07 23:20:01 UTC (rev 252211)
+++ trunk/Source/WebCore/ChangeLog	2019-11-07 23:24:35 UTC (rev 252212)
@@ -1,5 +1,25 @@
 2019-11-07  Chris Dumez  <[email protected]>
 
+        Port Worker to the HTML5 event loop
+        https://bugs.webkit.org/show_bug.cgi?id=203919
+
+        Reviewed by Ryosuke Niwa.
+
+        * dom/ActiveDOMObject.h:
+        * workers/Worker.cpp:
+        (WebCore::Worker::Worker):
+        (WebCore::Worker::terminate):
+        (WebCore::Worker::hasPendingActivity const):
+        (WebCore::Worker::notifyFinished):
+        (WebCore::Worker::dispatchEvent):
+        (WebCore::Worker::enqueueEvent): Deleted.
+        * workers/Worker.h:
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
+        (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
+
+2019-11-07  Chris Dumez  <[email protected]>
+
         Port MessagePort to the HTML5 event loop
         https://bugs.webkit.org/show_bug.cgi?id=203960
 

Modified: trunk/Source/WebCore/dom/ActiveDOMObject.h (252211 => 252212)


--- trunk/Source/WebCore/dom/ActiveDOMObject.h	2019-11-07 23:20:01 UTC (rev 252211)
+++ trunk/Source/WebCore/dom/ActiveDOMObject.h	2019-11-07 23:24:35 UTC (rev 252212)
@@ -113,12 +113,6 @@
     bool isContextStopped() const;
     bool isAllowedToRunScript() const;
 
-protected:
-    explicit ActiveDOMObject(ScriptExecutionContext*);
-    explicit ActiveDOMObject(Document*);
-    explicit ActiveDOMObject(Document&);
-    virtual ~ActiveDOMObject();
-
     template<typename T>
     static void queueTaskKeepingObjectAlive(T& object, TaskSource source, Function<void ()>&& task)
     {
@@ -136,6 +130,12 @@
         });
     }
 
+protected:
+    explicit ActiveDOMObject(ScriptExecutionContext*);
+    explicit ActiveDOMObject(Document*);
+    explicit ActiveDOMObject(Document&);
+    virtual ~ActiveDOMObject();
+
 private:
     enum CheckedScriptExecutionContextType { CheckedScriptExecutionContext };
     ActiveDOMObject(ScriptExecutionContext*, CheckedScriptExecutionContextType);

Modified: trunk/Source/WebCore/workers/Worker.cpp (252211 => 252212)


--- trunk/Source/WebCore/workers/Worker.cpp	2019-11-07 23:20:01 UTC (rev 252211)
+++ trunk/Source/WebCore/workers/Worker.cpp	2019-11-07 23:24:35 UTC (rev 252212)
@@ -69,7 +69,6 @@
     , m_identifier("worker:" + Inspector::IdentifiersFactory::createIdentifier())
     , m_contextProxy(WorkerGlobalScopeProxy::create(*this))
     , m_runtimeFlags(runtimeFlags)
-    , m_eventQueue(GenericEventQueue::create(*this))
 {
     static bool addedListener;
     if (!addedListener) {
@@ -147,7 +146,7 @@
 void Worker::terminate()
 {
     m_contextProxy.terminateWorkerGlobalScope();
-    m_eventQueue->cancelAllEvents();
+    m_wasTerminated = true;
 }
 
 const char* Worker::activeDOMObjectName() const
@@ -178,7 +177,7 @@
 
 bool Worker::hasPendingActivity() const
 {
-    return m_contextProxy.hasPendingActivity() || ActiveDOMObject::hasPendingActivity() || m_eventQueue->hasPendingEvents();
+    return m_contextProxy.hasPendingActivity() || ActiveDOMObject::hasPendingActivity();
 }
 
 void Worker::notifyNetworkStateChange(bool isOnLine)
@@ -206,7 +205,7 @@
         return;
 
     if (m_scriptLoader->failed()) {
-        enqueueEvent(Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::Yes));
+        queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::Yes));
         return;
     }
 
@@ -216,14 +215,10 @@
     InspectorInstrumentation::scriptImported(*context, m_scriptLoader->identifier(), m_scriptLoader->script());
 }
 
-void Worker::enqueueEvent(Ref<Event>&& event)
-{
-    m_eventQueue->enqueueEvent(WTFMove(event));
-}
-
 void Worker::dispatchEvent(Event& event)
 {
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!m_eventQueue->isSuspended());
+    if (m_wasTerminated)
+        return;
 
     AbstractWorker::dispatchEvent(event);
     if (is<ErrorEvent>(event) && !event.defaultPrevented() && event.isTrusted() && scriptExecutionContext()) {

Modified: trunk/Source/WebCore/workers/Worker.h (252211 => 252212)


--- trunk/Source/WebCore/workers/Worker.h	2019-11-07 23:20:01 UTC (rev 252211)
+++ trunk/Source/WebCore/workers/Worker.h	2019-11-07 23:24:35 UTC (rev 252212)
@@ -29,7 +29,6 @@
 #include "ActiveDOMObject.h"
 #include "ContentSecurityPolicyResponseHeaders.h"
 #include "EventTarget.h"
-#include "GenericEventQueue.h"
 #include "MessagePort.h"
 #include "WorkerScriptLoaderClient.h"
 #include <_javascript_Core/RuntimeFlags.h>
@@ -68,13 +67,11 @@
 
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
 
-    void enqueueEvent(Ref<Event>&&);
+    void dispatchEvent(Event&) final;
 
 private:
     explicit Worker(ScriptExecutionContext&, JSC::RuntimeFlags, const Options&);
 
-    void dispatchEvent(Event&) final;
-
     EventTargetInterface eventTargetInterface() const final { return WorkerEventTargetInterfaceType; }
 
     void notifyNetworkStateChange(bool isOnline);
@@ -98,7 +95,8 @@
     bool m_shouldBypassMainWorldContentSecurityPolicy { false };
     bool m_isSuspendedForBackForwardCache { false };
     JSC::RuntimeFlags m_runtimeFlags;
-    UniqueRef<GenericEventQueue> m_eventQueue;
+    Deque<RefPtr<Event>> m_pendingEvents;
+    bool m_wasTerminated { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (252211 => 252212)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2019-11-07 23:20:01 UTC (rev 252211)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2019-11-07 23:24:35 UTC (rev 252212)
@@ -104,7 +104,7 @@
             return;
 
         auto ports = MessagePort::entanglePorts(context, WTFMove(message.transferredPorts));
-        workerObject->enqueueEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
+        ActiveDOMObject::queueTaskToDispatchEvent(*workerObject, TaskSource::PostedMessageQueue, MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
     });
 }
 
@@ -177,7 +177,7 @@
 
         // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
         // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
-        workerObject->enqueueEvent(ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, { }));
+        ActiveDOMObject::queueTaskToDispatchEvent(*workerObject, TaskSource::DOMManipulation, ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, { }));
     });
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to