mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:57:43 +00:00
LibWeb: Add window.setTimeout()
This also leaks the timer just like setInterval() (FIXME).
This commit is contained in:
parent
16bd99aa52
commit
ca90f88d4e
4 changed files with 31 additions and 0 deletions
|
@ -44,6 +44,7 @@ WindowObject::WindowObject(Window& impl)
|
|||
put_native_property("document", document_getter, document_setter);
|
||||
put_native_function("alert", alert);
|
||||
put_native_function("setInterval", set_interval, 1);
|
||||
put_native_function("setTimeout", set_timeout, 1);
|
||||
put_native_function("requestAnimationFrame", request_animation_frame, 1);
|
||||
put_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
|
||||
|
||||
|
@ -97,6 +98,23 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter)
|
|||
return {};
|
||||
}
|
||||
|
||||
JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto& arguments = interpreter.call_frame().arguments;
|
||||
if (arguments.size() < 2)
|
||||
return {};
|
||||
auto* callback_object = arguments[0].to_object(interpreter.heap());
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function())
|
||||
return interpreter.throw_exception<JS::Error>("TypeError", "Not a function");
|
||||
impl->set_timeout(*static_cast<JS::Function*>(callback_object), arguments[1].to_i32());
|
||||
return {};
|
||||
}
|
||||
|
||||
JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue