No microtask checkpoint between animation frame callbacks in a worker

#419327007 Area: Blink>Workers / event loop CL 8650019 In Review

What happens

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.

Two rAF callbacks queued in the same frame inside a worker

Live: unpatched Chrome reports raf 1 → raf 2 → microtask from raf 1.
Before: microtask runs last
Kill switch off: the microtask of the first callback runs after the second callback.
After: microtask runs in between
With the fix: raf 1 → microtask from raf 1 → raf 2.
Diff mask over the readout
977 px differ -- the run order and the verdict row.

Verification

Links

Issue 419327007 CL 8650019 standalone sampler.html capture_screenshots.py