LibWeb: Avoid creating RAF driver when canceling frames

Treat a missing animation frame callback driver as an empty map when
canceling a frame. This keeps media controls finalization from
allocating while GC is collecting unreachable media elements.

Cover this with a media controls GC text test.
This commit is contained in:
Andreas Kling 2026-05-26 01:45:21 +02:00 committed by Andreas Kling
parent c334760815
commit 23c1e1d2b5
3 changed files with 21 additions and 1 deletions

View file

@ -1738,7 +1738,8 @@ void Window::cancel_animation_frame(WebIDL::UnsignedLong handle)
// 2. Let callbacks be this's target object's map of animation frame callbacks.
// 3. Remove callbacks[handle].
(void)animation_frame_callback_driver().remove(handle);
if (m_animation_frame_callback_driver)
(void)m_animation_frame_callback_driver->remove(handle);
}
AnimationFrameCallbackDriver& Window::animation_frame_callback_driver()

View file

@ -0,0 +1 @@
PASS (didn't crash)

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
function createUnreachableMediaElementWithControls() {
const video = document.createElement("video");
video.controls = true;
}
asyncTest(done => {
createUnreachableMediaElementWithControls();
requestIdleCallback(() => {
internals.gc();
println("PASS (didn't crash)");
done();
});
});
</script>