Changeset 252723 in webkit
- Timestamp:
- Nov 20, 2019, 5:47:56 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252718 r252723 1 2019-11-19 Ryosuke Niwa <rniwa@webkit.org> 2 3 MicrotaskQueue should be accessed via EventLoop 4 https://bugs.webkit.org/show_bug.cgi?id=204397 5 6 Reviewed by Antti Koivisto. 7 8 This patch refactors the existing code so that a microtask is always queued via EventLoopTaskGroup. 9 It preserves all other (broken) semantics and behavior like all origins sharing a single microtask queue. 10 11 The singleton MicrotaskQueue for the main thread has been moved from MicrotaskQueue::mainThreadQueue 12 to WindowEventLoop, and an instance of MicrotaskQueue for each worker has been moved from WorkerGlobalScope 13 to WorkerEventLoop. 14 15 * animation/DocumentTimeline.cpp: 16 (WebCore::DocumentTimeline::internalUpdateAnimationsAndSendEvents): 17 * animation/WebAnimation.cpp: 18 (WebCore::WebAnimation::updateFinishedState): 19 * bindings/js/JSDOMGlobalObjectTask.cpp: 20 (WebCore::JSGlobalObjectTask::JSGlobalObjectTask): 21 * bindings/js/JSDOMWindowBase.cpp: 22 (WebCore::JSDOMWindowBase::queueMicrotaskToEventLoop): Renamed from queueTaskToEventLoop. 23 * bindings/js/JSDOMWindowBase.h: 24 * bindings/js/JSExecState.cpp: 25 (WebCore::JSExecState::didLeaveScriptContext): 26 * bindings/js/JSRemoteDOMWindowBase.cpp: 27 * bindings/js/JSWorkerGlobalScopeBase.cpp: 28 (WebCore::JSWorkerGlobalScopeBase::queueMicrotaskToEventLoop): Renamed from queueTaskToEventLoop. 29 * bindings/js/JSWorkerGlobalScopeBase.h: 30 * bindings/js/JSWorkletGlobalScopeBase.cpp: 31 * bindings/js/JSWorkletGlobalScopeBase.h: 32 * dom/CustomElementReactionQueue.cpp: 33 (WebCore::BackupElementQueueMicrotask): Deleted. 34 (WebCore::CustomElementReactionQueue::enqueueElementOnAppropriateElementQueue): 35 (WebCore::CustomElementReactionQueue::ensureBackupQueue): 36 * dom/CustomElementReactionQueue.h: 37 * dom/Document.cpp: 38 (WebCore::Document::finishedParsing): 39 * dom/DocumentStorageAccess.cpp: 40 (WebCore::DocumentStorageAccess::requestStorageAccess): 41 * dom/EventLoop.cpp: 42 (WebCore::EventLoop::queueMicrotask): Added. 43 (WebCore::EventLoop::performMicrotaskCheckpoint): Added. 44 (WebCore::EventLoopTaskGroup::queueMicrotaskCallback): Added. 45 (WebCore::EventLoopTaskGroup::queueMicrotask): Added. 46 (WebCore::EventLoopTaskGroup::performMicrotaskCheckpoint): Added. 47 * dom/EventLoop.h: 48 (WebCore::EventLoopTaskGroup::microtaskQueue): 49 * dom/Microtasks.cpp: 50 (WebCore::MicrotaskQueue::mainThreadQueue): Deleted. 51 (WebCore::MicrotaskQueue::contextQueue): Deleted. 52 * dom/Microtasks.h: 53 * dom/MutationObserver.cpp: 54 (WebCore::MutationObserverMicrotask): Deleted. 55 (WebCore::MutationObserver::queueMutationObserverCompoundMicrotask): Made this a member function 56 so that it can call notifyMutationObservers in its lambda. 57 (WebCore::MutationObserver::enqueueMutationRecord): 58 (WebCore::MutationObserver::enqueueSlotChangeEvent): 59 (WebCore::MutationObserver::setHasTransientRegistration): 60 * dom/MutationObserver.h: 61 * dom/MutationObserverRegistration.cpp: 62 (WebCore::MutationObserverRegistration::observedSubtreeNodeWillDetach): 63 * dom/WindowEventLoop.cpp: 64 (WebCore::WindowEventLoop::microtaskQueue): 65 * dom/WindowEventLoop.h: 66 * html/parser/HTMLDocumentParser.cpp: 67 (WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): 68 * html/parser/HTMLScriptRunner.cpp: 69 (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): 70 (WebCore::HTMLScriptRunner::runScript): 71 * inspector/agents/InspectorCanvasAgent.cpp: 72 (WebCore::InspectorCanvasAgent::recordCanvasAction): 73 * testing/Internals.cpp: 74 (WebCore::Internals::queueMicroTask): 75 * workers/WorkerEventLoop.cpp: 76 (WebCore::WorkerEventLoop::~WorkerEventLoop): 77 (WebCore::WorkerEventLoop::microtaskQueue): 78 (WebCore::WorkerEventLoop::clearMicrotaskQueue): 79 * workers/WorkerEventLoop.h: 80 * workers/WorkerGlobalScope.cpp: 81 (WebCore::WorkerGlobalScope::WorkerGlobalScope): 82 (WebCore::WorkerGlobalScope::prepareForTermination): 83 * workers/WorkerGlobalScope.h: 84 (WebCore::WorkerGlobalScope::microtaskQueue const): Deleted. 85 1 86 2019-11-20 Wenson Hsieh <wenson_hsieh@apple.com> 2 87 -
trunk/Source/WebCore/animation/DocumentTimeline.cpp
r252527 r252723 33 33 #include "DeclarativeAnimation.h" 34 34 #include "Document.h" 35 #include "EventLoop.h" 35 36 #include "EventNames.h" 36 37 #include "GraphicsLayer.h" … … 389 390 390 391 // 3. Perform a microtask checkpoint. 391 MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint(); 392 if (auto document = makeRefPtr(this->document())) 393 document->eventLoop().performMicrotaskCheckpoint(); 392 394 393 395 // 4. Let events to dispatch be a copy of doc's pending animation event queue. -
trunk/Source/WebCore/animation/WebAnimation.cpp
r252658 r252723 797 797 // is already a microtask queued to run those steps for animation. 798 798 m_finishNotificationStepsMicrotaskPending = true; 799 MicrotaskQueue::mainThreadQueue().append(makeUnique<VoidMicrotask>([this, protectedThis = makeRef(*this)] () { 800 if (m_finishNotificationStepsMicrotaskPending) { 801 m_finishNotificationStepsMicrotaskPending = false; 802 finishNotificationSteps(); 803 } 804 })); 799 if (auto* context = scriptExecutionContext()) { 800 context->eventLoop().queueMicrotask([this, protectedThis = makeRef(*this)] { 801 if (m_finishNotificationStepsMicrotaskPending) { 802 m_finishNotificationStepsMicrotaskPending = false; 803 finishNotificationSteps(); 804 } 805 }); 806 } 805 807 } 806 808 } -
trunk/Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp
r251425 r252723 39 39 class JSGlobalObjectCallback final : public RefCounted<JSGlobalObjectCallback>, private ActiveDOMCallback { 40 40 public: 41 static Ref<JSGlobalObjectCallback> create(JSDOMGlobalObject& globalObject, Ref< Microtask>&& task)41 static Ref<JSGlobalObjectCallback> create(JSDOMGlobalObject& globalObject, Ref<JSC::Microtask>&& task) 42 42 { 43 43 return adoptRef(*new JSGlobalObjectCallback(globalObject, WTFMove(task))); … … 65 65 66 66 private: 67 JSGlobalObjectCallback(JSDOMGlobalObject& globalObject, Ref< Microtask>&& task)67 JSGlobalObjectCallback(JSDOMGlobalObject& globalObject, Ref<JSC::Microtask>&& task) 68 68 : ActiveDOMCallback { globalObject.scriptExecutionContext() } 69 69 , m_globalObject { globalObject.vm(), &globalObject } … … 73 73 74 74 Strong<JSDOMGlobalObject> m_globalObject; 75 Ref< Microtask> m_task;75 Ref<JSC::Microtask> m_task; 76 76 }; 77 77 78 JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject& globalObject, Ref< Microtask>&& task)78 JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject& globalObject, Ref<JSC::Microtask>&& task) 79 79 : ScriptExecutionContext::Task({ }) 80 80 { -
trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp
r251691 r252723 30 30 #include "DOMWindow.h" 31 31 #include "Document.h" 32 #include "EventLoop.h" 32 33 #include "FetchResponse.h" 33 34 #include "Frame.h" … … 71 72 &shouldInterruptScript, 72 73 &javaScriptRuntimeFlags, 73 &queue TaskToEventLoop,74 &queueMicrotaskToEventLoop, 74 75 &shouldInterruptScriptBeforeTimeout, 75 76 &moduleLoaderImportModule, … … 205 206 } 206 207 207 void JSDOMWindowBase::queue TaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task)208 void JSDOMWindowBase::queueMicrotaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task) 208 209 { 209 210 JSDOMWindowBase& thisObject = static_cast<JSDOMWindowBase&>(object); 210 211 211 212 auto callback = JSMicrotaskCallback::create(thisObject, WTFMove(task)); 212 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(MicrotaskQueue::mainThreadQueue(), *thisObject.scriptExecutionContext(), [callback = WTFMove(callback)]() mutable { 213 auto& eventLoop = thisObject.scriptExecutionContext()->eventLoop(); 214 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *thisObject.scriptExecutionContext(), [callback = WTFMove(callback)]() mutable { 213 215 callback->call(); 214 216 }); 215 216 MicrotaskQueue::mainThreadQueue().append(WTFMove(microtask)); 217 eventLoop.queueMicrotaskCallback(WTFMove(microtask)); 217 218 } 218 219 -
trunk/Source/WebCore/bindings/js/JSDOMWindowBase.h
r251691 r252723 78 78 static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*); 79 79 static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*); 80 static void queue TaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&);80 static void queueMicrotaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&); 81 81 82 82 void printErrorMessage(const String&) const; -
trunk/Source/WebCore/bindings/js/JSExecState.cpp
r251425 r252723 27 27 #include "JSExecState.h" 28 28 29 #include "EventLoop.h" 29 30 #include "Microtasks.h" 30 31 #include "RejectedPromiseTracker.h" … … 40 41 if (!context) 41 42 return; 42 MicrotaskQueue::contextQueue(*context).performMicrotaskCheckpoint();43 context->eventLoop().performMicrotaskCheckpoint(); 43 44 context->ensureRejectedPromiseTracker().processQueueSoon(); 44 45 } -
trunk/Source/WebCore/bindings/js/JSRemoteDOMWindowBase.cpp
r231194 r252723 40 40 nullptr, // shouldInterruptScript 41 41 &javaScriptRuntimeFlags, 42 nullptr, // queue TaskToEventLoop42 nullptr, // queueMicrotaskToEventLoop 43 43 nullptr, // shouldInterruptScriptBeforeTimeout 44 44 nullptr, // moduleLoaderImportModule -
trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
r251425 r252723 31 31 #include "ActiveDOMCallbackMicrotask.h" 32 32 #include "DOMWrapperWorld.h" 33 #include "EventLoop.h" 33 34 #include "JSDOMGlobalObjectTask.h" 34 35 #include "JSDOMGuardedObject.h" … … 58 59 &shouldInterruptScript, 59 60 &javaScriptRuntimeFlags, 60 &queue TaskToEventLoop,61 &queueMicrotaskToEventLoop, 61 62 &shouldInterruptScriptBeforeTimeout, 62 63 nullptr, // moduleLoaderImportModule … … 131 132 } 132 133 133 void JSWorkerGlobalScopeBase::queue TaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task)134 void JSWorkerGlobalScopeBase::queueMicrotaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task) 134 135 { 135 136 JSWorkerGlobalScopeBase& thisObject = static_cast<JSWorkerGlobalScopeBase&>(object); … … 137 138 auto callback = JSMicrotaskCallback::create(thisObject, WTFMove(task)); 138 139 auto& context = thisObject.wrapped(); 139 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(context. microtaskQueue(), context, [callback = WTFMove(callback)]() mutable {140 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(context.eventLoop().microtaskQueue(), context, [callback = WTFMove(callback)]() mutable { 140 141 callback->call(); 141 142 }); 142 143 context.microtaskQueue().append(WTFMove(microtask)); 143 context.eventLoop().queueMicrotaskCallback(WTFMove(microtask)); 144 144 } 145 145 -
trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.h
r251425 r252723 70 70 static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*); 71 71 static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*); 72 static void queue TaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&);72 static void queueMicrotaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&); 73 73 74 74 void clearDOMGuardedObjects(); -
trunk/Source/WebCore/bindings/js/JSWorkletGlobalScopeBase.cpp
r251425 r252723 50 50 &shouldInterruptScript, 51 51 &javaScriptRuntimeFlags, 52 nullptr, // queue TaskToEventLoop52 nullptr, // queueMicrotaskToEventLoop 53 53 &shouldInterruptScriptBeforeTimeout, 54 54 nullptr, // moduleLoaderImportModule -
trunk/Source/WebCore/bindings/js/JSWorkletGlobalScopeBase.h
r251425 r252723 60 60 static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*); 61 61 static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*); 62 static void queue TaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&);62 static void queueMicrotaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&); 63 63 64 64 void clearDOMGuardedObjects(); -
trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp
r251425 r252723 31 31 #include "Document.h" 32 32 #include "Element.h" 33 #include "EventLoop.h" 33 34 #include "HTMLNames.h" 34 35 #include "JSCustomElementInterface.h" … … 294 295 ASSERT(element.reactionQueue()); 295 296 if (!CustomElementReactionStack::s_currentProcessingStack) { 296 auto& queue = ensureBackupQueue( );297 auto& queue = ensureBackupQueue(element.document()); 297 298 queue.add(element); 298 299 return; … … 319 320 } 320 321 321 class BackupElementQueueMicrotask final : public Microtask {322 WTF_MAKE_FAST_ALLOCATED;323 private:324 Result run() final325 {326 CustomElementReactionQueue::processBackupQueue();327 return Result::Done;328 }329 };330 331 322 static bool s_processingBackupElementQueue = false; 332 323 333 CustomElementReactionQueue::ElementQueue& CustomElementReactionQueue::ensureBackupQueue() 324 // FIXME: BackupQueue must be per event loop. 325 CustomElementReactionQueue::ElementQueue& CustomElementReactionQueue::ensureBackupQueue(Document& document) 334 326 { 335 327 if (!s_processingBackupElementQueue) { 336 328 s_processingBackupElementQueue = true; 337 MicrotaskQueue::mainThreadQueue().append(makeUnique<BackupElementQueueMicrotask>()); 329 document.eventLoop().queueMicrotask([] { 330 CustomElementReactionQueue::processBackupQueue(); 331 }); 338 332 } 339 333 return backupElementQueue(); -
trunk/Source/WebCore/dom/CustomElementReactionQueue.h
r251425 r252723 81 81 private: 82 82 static void enqueueElementOnAppropriateElementQueue(Element&); 83 static ElementQueue& ensureBackupQueue( );83 static ElementQueue& ensureBackupQueue(Document&); 84 84 static ElementQueue& backupElementQueue(); 85 85 -
trunk/Source/WebCore/dom/Document.cpp
r252667 r252723 5794 5794 if (!page() || !page()->isForSanitizingWebContent()) { 5795 5795 // FIXME: Schedule a task to fire DOMContentLoaded event instead. See webkit.org/b/82931 5796 MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();5796 eventLoop().performMicrotaskCheckpoint(); 5797 5797 } 5798 5798 -
trunk/Source/WebCore/dom/DocumentStorageAccess.cpp
r251361 r252723 32 32 #include "ChromeClient.h" 33 33 #include "Document.h" 34 #include "EventLoop.h" 34 35 #include "Frame.h" 35 36 #include "FrameLoader.h" 36 37 #include "FrameLoaderClient.h" 37 38 #include "JSDOMPromiseDeferred.h" 38 #include "Microtasks.h"39 39 #include "Page.h" 40 40 #include "RegistrableDomain.h" … … 183 183 184 184 if (shouldPreserveUserGesture) { 185 MicrotaskQueue::mainThreadQueue().append(makeUnique<VoidMicrotask>([this, weakThis] (){185 m_document.eventLoop().queueMicrotask([this, weakThis = makeWeakPtr(*this)] { 186 186 if (weakThis) 187 187 enableTemporaryTimeUserGesture(); 188 }) );188 }); 189 189 } 190 190 … … 198 198 199 199 if (shouldPreserveUserGesture) { 200 MicrotaskQueue::mainThreadQueue().append(makeUnique<VoidMicrotask>([this, weakThis = WTFMove(weakThis)] (){200 m_document.eventLoop().queueMicrotask([this, weakThis = makeWeakPtr(*this)] { 201 201 if (weakThis) 202 202 consumeTemporaryTimeUserGesture(); 203 }) );203 }); 204 204 } 205 205 }); -
trunk/Source/WebCore/dom/EventLoop.cpp
r252646 r252723 27 27 #include "EventLoop.h" 28 28 29 #include "ActiveDOMCallbackMicrotask.h" 30 #include "Microtasks.h" 31 29 32 namespace WebCore { 30 33 … … 35 38 scheduleToRunIfNeeded(); 36 39 m_tasks.append(WTFMove(task)); 40 } 41 42 void EventLoop::queueMicrotask(std::unique_ptr<Microtask>&& microtask) 43 { 44 microtaskQueue().append(WTFMove(microtask)); 45 } 46 47 void EventLoop::performMicrotaskCheckpoint() 48 { 49 microtaskQueue().performMicrotaskCheckpoint(); 37 50 } 38 51 … … 121 134 } 122 135 136 void EventLoopTaskGroup::queueMicrotaskCallback(std::unique_ptr<ActiveDOMCallbackMicrotask>&& microtask) 137 { 138 if (m_state == State::Stopped || !m_eventLoop) 139 return; 140 m_eventLoop->queueMicrotask(WTFMove(microtask)); 141 } 142 143 class VoidMicrotask final : public Microtask { 144 public: 145 explicit VoidMicrotask(Function<void()>&& function) 146 : m_function(WTFMove(function)) 147 { 148 } 149 150 private: 151 Result run() final 152 { 153 m_function(); 154 return Result::Done; 155 } 156 157 Function<void()> m_function; 158 }; 159 160 void EventLoopTaskGroup::queueMicrotask(EventLoop::TaskFunction&& function) 161 { 162 if (m_state == State::Stopped || !m_eventLoop) 163 return; 164 m_eventLoop->queueMicrotask(makeUnique<VoidMicrotask>(WTFMove(function))); 165 } 166 167 void EventLoopTaskGroup::performMicrotaskCheckpoint() 168 { 169 if (m_eventLoop) 170 m_eventLoop->performMicrotaskCheckpoint(); 171 } 172 123 173 } // namespace WebCore -
trunk/Source/WebCore/dom/EventLoop.h
r252646 r252723 35 35 namespace WebCore { 36 36 37 class ActiveDOMCallbackMicrotask; 37 38 class EventLoopTaskGroup; 38 39 class EventTarget; 40 class Microtask; 41 class MicrotaskQueue; 39 42 class ScriptExecutionContext; 40 43 … … 66 69 typedef Function<void ()> TaskFunction; 67 70 void queueTask(std::unique_ptr<EventLoopTask>&&); 71 72 // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask 73 void queueMicrotask(std::unique_ptr<Microtask>&&); 74 75 // https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint 76 void performMicrotaskCheckpoint(); 77 virtual MicrotaskQueue& microtaskQueue() = 0; 68 78 69 79 void resumeGroup(EventLoopTaskGroup&); … … 131 141 WEBCORE_EXPORT void queueTask(TaskSource, EventLoop::TaskFunction&&); 132 142 143 // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask 144 void queueMicrotask(EventLoop::TaskFunction&&); 145 MicrotaskQueue& microtaskQueue() { return m_eventLoop->microtaskQueue(); } 146 147 // FIXME: This function and ActiveDOMCallbackMicrotask should go away. 148 WEBCORE_EXPORT void queueMicrotaskCallback(std::unique_ptr<ActiveDOMCallbackMicrotask>&&); 149 150 // https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint 151 void performMicrotaskCheckpoint(); 152 133 153 private: 134 154 enum class State : uint8_t { Running, Suspended, Stopped }; -
trunk/Source/WebCore/dom/Microtasks.cpp
r246565 r252723 43 43 44 44 MicrotaskQueue::~MicrotaskQueue() = default; 45 46 MicrotaskQueue& MicrotaskQueue::mainThreadQueue()47 {48 ASSERT(isMainThread());49 static NeverDestroyed<MicrotaskQueue> queue(commonVM());50 return queue;51 }52 53 MicrotaskQueue& MicrotaskQueue::contextQueue(ScriptExecutionContext& context)54 {55 // While main thread has many ScriptExecutionContexts, WorkerGlobalScope and worker thread have56 // one on one correspondence. The lifetime of MicrotaskQueue is aligned to this semantics.57 // While main thread MicrotaskQueue is persistently held, worker's MicrotaskQueue is held by58 // WorkerGlobalScope.59 if (isMainThread())60 return mainThreadQueue();61 return downcast<WorkerGlobalScope>(context).microtaskQueue();62 }63 45 64 46 void MicrotaskQueue::append(std::unique_ptr<Microtask>&& task) -
trunk/Source/WebCore/dom/Microtasks.h
r248762 r252723 53 53 }; 54 54 55 class VoidMicrotask final : public Microtask {56 public:57 explicit VoidMicrotask(Function<void()>&& function)58 : m_function(WTFMove(function))59 {60 }61 62 private:63 Result run() final64 {65 m_function();66 return Result::Done;67 }68 69 Function<void()> m_function;70 };71 72 55 class MicrotaskQueue final { 73 56 WTF_MAKE_FAST_ALLOCATED; … … 75 58 friend class Microtask; 76 59 public: 77 WEBCORE_EXPORT static MicrotaskQueue& mainThreadQueue();78 WEBCORE_EXPORT static MicrotaskQueue& contextQueue(ScriptExecutionContext&);79 80 60 WEBCORE_EXPORT MicrotaskQueue(JSC::VM&); 81 61 WEBCORE_EXPORT ~MicrotaskQueue(); -
trunk/Source/WebCore/dom/MutationObserver.cpp
r250672 r252723 35 35 36 36 #include "Document.h" 37 #include "EventLoop.h" 37 38 #include "GCReachableRef.h" 38 39 #include "HTMLSlotElement.h" … … 159 160 } 160 161 161 static bool mutationObserverCompoundMicrotaskQueuedFlag; 162 163 class MutationObserverMicrotask final : public Microtask { 164 WTF_MAKE_FAST_ALLOCATED; 165 private: 166 Result run() final 167 { 168 MutationObserver::notifyMutationObservers(); 169 return Result::Done; 170 } 171 }; 172 173 static void queueMutationObserverCompoundMicrotask() 162 // This state must be per event loop. 163 static bool mutationObserverCompoundMicrotaskQueuedFlag = false; 164 165 void MutationObserver::queueMutationObserverCompoundMicrotask(Document& document) 174 166 { 175 167 if (mutationObserverCompoundMicrotaskQueuedFlag) 176 168 return; 177 169 mutationObserverCompoundMicrotaskQueuedFlag = true; 178 MicrotaskQueue::mainThreadQueue().append(makeUnique<MutationObserverMicrotask>()); 170 document.eventLoop().queueMicrotask([] { 171 notifyMutationObservers(); 172 }); 179 173 } 180 174 … … 183 177 ASSERT(isMainThread()); 184 178 ASSERT(mutation->target()); 179 auto document = makeRef(mutation->target()->document()); 180 185 181 m_pendingTargets.add(*mutation->target()); 186 182 m_records.append(WTFMove(mutation)); 187 183 activeMutationObservers().add(this); 188 184 189 queueMutationObserverCompoundMicrotask( );185 queueMutationObserverCompoundMicrotask(document.get()); 190 186 } 191 187 … … 196 192 signalSlotList().append(slot); 197 193 198 queueMutationObserverCompoundMicrotask( );199 } 200 201 void MutationObserver::setHasTransientRegistration( )194 queueMutationObserverCompoundMicrotask(slot.document()); 195 } 196 197 void MutationObserver::setHasTransientRegistration(Document& document) 202 198 { 203 199 ASSERT(isMainThread()); 204 200 activeMutationObservers().add(this); 205 201 206 queueMutationObserverCompoundMicrotask( );202 queueMutationObserverCompoundMicrotask(document); 207 203 } 208 204 -
trunk/Source/WebCore/dom/MutationObserver.h
r239427 r252723 41 41 namespace WebCore { 42 42 43 class Document; 43 44 class HTMLSlotElement; 44 45 class MutationCallback; … … 52 53 class MutationObserver final : public RefCounted<MutationObserver> { 53 54 WTF_MAKE_ISO_ALLOCATED(MutationObserver); 54 friend class MutationObserverMicrotask;55 55 public: 56 56 enum MutationType { … … 98 98 void observationEnded(MutationObserverRegistration&); 99 99 void enqueueMutationRecord(Ref<MutationRecord>&&); 100 void setHasTransientRegistration( );100 void setHasTransientRegistration(Document&); 101 101 bool canDeliver(); 102 102 … … 111 111 void deliver(); 112 112 113 static void queueMutationObserverCompoundMicrotask(Document&); 113 114 static void notifyMutationObservers(); 114 115 static bool validateOptions(MutationObserverOptions); -
trunk/Source/WebCore/dom/MutationObserverRegistration.cpp
r248846 r252723 66 66 67 67 node.registerTransientMutationObserver(*this); 68 m_observer->setHasTransientRegistration( );68 m_observer->setHasTransientRegistration(node.document()); 69 69 70 70 if (!m_transientRegistrationNodes) { -
trunk/Source/WebCore/dom/WindowEventLoop.cpp
r252646 r252723 27 27 #include "WindowEventLoop.h" 28 28 29 #include "CommonVM.h" 29 30 #include "Document.h" 31 #include "Microtasks.h" 30 32 31 33 namespace WebCore { … … 72 74 } 73 75 76 MicrotaskQueue& WindowEventLoop::microtaskQueue() 77 { 78 // MicrotaskQueue must be one per event loop. 79 static NeverDestroyed<MicrotaskQueue> queue(commonVM()); 80 return queue; 81 } 82 74 83 } // namespace WebCore -
trunk/Source/WebCore/dom/WindowEventLoop.h
r252646 r252723 40 40 static Ref<WindowEventLoop> ensureForRegistrableDomain(const RegistrableDomain&); 41 41 42 ~WindowEventLoop();42 virtual ~WindowEventLoop(); 43 43 44 44 private: … … 47 47 void scheduleToRun() final; 48 48 bool isContextThread() const final; 49 MicrotaskQueue& microtaskQueue() final; 49 50 50 51 RegistrableDomain m_domain; -
trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp
r248846 r252723 32 32 #include "DocumentFragment.h" 33 33 #include "DocumentLoader.h" 34 #include "EventLoop.h" 34 35 #include "Frame.h" 35 36 #include "HTMLDocument.h" … … 41 42 #include "JSCustomElementInterface.h" 42 43 #include "LinkLoader.h" 43 #include "Microtasks.h"44 44 #include "NavigationScheduler.h" 45 45 #include "ScriptElement.h" … … 217 217 ThrowOnDynamicMarkupInsertionCountIncrementer incrementer(*document()); 218 218 219 MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();219 document()->eventLoop().performMicrotaskCheckpoint(); 220 220 221 221 CustomElementReactionStack reactionStack(document()->execState()); -
trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp
r243459 r252723 30 30 #include "Element.h" 31 31 #include "Event.h" 32 #include "EventLoop.h" 32 33 #include "EventNames.h" 33 34 #include "Frame.h" … … 37 38 #include "IgnoreDestructiveWriteCountIncrementer.h" 38 39 #include "InlineClassicScript.h" 39 #include "Microtasks.h"40 40 #include "MutationObserver.h" 41 41 #include "NestingLevelIncrementer.h" … … 107 107 stopWatchingForLoad(pendingScript); 108 108 109 if (!isExecutingScript() )110 MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();109 if (!isExecutingScript() && m_document) 110 m_document->eventLoop().performMicrotaskCheckpoint(); 111 111 112 112 { … … 242 242 // unfortunately no obvious way to tell if prepareScript is going to 243 243 // execute the script before calling it. 244 if (!isExecutingScript() )245 MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();244 if (!isExecutingScript() && m_document) 245 m_document->eventLoop().performMicrotaskCheckpoint(); 246 246 247 247 InsertionPointRecord insertionPointRecord(m_host.inputStream()); -
trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp
r251630 r252723 32 32 #include "Document.h" 33 33 #include "Element.h" 34 #include "EventLoop.h" 34 35 #include "Frame.h" 35 36 #include "HTMLCanvasElement.h" … … 454 455 if (!inspectorCanvas->currentFrameHasData()) { 455 456 if (auto* scriptExecutionContext = inspectorCanvas->scriptExecutionContext()) { 456 auto& queue = MicrotaskQueue::mainThreadQueue();457 queue.append(makeUnique<ActiveDOMCallbackMicrotask>(queue, *scriptExecutionContext, [&, protectedInspectorCanvas = inspectorCanvas.copyRef()] {457 auto& eventLoop = scriptExecutionContext->eventLoop(); 458 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *scriptExecutionContext, [&, protectedInspectorCanvas = inspectorCanvas.copyRef()] { 458 459 if (auto* canvasElement = protectedInspectorCanvas->canvasElement()) { 459 460 if (canvasElement->isDescendantOf(canvasElement->document())) … … 463 464 if (canvasRenderingContext.callTracingActive()) 464 465 didFinishRecordingCanvasFrame(canvasRenderingContext); 465 })); 466 }); 467 eventLoop.queueMicrotaskCallback(WTFMove(microtask)); 466 468 } 467 469 } -
trunk/Source/WebCore/testing/Internals.cpp
r252646 r252723 4328 4328 return; 4329 4329 4330 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(MicrotaskQueue::mainThreadQueue(), *document, [document, testNumber]() { 4330 ScriptExecutionContext* context = document; 4331 auto& eventLoop = context->eventLoop(); 4332 auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *document, [document, testNumber]() { 4331 4333 document->addConsoleMessage(MessageSource::JS, MessageLevel::Debug, makeString("MicroTask #", testNumber, " has run.")); 4332 4334 }); 4333 4334 MicrotaskQueue::mainThreadQueue().append(WTFMove(microtask)); 4335 eventLoop.queueMicrotaskCallback(WTFMove(microtask)); 4335 4336 } 4336 4337 -
trunk/Source/WebCore/workers/WorkerEventLoop.cpp
r252607 r252723 27 27 #include "WorkerEventLoop.h" 28 28 29 #include "Microtasks.h" 29 30 #include "WorkerGlobalScope.h" 30 31 #include "WorkletGlobalScope.h" … … 49 50 } 50 51 52 WorkerEventLoop::~WorkerEventLoop() 53 { 54 } 55 51 56 void WorkerEventLoop::scheduleToRun() 52 57 { … … 62 67 } 63 68 69 MicrotaskQueue& WorkerEventLoop::microtaskQueue() 70 { 71 ASSERT(scriptExecutionContext()); 72 if (!m_microtaskQueue) 73 m_microtaskQueue = makeUnique<MicrotaskQueue>(scriptExecutionContext()->vm()); 74 return *m_microtaskQueue; 75 } 76 77 void WorkerEventLoop::clearMicrotaskQueue() 78 { 79 m_microtaskQueue = nullptr; 80 } 81 64 82 } // namespace WebCore 65 83 -
trunk/Source/WebCore/workers/WorkerEventLoop.h
r252646 r252723 43 43 #endif 44 44 45 virtual ~WorkerEventLoop(); 46 47 // FIXME: This should be removed once MicrotaskQueue is integrated with EventLoopTaskGroup. 48 void clearMicrotaskQueue(); 49 45 50 private: 46 51 explicit WorkerEventLoop(ScriptExecutionContext&); … … 48 53 void scheduleToRun() final; 49 54 bool isContextThread() const; 55 MicrotaskQueue& microtaskQueue() final; 56 57 std::unique_ptr<MicrotaskQueue> m_microtaskQueue; 50 58 }; 51 59 -
trunk/Source/WebCore/workers/WorkerGlobalScope.cpp
r252607 r252723 69 69 , m_script(makeUnique<WorkerScriptController>(this)) 70 70 , m_inspectorController(makeUnique<WorkerInspectorController>(*this)) 71 , m_microtaskQueue(makeUnique<MicrotaskQueue>(m_script->vm()))72 71 , m_isOnline(isOnline) 73 72 , m_shouldBypassMainWorldContentSecurityPolicy(shouldBypassMainWorldContentSecurityPolicy) … … 144 143 145 144 // MicrotaskQueue and RejectedPromiseTracker reference Heap. 146 m_microtaskQueue = nullptr; 145 if (m_eventLoop) 146 m_eventLoop->clearMicrotaskQueue(); 147 147 removeRejectedPromiseTracker(); 148 148 } -
trunk/Source/WebCore/workers/WorkerGlobalScope.h
r252607 r252723 46 46 class Crypto; 47 47 class EventLoopTaskGroup; 48 class MicrotaskQueue;49 48 class Performance; 50 49 class ScheduledAction; … … 90 89 91 90 WorkerInspectorController& inspectorController() const { return *m_inspectorController; } 92 93 MicrotaskQueue& microtaskQueue() const { return *m_microtaskQueue; }94 91 95 92 WorkerThread& thread() const { return m_thread; } … … 192 189 std::unique_ptr<WorkerScriptController> m_script; 193 190 std::unique_ptr<WorkerInspectorController> m_inspectorController; 194 std::unique_ptr<MicrotaskQueue> m_microtaskQueue;195 191 196 192 bool m_closing { false }; -
trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp
r252607 r252723 81 81 m_defaultTaskGroup->stopAndDiscardAllTasks(); 82 82 stopActiveDOMObjects(); 83 removeAllEventListeners(); 84 if (m_eventLoop) 85 m_eventLoop->clearMicrotaskQueue(); 83 86 removeRejectedPromiseTracker(); 84 removeAllEventListeners();85 87 m_script->vm().notifyNeedTermination(); 86 88 m_script = nullptr;
Note:
See TracChangeset
for help on using the changeset viewer.