mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 07:07:23 +00:00
LibWeb: Add window.setTimeout()
This also leaks the timer just like setInterval() (FIXME).
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user