Invoking an animation frame callback empties the JavaScript execution
context stack, so a microtask checkpoint has to run before the next callback
of the same frame. In a dedicated worker it did not:
WorkerAnimationFrameProvider::BeginFrame() wrapped the whole
callback list in a single EnqueueMicrotask(), and microtasks
queued inside a microtask only run once that outer one finishes. A promise
resolved in the first callback therefore ran after the last callback of the
frame instead of before the second one.
The CL runs the callbacks directly in the BeginFrame task, like the main
thread does, so each callback gets its own checkpoint. The wrapper came from
a 2019 CL that replaced a PostTask with a microtask for
scheduling reasons; nothing depends on the nesting. Behind the default-on
WorkerRafMicrotaskCheckpoint kill switch.
raf 1 → raf 2 → microtask from raf 1.
raf 1 → microtask from raf 1 → raf 2.
event-loops/worker_microtask_after_raf.tentative.html, red
with --disable-blink-features=WorkerRafMicrotaskCheckpoint.
The worker sends its reply from a microtask queued in the last
callback, so the test also fails if the checkpoint after the final
callback were to disappear.fast/canvas/offscreencanvas,
wpt/html/canvas/offscreen, event-loops,
http/tests/worker: 2328 tests as expected; the handful of
offscreen text outliers reproduce on a build with the patch reverted and
shift between runs.