1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

LibWeb: Add window.setTimeout()

This also leaks the timer just like setInterval() (FIXME).
This commit is contained in:
Andreas Kling 2020-04-05 00:56:16 +02:00
parent 16bd99aa52
commit ca90f88d4e
4 changed files with 31 additions and 0 deletions

View file

@ -62,6 +62,17 @@ void Window::set_interval(JS::Function& callback, i32 interval)
}).leak_ref();
}
void Window::set_timeout(JS::Function& callback, i32 interval)
{
// FIXME: This leaks the interval timer and makes it unstoppable.
auto& timer = Core::Timer::construct(interval, [handle = make_handle(&callback)] {
auto* function = const_cast<JS::Function*>(static_cast<const JS::Function*>(handle.cell()));
auto& interpreter = function->interpreter();
interpreter.call(function);
}).leak_ref();
timer.set_single_shot(true);
}
i32 Window::request_animation_frame(JS::Function& callback)
{
i32 link_id = GUI::DisplayLink::register_callback([handle = make_handle(&callback)](i32 link_id) {