LibWeb: Make requestAnimationFrame() callback IDs sequential

This is required by the spec, so let's stop returning random IDs in
favor of a simple sequential integer sequence.
This commit is contained in:
Andreas Kling 2024-08-04 16:36:50 +02:00 committed by Andreas Kling
commit 0e1256e5a4
Notes: github-actions[bot] 2024-08-05 07:13:03 +00:00
6 changed files with 32 additions and 14 deletions

View file

@ -1438,7 +1438,7 @@ double Window::device_pixel_ratio() const
}
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-animationframeprovider-requestanimationframe
i32 Window::request_animation_frame(WebIDL::CallbackType& callback)
WebIDL::UnsignedLong Window::request_animation_frame(WebIDL::CallbackType& callback)
{
// FIXME: Make this fully spec compliant. Currently implements a mix of 'requestAnimationFrame()' and 'run the animation frame callbacks'.
return m_animation_frame_callback_driver.add([this, callback = JS::make_handle(callback)](double now) {
@ -1450,14 +1450,14 @@ i32 Window::request_animation_frame(WebIDL::CallbackType& callback)
}
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animationframeprovider-cancelanimationframe
void Window::cancel_animation_frame(i32 handle)
void Window::cancel_animation_frame(WebIDL::UnsignedLong handle)
{
// 1. If this is not supported, then throw a "NotSupportedError" DOMException.
// NOTE: Doesn't apply in this Window-specific implementation.
// 2. Let callbacks be this's target object's map of animation frame callbacks.
// 3. Remove callbacks[handle].
m_animation_frame_callback_driver.remove(handle);
(void)m_animation_frame_callback_driver.remove(handle);
}
// https://w3c.github.io/requestidlecallback/#dom-window-requestidlecallback