Changeset 252824 in webkit
- Timestamp:
- Nov 22, 2019, 8:28:46 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r252724 r252824 1 2019-11-21 Ryosuke Niwa <rniwa@webkit.org> 2 3 Use the event loop instead of DocumentEventQueue and WorkerEventQueue 4 https://bugs.webkit.org/show_bug.cgi?id=204447 5 <rdar://problem/57420691> 6 7 Reviewed by Antti Koivisto. 8 9 Updated the expected result. It now fails one step head due to EventLoop getting better integrated with timers. 10 11 * web-platform-tests/requestidlecallback/callback-timeout-when-busy-expected.txt: 12 1 13 2019-11-20 Simon Fraser <simon.fraser@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/requestidlecallback/callback-timeout-when-busy-expected.txt
r251120 r252824 3 3 4 4 FAIL requestIdleCallback not scheduled when event loop is busy. assert_false: IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout expected false got true 5 FAIL requestIdleCallback scheduled with timeout when event loop is busy. assert_true: Should only have been run aftertimeout expected true got false5 FAIL requestIdleCallback scheduled with timeout when event loop is busy. assert_true: IdleDeadline.timeRemaining MUST be equal to zero if requestIdleCallback was scheduled due to a timeout expected true got false 6 6 -
trunk/Source/WebCore/ChangeLog
r252823 r252824 1 2019-11-21 Ryosuke Niwa <rniwa@webkit.org> 2 3 Use the event loop instead of DocumentEventQueue and WorkerEventQueue 4 https://bugs.webkit.org/show_bug.cgi?id=204447 5 <rdar://problem/57420691> 6 7 Reviewed by Antti Koivisto. 8 9 This patch replaces every use of DocumentEventQueue and WorkerEventQueue by the integration 10 with the event loop. 11 12 Because this changes the order by which some of the affected events fire and tasks run, 13 this patch also makes WindowEventLoop::scheduleToRun use a Timer instead of callOnMainThread 14 in order to avoid introducing new test failures. 15 16 In addition, WebSQL needed a code change to scheudle tasks via the event loop after moving 17 to the event loop as callOnMainThread could run before or after a 0s timer fires depending 18 on whether it was called during another timer or not; meaning that it could change the order 19 of operations with respect to other tasks scheduled via event loops in some cases. 20 21 Finally, added the links to various specifications where appropriate. 22 23 * Modules/indexeddb/IDBDatabase.cpp: 24 (WebCore::IDBDatabase::connectionToServerLost): 25 (WebCore::IDBDatabase::fireVersionChangeEvent): 26 * Modules/indexeddb/IDBRequest.cpp: 27 (WebCore::IDBRequest::enqueueEvent): 28 * Modules/indexeddb/IDBTransaction.cpp: 29 (WebCore::IDBTransaction::enqueueEvent): 30 (WebCore::IDBTransaction::dispatchEvent): 31 * Modules/mediastream/RTCDataChannel.cpp: 32 (WebCore::RTCDataChannel::scheduleDispatchEvent): 33 * Modules/webdatabase/Database.cpp: 34 (WebCore::Database::scheduleTransactionCallback): Schedule a task on the event loop once 35 we're in the main thread as the order of operation could change with respect to other tasks 36 scheduled via the event loop otherwise. 37 * Modules/webdatabase/SQLTransaction.cpp: 38 (WebCore::SQLTransaction::notifyDatabaseThreadIsShuttingDown): Ditto. 39 * dom/Document.cpp: 40 (WebCore::Document::visibilityStateChanged): 41 (WebCore::Document::prepareForDestruction): 42 (WebCore::Document::enqueueWindowEvent): Deleted. 43 (WebCore::Document::queueTaskToDispatchEvent): Added. 44 (WebCore::Document::enqueueDocumentEvent): Deleted. 45 (WebCore::Document::queueTaskToDispatchEventOnWindow): Added. 46 (WebCore::Document::enqueueOverflowEvent): 47 (WebCore::Document::enqueueSecurityPolicyViolationEvent): 48 (WebCore::Document::enqueueHashchangeEvent): Rewritten. Keep the target node alive until 49 the overflow event fires. 50 fired on an overflow element 51 * dom/Document.h: 52 * dom/ScriptExecutionContext.h: 53 * dom/TaskSource.h: 54 * dom/WindowEventLoop.cpp: 55 (WebCore::WindowEventLoop::WindowEventLoop): 56 (WebCore::WindowEventLoop::scheduleToRun): 57 * dom/WindowEventLoop.h: 58 * editing/FrameSelection.cpp: 59 (WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): 60 * page/DOMWindow.cpp: 61 (WebCore::DOMWindow::languagesChanged): 62 * page/PointerCaptureController.cpp: 63 (WebCore::PointerCaptureController::elementWasRemoved): 64 * page/PointerLockController.cpp: 65 (WebCore::PointerLockController::enqueueEvent): 66 * storage/StorageEventDispatcher.cpp: 67 (WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames): 68 (WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames): 69 * workers/WorkerGlobalScope.cpp: 70 (WebCore::WorkerGlobalScope::WorkerGlobalScope): 71 (WebCore::WorkerGlobalScope::eventQueue const): Deleted. 72 * workers/WorkerGlobalScope.h: 73 * worklets/WorkletGlobalScope.cpp: 74 (WebCore::WorkletGlobalScope::WorkletGlobalScope): 75 * worklets/WorkletGlobalScope.h: 76 1 77 2019-11-22 Ryosuke Niwa <rniwa@webkit.org> 2 78 -
trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
r252642 r252824 280 280 281 281 if (auto* context = scriptExecutionContext()) 282 context->eventQueue().enqueueEvent(WTFMove(errorEvent));282 queueTaskToDispatchEvent(*this, TaskSource::DatabaseAccess, WTFMove(errorEvent)); 283 283 284 284 auto closeEvent = Event::create(m_eventNames.closeEvent, Event::CanBubble::Yes, Event::IsCancelable::No); … … 286 286 287 287 if (auto* context = scriptExecutionContext()) 288 context->eventQueue().enqueueEvent(WTFMove(closeEvent));288 queueTaskToDispatchEvent(*this, TaskSource::DatabaseAccess, WTFMove(closeEvent)); 289 289 } 290 290 … … 469 469 470 470 Ref<Event> event = IDBVersionChangeEvent::create(requestIdentifier, currentVersion, requestedVersion, m_eventNames.versionchangeEvent); 471 event->setTarget(this); 472 scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event)); 471 queueTaskToDispatchEvent(*this, TaskSource::DatabaseAccess, WTFMove(event)); 473 472 } 474 473 -
trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp
r252642 r252824 291 291 return; 292 292 293 event->setTarget(this); 294 scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event)); 293 queueTaskToDispatchEvent(*this, TaskSource::DatabaseAccess, WTFMove(event)); 295 294 } 296 295 -
trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
r252642 r252824 626 626 return; 627 627 628 event->setTarget(this); 629 scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event)); 628 queueTaskToDispatchEvent(*this, TaskSource::DatabaseAccess, WTFMove(event)); 630 629 } 631 630 … … 637 636 ASSERT(scriptExecutionContext()); 638 637 ASSERT(!m_contextStopped); 639 ASSERT(event.target() == this);640 638 ASSERT(event.type() == eventNames().completeEvent || event.type() == eventNames().abortEvent); 641 639 -
trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp
r250573 r252824 231 231 return; 232 232 233 event->setTarget(this);234 scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event));233 // https://w3c.github.io/webrtc-pc/#operation 234 queueTaskToDispatchEvent(*this, TaskSource::Networking, WTFMove(event)); 235 235 } 236 236 -
trunk/Source/WebCore/Modules/webdatabase/Database.cpp
r252607 r252824 704 704 void Database::scheduleTransactionCallback(SQLTransaction* transaction) 705 705 { 706 callOnMainThread([transaction = makeRefPtr(transaction)] { 707 transaction->performPendingCallback(); 706 callOnMainThread([this, protectedThis = makeRef(*this), transaction = makeRefPtr(transaction)] { 707 m_document->eventLoop().queueTask(TaskSource::Networking, [transaction = transaction.copyRef()] { 708 transaction->performPendingCallback(); 709 }); 708 710 }); 709 711 } -
trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
r252607 r252824 129 129 { 130 130 callOnMainThread([this, protectedThis = makeRef(*this)]() mutable { 131 callErrorCallbackDueToInterruption(); 131 m_database->document().eventLoop().queueTask(TaskSource::Networking, [this, protectedThis = protectedThis.copyRef()]() mutable { 132 callErrorCallbackDueToInterruption(); 133 }); 132 134 }); 133 135 -
trunk/Source/WebCore/dom/Document.cpp
r252761 r252824 555 555 , m_constantPropertyMap(makeUnique<ConstantPropertyMap>(*this)) 556 556 , m_documentClasses(documentClasses) 557 , m_eventQueue(*this)558 557 #if ENABLE(FULLSCREEN_API) 559 558 , m_fullscreenManager { makeUniqueRef<FullscreenManager>(*this) } … … 1708 1707 void Document::visibilityStateChanged() 1709 1708 { 1710 enqueueDocumentEvent(Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 1709 // // https://w3c.github.io/page-visibility/#reacting-to-visibilitychange-changes 1710 queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 1711 1711 for (auto* client : m_visibilityStateCallbackClients) 1712 1712 client->visibilityStateChanged(); … … 2533 2533 2534 2534 stopActiveDOMObjects(); 2535 m_eventQueue.close();2536 2535 #if ENABLE(FULLSCREEN_API) 2537 2536 m_fullscreenManager->emptyEventQueue(); … … 4738 4737 } 4739 4738 4740 void Document::enqueueWindowEvent(Ref<Event>&& event) 4741 { 4742 event->setTarget(m_domWindow.get()); 4743 m_eventQueue.enqueueEvent(WTFMove(event)); 4744 } 4745 4746 void Document::enqueueDocumentEvent(Ref<Event>&& event) 4747 { 4748 event->setTarget(this); 4749 m_eventQueue.enqueueEvent(WTFMove(event)); 4739 void Document::queueTaskToDispatchEvent(TaskSource source, Ref<Event>&& event) 4740 { 4741 eventLoop().queueTask(source, [document = makeRef(*this), event = WTFMove(event)] { 4742 document->dispatchEvent(event); 4743 }); 4744 } 4745 4746 void Document::queueTaskToDispatchEventOnWindow(TaskSource source, Ref<Event>&& event) 4747 { 4748 eventLoop().queueTask(source, [this, protectedThis = makeRef(*this), event = WTFMove(event)] { 4749 if (!m_domWindow) 4750 return; 4751 m_domWindow->dispatchEvent(event); 4752 }); 4750 4753 } 4751 4754 4752 4755 void Document::enqueueOverflowEvent(Ref<Event>&& event) 4753 4756 { 4754 m_eventQueue.enqueueEvent(WTFMove(event)); 4757 // https://developer.mozilla.org/en-US/docs/Web/API/Element/overflow_event 4758 // FIXME: This event is totally unspecified. 4759 auto* target = event->target(); 4760 RELEASE_ASSERT(target); 4761 RELEASE_ASSERT(is<Node>(target)); 4762 eventLoop().queueTask(TaskSource::DOMManipulation, [protectedTarget = GCReachableRef<Node>(downcast<Node>(*target)), event = WTFMove(event)] { 4763 protectedTarget->dispatchEvent(event); 4764 }); 4755 4765 } 4756 4766 … … 6373 6383 void Document::enqueueSecurityPolicyViolationEvent(SecurityPolicyViolationEvent::Init&& eventInit) 6374 6384 { 6375 enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, WTFMove(eventInit), Event::IsTrusted::Yes));6385 queueTaskToDispatchEvent(TaskSource::DOMManipulation, SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, WTFMove(eventInit), Event::IsTrusted::Yes)); 6376 6386 } 6377 6387 6378 6388 void Document::enqueueHashchangeEvent(const String& oldURL, const String& newURL) 6379 6389 { 6380 enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL)); 6390 // FIXME: popstate event and hashchange event are supposed to fire in a single task. 6391 queueTaskToDispatchEventOnWindow(TaskSource::DOMManipulation, HashChangeEvent::create(oldURL, newURL)); 6381 6392 } 6382 6393 -
trunk/Source/WebCore/dom/Document.h
r252646 r252824 1169 1169 bool isJSExecutionForbidden() const final { return false; } 1170 1170 1171 void enqueueWindowEvent(Ref<Event>&&);1172 void enqueueDocumentEvent(Ref<Event>&&);1171 void queueTaskToDispatchEvent(TaskSource, Ref<Event>&&); 1172 void queueTaskToDispatchEventOnWindow(TaskSource, Ref<Event>&&); 1173 1173 void enqueueOverflowEvent(Ref<Event>&&); 1174 1174 void dispatchPageshowEvent(PageshowEventPersistence); … … 1176 1176 void enqueueHashchangeEvent(const String& oldURL, const String& newURL); 1177 1177 void dispatchPopstateEvent(RefPtr<SerializedScriptValue>&& stateObject); 1178 DocumentEventQueue& eventQueue() const final { return m_eventQueue; }1179 1178 1180 1179 WEBCORE_EXPORT void addMediaCanStartListener(MediaCanStartListener&); … … 1826 1825 1827 1826 RenderPtr<RenderView> m_renderView; 1828 mutable DocumentEventQueue m_eventQueue;1829 1827 1830 1828 HashSet<MediaCanStartListener*> m_mediaCanStartListeners; -
trunk/Source/WebCore/dom/ScriptExecutionContext.h
r252646 r252824 218 218 virtual Seconds domTimerAlignmentInterval(bool hasReachedMaxNestingLevel) const; 219 219 220 virtual EventQueue& eventQueue() const = 0;221 220 virtual EventTarget* errorEventTarget() = 0; 222 221 -
trunk/Source/WebCore/dom/TaskSource.h
r252820 r252824 30 30 enum class TaskSource : uint8_t { 31 31 DOMManipulation, 32 DatabaseAccess, 32 33 FileReading, 33 34 FontLoading, -
trunk/Source/WebCore/dom/WindowEventLoop.cpp
r252723 r252824 53 53 inline WindowEventLoop::WindowEventLoop(const RegistrableDomain& domain) 54 54 : m_domain(domain) 55 , m_timer(*this, &WindowEventLoop::run) 55 56 { 56 57 } … … 64 65 void WindowEventLoop::scheduleToRun() 65 66 { 66 callOnMainThread([eventLoop = makeRef(*this)] () { 67 eventLoop->run(); 68 }); 67 m_timer.startOneShot(0_s); 69 68 } 70 69 -
trunk/Source/WebCore/dom/WindowEventLoop.h
r252723 r252824 29 29 #include "EventLoop.h" 30 30 #include "RegistrableDomain.h" 31 #include "Timer.h" 31 32 #include <wtf/HashSet.h> 32 33 … … 50 51 51 52 RegistrableDomain m_domain; 53 Timer m_timer; 52 54 }; 53 55 -
trunk/Source/WebCore/editing/FrameSelection.cpp
r252546 r252824 378 378 selectFrameElementInParentIfFullySelected(); 379 379 m_frame->editor().respondToChangedSelection(oldSelection, options); 380 m_frame->document()->enqueueDocumentEvent(Event::create(eventNames().selectionchangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 380 // https://www.w3.org/TR/selection-api/#selectionchange-event 381 // FIXME: Spec doesn't specify which task source to use. 382 m_frame->document()->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().selectionchangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 381 383 382 384 return true; -
trunk/Source/WebCore/page/DOMWindow.cpp
r252546 r252824 2125 2125 void DOMWindow::languagesChanged() 2126 2126 { 2127 if (auto* document = this->document()) 2128 document->enqueueWindowEvent(Event::create(eventNames().languagechangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 2127 // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-languages 2128 if (auto document = makeRefPtr(this->document())) 2129 document->queueTaskToDispatchEventOnWindow(TaskSource::DOMManipulation, Event::create(eventNames().languagechangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 2129 2130 } 2130 2131 -
trunk/Source/WebCore/page/PointerCaptureController.cpp
r251320 r252824 151 151 auto pointerType = capturingData.pointerType; 152 152 releasePointerCapture(&element, pointerId); 153 element.document().enqueueDocumentEvent(PointerEvent::create(eventNames().lostpointercaptureEvent, pointerId, pointerType)); 153 // FIXME: Spec doesn't specify which task soruce to use. 154 element.document().queueTaskToDispatchEvent(TaskSource::UserInteraction, PointerEvent::create(eventNames().lostpointercaptureEvent, pointerId, pointerType)); 154 155 return; 155 156 } -
trunk/Source/WebCore/page/PointerLockController.cpp
r251041 r252824 216 216 void PointerLockController::enqueueEvent(const AtomString& type, Document* document) 217 217 { 218 if (document) 219 document->enqueueDocumentEvent(Event::create(type, Event::CanBubble::Yes, Event::IsCancelable::No)); 218 // FIXME: Spec doesn't specify which task source use. 219 if (auto protectedDocument = makeRefPtr(document)) 220 protectedDocument->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(type, Event::CanBubble::Yes, Event::IsCancelable::No)); 220 221 } 221 222 -
trunk/Source/WebCore/storage/StorageEventDispatcher.cpp
r230211 r252824 86 86 87 87 for (auto& frame : frames) { 88 auto result = frame->document()->domWindow()->sessionStorage(); 89 if (!frame->document()) 90 continue; 91 if (!result.hasException()) 92 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 88 auto document = makeRefPtr(frame->document()); 89 auto result = document->domWindow()->sessionStorage(); 90 if (!result.hasException()) // https://html.spec.whatwg.org/multipage/webstorage.html#the-storage-event:event-storage 91 document->queueTaskToDispatchEventOnWindow(TaskSource::DOMManipulation, StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 93 92 } 94 93 } … … 100 99 101 100 for (auto& frame : frames) { 102 auto result = frame->document()->domWindow()->localStorage(); 103 if (!frame->document()) 104 continue; 105 if (!result.hasException()) 106 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 101 auto document = makeRefPtr(frame->document()); 102 auto result = document->domWindow()->localStorage(); 103 if (!result.hasException()) // https://html.spec.whatwg.org/multipage/webstorage.html#the-storage-event:event-storage 104 document->queueTaskToDispatchEventOnWindow(TaskSource::DOMManipulation, StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 107 105 } 108 106 } -
trunk/Source/WebCore/workers/WorkerGlobalScope.cpp
r252723 r252824 71 71 , m_isOnline(isOnline) 72 72 , m_shouldBypassMainWorldContentSecurityPolicy(shouldBypassMainWorldContentSecurityPolicy) 73 , m_eventQueue(*this)74 73 , m_topOrigin(WTFMove(topOrigin)) 75 74 #if ENABLE(INDEXED_DATABASE) … … 413 412 { 414 413 return m_script->isExecutionForbidden(); 415 }416 417 WorkerEventQueue& WorkerGlobalScope::eventQueue() const418 {419 return m_eventQueue;420 414 } 421 415 -
trunk/Source/WebCore/workers/WorkerGlobalScope.h
r252723 r252824 35 35 #include <wtf/URL.h> 36 36 #include "WorkerCacheStorageConnection.h" 37 #include "WorkerEventQueue.h"38 37 #include "WorkerMessagePortChannelProvider.h" 39 38 #include "WorkerScriptController.h" … … 162 161 void disableWebAssembly(const String& errorMessage) final; 163 162 EventTarget* errorEventTarget() final; 164 WorkerEventQueue& eventQueue() const final;165 163 String resourceRequestIdentifier() const final { return m_identifier; } 166 164 SocketProvider* socketProvider() final; … … 196 194 RefPtr<WorkerEventLoop> m_eventLoop; 197 195 std::unique_ptr<EventLoopTaskGroup> m_defaultTaskGroup; 198 199 mutable WorkerEventQueue m_eventQueue;200 196 201 197 Ref<SecurityOrigin> m_topOrigin; -
trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp
r252723 r252824 52 52 , m_script(makeUnique<WorkletScriptController>(this)) 53 53 , m_topOrigin(SecurityOrigin::createUnique()) 54 , m_eventQueue(*this)55 54 , m_code(WTFMove(code)) 56 55 { -
trunk/Source/WebCore/worklets/WorkletGlobalScope.h
r252607 r252824 118 118 119 119 EventTarget* errorEventTarget() final { return this; } 120 EventQueue& eventQueue() const final { ASSERT_NOT_REACHED(); return m_eventQueue; }121 120 122 121 #if ENABLE(WEB_CRYPTO) … … 138 137 std::unique_ptr<EventLoopTaskGroup> m_defaultTaskGroup; 139 138 140 // FIXME: This is not implemented properly, it just satisfies the compiler.141 // https://bugs.webkit.org/show_bug.cgi?id=191136142 mutable WorkerEventQueue m_eventQueue;143 144 139 JSC::RuntimeFlags m_jsRuntimeFlags; 145 140 ScriptSourceCode m_code;
Note:
See TracChangeset
for help on using the changeset viewer.