<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - JSContext Promise resolve tasks too eager, can result in infinite loop"
href="https://bugs.webkit.org/show_bug.cgi?id=151482#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - JSContext Promise resolve tasks too eager, can result in infinite loop"
href="https://bugs.webkit.org/show_bug.cgi?id=151482">bug 151482</a>
from <span class="vcard"><a class="email" href="mailto:utatane.tea@gmail.com" title="Yusuke Suzuki <utatane.tea@gmail.com>"> <span class="fn">Yusuke Suzuki</span></a>
</span></b>
<pre>Yeah, this is expected behavior.
Currently, we enable automatic recursive draining at the end of VM.
This is nice for the default behavior.
But sometimes we would like to take more fine-grained control over microtasks.
So, I'd like to propose the following APIs,
1. adding an option to disable automatic draining
2. adding an API that explicitly drains queued microtasks. And it does not drains tasks recursively
3. adding an API that tells us whether tasks are queued.
1:
void JSGlobalContextSetAutomaticMicrotaskDrainingEnabled(JSGlobalContextRef ctx, bool enabled);
bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx);
(This style and naming convention is similar to JSGlobalContextSetRemoteInspectionEnabled)
And these APIs are similar to V8's `SetAutorunMicrotasks` and `WillAutorunMicrotasks`.
2.
void JSGlobalContextDrainMicrotasksNonRecursively(JSGlobalContextRef ctx);
This is similar to V8's `RunMicrotasks`,
but while `RunMicrotasks` drains tasks until queue is empty (That causes the same infinite loop pasted in this issue),
this API only drains microtasks that is queued now.
3.
size_t JSGlobalContextGetQueuedMicrotasksCount(JSGlobalContextRef ctx);
Returns the number of currently queued microtasks.
So, the current behavior will be emulated with 2 and 3 API like,
if (JSGlobalContextGetQueuedMicrotasksCount(vm))
JSGlobalContextDrainMicrotasksNonRecursively(vm);</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>