Diff
Modified: trunk/LayoutTests/ChangeLog (253090 => 253091)
--- trunk/LayoutTests/ChangeLog 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/LayoutTests/ChangeLog 2019-12-04 05:22:03 UTC (rev 253091)
@@ -1,3 +1,16 @@
+2019-11-23 Ryosuke Niwa <[email protected]>
+
+ Perform microtask checkpoint after each task as spec'ed
+ https://bugs.webkit.org/show_bug.cgi?id=204546
+ <rdar://problem/57449333>
+
+ Reviewed by Chris Dumez.
+
+ Added a regresion test using newly added internals methods.
+
+ * http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task-expected.txt: Added.
+ * http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task.html: Added.
+
2019-12-03 Simon Fraser <[email protected]>
Unreviewed test gardening.
Added: trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task-expected.txt (0 => 253091)
--- trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task-expected.txt 2019-12-04 05:22:03 UTC (rev 253091)
@@ -0,0 +1,10 @@
+A microtask checkpoint should be performed after executing each task.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS logs.join(", ") is "1.task, 2.microtask, 3.microtask, 4.task"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task.html (0 => 253091)
--- trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task.html (rev 0)
+++ trunk/LayoutTests/http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task.html 2019-12-04 05:22:03 UTC (rev 253091)
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('A microtask checkpoint should be performed after executing each task.');
+
+const logs = [];
+
+if (!window.internals)
+ testFailed('This test requires internals');
+else {
+ jsTestIsAsync = true;
+
+ internals.queueTask('DOMManipulation', () => {
+ logs.push('1.task');
+ });
+ internals.queueTaskToQueueMicrotask('DOMManipulation', () => {
+ logs.push('2.microtask');
+ });
+ internals.queueTaskToQueueMicrotask('DOMManipulation', () => {
+ logs.push('3.microtask');
+ });
+ internals.queueTask('DOMManipulation', () => {
+ logs.push('4.task');
+ });
+
+ internals.queueTask('DOMManipulation', () => {
+ shouldBeEqualToString('logs.join(", ")', '1.task, 2.microtask, 3.microtask, 4.task');
+ finishJSTest();
+ });
+}
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (253090 => 253091)
--- trunk/Source/WebCore/ChangeLog 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/ChangeLog 2019-12-04 05:22:03 UTC (rev 253091)
@@ -1,3 +1,49 @@
+2019-11-22 Ryosuke Niwa <[email protected]>
+
+ Perform microtask checkpoint after each task as spec'ed
+ https://bugs.webkit.org/show_bug.cgi?id=204546
+ <rdar://problem/57449333>
+
+ Reviewed by Chris Dumez.
+
+ This patch makes EventLoop perform a microtask checkpoint after each task as spec'ed:
+ https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model
+ and removes the timer in MicrotaskQueue.
+
+ Because we always perform a microtask checkpoint after executing _javascript_ in
+ JSExecState::didLeaveScriptContext, there isn't a good way of testing this code change
+ from the existing API and the infrastructure. This patch, therefore, also introduces
+ internals.queueMicrotaskInTask, which schedules a new task within which a new microtask
+ to invoke the callback is scheduled.
+
+ This patch also stops including Microtasks.h from most places as only event loop
+ implementations need to access MicrotaskQueue object now after r252820.
+
+ Test: http/tests/eventloop/perform-microtask-checkpoint-at-end-of-task.html
+
+ * animation/DocumentTimeline.cpp:
+ * animation/WebAnimation.cpp:
+ * bindings/js/JSExecState.cpp:
+ * dom/CustomElementReactionQueue.cpp:
+ * dom/Document.cpp:
+ * dom/EventLoop.cpp:
+ (WebCore::EventLoop::queueMicrotask):
+ (WebCore::EventLoop::run):
+ * dom/Microtasks.cpp:
+ (WebCore::MicrotaskQueue::MicrotaskQueue):
+ (WebCore::MicrotaskQueue::append):
+ (WebCore::MicrotaskQueue::timerFired): Deleted.
+ * dom/Microtasks.h:
+ * dom/MutationObserver.cpp:
+ * testing/Internals.cpp:
+ (WebCore::taskSourceFromString): Extracted from Internals::queueTask.
+ (WebCore::Internals::queueTask):
+ (WebCore::Internals::queueMicrotaskInTask): Added.
+ * testing/Internals.h:
+ * testing/Internals.idl:
+ * workers/WorkerGlobalScope.cpp:
+ * workers/service/SWClientConnection.cpp:
+
2019-12-03 Ryosuke Niwa <[email protected]>
Replace customJavaScriptUserAgentAsSiteSpecificQuirks with customUserAgentAsSiteSpecificQuirks
Modified: trunk/Source/WebCore/animation/DocumentTimeline.cpp (253090 => 253091)
--- trunk/Source/WebCore/animation/DocumentTimeline.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/animation/DocumentTimeline.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -36,7 +36,6 @@
#include "EventNames.h"
#include "GraphicsLayer.h"
#include "KeyframeEffect.h"
-#include "Microtasks.h"
#include "Node.h"
#include "Page.h"
#include "PseudoElement.h"
Modified: trunk/Source/WebCore/animation/WebAnimation.cpp (253090 => 253091)
--- trunk/Source/WebCore/animation/WebAnimation.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/animation/WebAnimation.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -40,7 +40,6 @@
#include "JSWebAnimation.h"
#include "KeyframeEffect.h"
#include "KeyframeEffectStack.h"
-#include "Microtasks.h"
#include "RenderElement.h"
#include "StyledElement.h"
#include "WebAnimationUtilities.h"
Modified: trunk/Source/WebCore/bindings/js/JSExecState.cpp (253090 => 253091)
--- trunk/Source/WebCore/bindings/js/JSExecState.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/bindings/js/JSExecState.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -27,7 +27,6 @@
#include "JSExecState.h"
#include "EventLoop.h"
-#include "Microtasks.h"
#include "RejectedPromiseTracker.h"
#include "ScriptExecutionContext.h"
#include "ScriptState.h"
Modified: trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp (253090 => 253091)
--- trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -34,7 +34,6 @@
#include "HTMLNames.h"
#include "JSCustomElementInterface.h"
#include "JSDOMBinding.h"
-#include "Microtasks.h"
#include <_javascript_Core/CatchScope.h>
#include <_javascript_Core/Heap.h>
#include <wtf/NeverDestroyed.h>
Modified: trunk/Source/WebCore/dom/Document.cpp (253090 => 253091)
--- trunk/Source/WebCore/dom/Document.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -130,7 +130,6 @@
#include "MediaQueryMatcher.h"
#include "MediaStream.h"
#include "MessageEvent.h"
-#include "Microtasks.h"
#include "MouseEventWithHitTestResults.h"
#include "MutationEvent.h"
#include "NameNodeList.h"
Modified: trunk/Source/WebCore/dom/EventLoop.cpp (253090 => 253091)
--- trunk/Source/WebCore/dom/EventLoop.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/EventLoop.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -43,6 +43,7 @@
{
ASSERT(microtask->taskSource() == TaskSource::Microtask);
microtaskQueue().append(WTFMove(microtask));
+ scheduleToRunIfNeeded(); // FIXME: Remove this once everything is integrated with the event loop.
}
void EventLoop::performMicrotaskCheckpoint()
@@ -77,28 +78,35 @@
void EventLoop::run()
{
m_isScheduledToRun = false;
- if (m_tasks.isEmpty())
- return;
+ bool didPerformMicrotaskCheckpoint = false;
- 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 (!m_tasks.isEmpty()) {
+ 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);
+ if (group->isSuspended()) {
+ m_groupsWithSuspenedTasks.add(group);
+ remainingTasks.append(WTFMove(task));
+ continue;
+ }
+
+ task->execute();
+ didPerformMicrotaskCheckpoint = true;
+ microtaskQueue().performMicrotaskCheckpoint();
+ }
+ for (auto& task : m_tasks)
remainingTasks.append(WTFMove(task));
- continue;
- }
+ m_tasks = WTFMove(remainingTasks);
+ }
- task->execute();
- }
- for (auto& task : m_tasks)
- remainingTasks.append(WTFMove(task));
- m_tasks = WTFMove(remainingTasks);
+ // FIXME: Remove this once everything is integrated with the event loop.
+ if (!didPerformMicrotaskCheckpoint)
+ microtaskQueue().performMicrotaskCheckpoint();
}
void EventLoop::clearAllTasks()
Modified: trunk/Source/WebCore/dom/Microtasks.cpp (253090 => 253091)
--- trunk/Source/WebCore/dom/Microtasks.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/Microtasks.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -33,7 +33,6 @@
MicrotaskQueue::MicrotaskQueue(JSC::VM& vm)
: m_vm(makeRef(vm))
- , m_timer(*this, &MicrotaskQueue::timerFired)
{
}
@@ -42,15 +41,8 @@
void MicrotaskQueue::append(std::unique_ptr<EventLoopTask>&& task)
{
m_microtaskQueue.append(WTFMove(task));
-
- m_timer.startOneShot(0_s);
}
-void MicrotaskQueue::timerFired()
-{
- performMicrotaskCheckpoint();
-}
-
void MicrotaskQueue::performMicrotaskCheckpoint()
{
if (m_performingMicrotaskCheckpoint)
Modified: trunk/Source/WebCore/dom/Microtasks.h (253090 => 253091)
--- trunk/Source/WebCore/dom/Microtasks.h 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/Microtasks.h 2019-12-04 05:22:03 UTC (rev 253091)
@@ -21,7 +21,6 @@
#pragma once
-#include "Timer.h"
#include <wtf/Forward.h>
#include <wtf/Vector.h>
@@ -32,7 +31,6 @@
namespace WebCore {
class EventLoopTask;
-class ScriptExecutionContext;
class MicrotaskQueue final {
WTF_MAKE_FAST_ALLOCATED;
@@ -43,19 +41,13 @@
WEBCORE_EXPORT void append(std::unique_ptr<EventLoopTask>&&);
WEBCORE_EXPORT void performMicrotaskCheckpoint();
+private:
JSC::VM& vm() const { return m_vm.get(); }
-private:
- void timerFired();
-
bool m_performingMicrotaskCheckpoint { false };
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;
-
- // FIXME: Instead of a Timer, we should have a centralized Event Loop that calls performMicrotaskCheckpoint()
- // on every iteration, implementing https://html.spec.whatwg.org/multipage/webappapis.html#processing-model-9
- Timer m_timer;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/MutationObserver.cpp (253090 => 253091)
--- trunk/Source/WebCore/dom/MutationObserver.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/dom/MutationObserver.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -38,7 +38,6 @@
#include "GCReachableRef.h"
#include "HTMLSlotElement.h"
#include "InspectorInstrumentation.h"
-#include "Microtasks.h"
#include "MutationCallback.h"
#include "MutationObserverRegistration.h"
#include "MutationRecord.h"
Modified: trunk/Source/WebCore/testing/Internals.cpp (253090 => 253091)
--- trunk/Source/WebCore/testing/Internals.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/testing/Internals.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -4650,15 +4650,20 @@
});
}
+static Optional<TaskSource> taskSourceFromString(const String& taskSourceName)
+{
+ if (taskSourceName == "DOMManipulation")
+ return TaskSource::DOMManipulation;
+ return WTF::nullopt;
+}
+
ExceptionOr<void> Internals::queueTask(ScriptExecutionContext& context, const String& taskSourceName, RefPtr<VoidCallback>&& callback)
{
- TaskSource source;
- if (taskSourceName == "DOMManipulation")
- source = TaskSource::DOMManipulation;
- else
+ auto source = taskSourceFromString(taskSourceName);
+ if (!source)
return Exception { NotSupportedError };
- context.eventLoop().queueTask(source, [callback = WTFMove(callback)]() {
+ context.eventLoop().queueTask(*source, [callback = WTFMove(callback)] {
callback->handleEvent();
});
@@ -4665,6 +4670,23 @@
return { };
}
+ExceptionOr<void> Internals::queueTaskToQueueMicrotask(Document& document, const String& taskSourceName, RefPtr<VoidCallback>&& callback)
+{
+ auto source = taskSourceFromString(taskSourceName);
+ if (!source)
+ return Exception { NotSupportedError };
+
+ ScriptExecutionContext& context = document; // This avoids unnecessarily exporting Document::eventLoop.
+ context.eventLoop().queueTask(*source, [movedCallback = WTFMove(callback), protectedDocument = makeRef(document)]() mutable {
+ ScriptExecutionContext& context = protectedDocument.get();
+ context.eventLoop().queueMicrotask([callback = WTFMove(movedCallback)] {
+ callback->handleEvent();
+ });
+ });
+
+ return { };
+}
+
Vector<String> Internals::accessKeyModifiers() const
{
Vector<String> accessKeyModifierStrings;
Modified: trunk/Source/WebCore/testing/Internals.h (253090 => 253091)
--- trunk/Source/WebCore/testing/Internals.h 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/testing/Internals.h 2019-12-04 05:22:03 UTC (rev 253091)
@@ -776,6 +776,7 @@
void postTask(RefPtr<VoidCallback>&&);
ExceptionOr<void> queueTask(ScriptExecutionContext&, const String& source, RefPtr<VoidCallback>&&);
+ ExceptionOr<void> queueTaskToQueueMicrotask(Document&, const String& source, RefPtr<VoidCallback>&&);
void markContextAsInsecure();
bool usingAppleInternalSDK() const;
Modified: trunk/Source/WebCore/testing/Internals.idl (253090 => 253091)
--- trunk/Source/WebCore/testing/Internals.idl 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/testing/Internals.idl 2019-12-04 05:22:03 UTC (rev 253091)
@@ -765,6 +765,7 @@
void postTask(VoidCallback callback);
[CallWith=ScriptExecutionContext, MayThrowException] void queueTask(DOMString source, VoidCallback callback);
+ [CallWith=Document] void queueTaskToQueueMicrotask(DOMString source, VoidCallback callback);
void markContextAsInsecure();
void setMaxCanvasPixelMemory(unsigned long size);
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (253090 => 253091)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -35,7 +35,6 @@
#include "IDBConnectionProxy.h"
#include "ImageBitmapOptions.h"
#include "InspectorInstrumentation.h"
-#include "Microtasks.h"
#include "Performance.h"
#include "RuntimeEnabledFeatures.h"
#include "ScheduledAction.h"
Modified: trunk/Source/WebCore/workers/service/SWClientConnection.cpp (253090 => 253091)
--- trunk/Source/WebCore/workers/service/SWClientConnection.cpp 2019-12-04 04:28:10 UTC (rev 253090)
+++ trunk/Source/WebCore/workers/service/SWClientConnection.cpp 2019-12-04 05:22:03 UTC (rev 253091)
@@ -31,7 +31,6 @@
#include "Document.h"
#include "ExceptionData.h"
#include "MessageEvent.h"
-#include "Microtasks.h"
#include "SWContextManager.h"
#include "ServiceWorkerContainer.h"
#include "ServiceWorkerFetchResult.h"