diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 1e206d660f..5f09f0cddc 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -748,13 +748,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge> Window::crypto()
return JS::NonnullGCPtr { *m_crypto };
}
-static JS::ThrowCompletionOr make_timer_handler(JS::VM& vm, JS::Value handler)
-{
- if (handler.is_function())
- return JS::make_handle(vm.heap().allocate_without_realm(handler.as_function(), incumbent_settings_object()));
- return TRY(handler.to_string(vm));
-}
-
-// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
-JS_DEFINE_NATIVE_FUNCTION(Window::set_timeout)
-{
- auto* impl = TRY(impl_from(vm));
-
- if (!vm.argument_count())
- return vm.throw_completion(JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
-
- auto handler = TRY(make_timer_handler(vm, vm.argument(0)));
-
- i32 timeout = 0;
- if (vm.argument_count() >= 2)
- timeout = TRY(vm.argument(1).to_i32(vm));
-
- JS::MarkedVector arguments { vm.heap() };
- for (size_t i = 2; i < vm.argument_count(); ++i)
- arguments.append(vm.argument(i));
-
- auto id = static_cast(impl)->set_timeout(move(handler), timeout, move(arguments));
- return JS::Value(id);
-}
-
-// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
-JS_DEFINE_NATIVE_FUNCTION(Window::set_interval)
-{
- auto* impl = TRY(impl_from(vm));
-
- if (!vm.argument_count())
- return vm.throw_completion(JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
-
- auto handler = TRY(make_timer_handler(vm, vm.argument(0)));
-
- i32 timeout = 0;
- if (vm.argument_count() >= 2)
- timeout = TRY(vm.argument(1).to_i32(vm));
-
- JS::MarkedVector arguments { vm.heap() };
- for (size_t i = 2; i < vm.argument_count(); ++i)
- arguments.append(vm.argument(i));
-
- auto id = static_cast(impl)->set_interval(move(handler), timeout, move(arguments));
- return JS::Value(id);
-}
-
-// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout
-JS_DEFINE_NATIVE_FUNCTION(Window::clear_timeout)
-{
- auto* impl = TRY(impl_from(vm));
-
- i32 id = 0;
- if (vm.argument_count())
- id = TRY(vm.argument(0).to_i32(vm));
-
- static_cast(impl)->clear_timeout(id);
- return JS::js_undefined();
-}
-
-// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval
-JS_DEFINE_NATIVE_FUNCTION(Window::clear_interval)
-{
- auto* impl = TRY(impl_from(vm));
-
- i32 id = 0;
- if (vm.argument_count())
- id = TRY(vm.argument(0).to_i32(vm));
-
- static_cast(impl)->clear_interval(id);
- return JS::js_undefined();
-}
-
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
size_t Window::document_tree_child_browsing_context_count() const
{
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index d6967077a4..f61e39099a 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -56,8 +56,12 @@ public:
using WindowOrWorkerGlobalScopeMixin::atob;
using WindowOrWorkerGlobalScopeMixin::btoa;
+ using WindowOrWorkerGlobalScopeMixin::clear_interval;
+ using WindowOrWorkerGlobalScopeMixin::clear_timeout;
using WindowOrWorkerGlobalScopeMixin::fetch;
using WindowOrWorkerGlobalScopeMixin::queue_microtask;
+ using WindowOrWorkerGlobalScopeMixin::set_interval;
+ using WindowOrWorkerGlobalScopeMixin::set_timeout;
using WindowOrWorkerGlobalScopeMixin::structured_clone;
// ^DOM::EventTarget
@@ -231,11 +235,6 @@ private:
CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map;
JS_DECLARE_NATIVE_FUNCTION(location_setter);
-
- JS_DECLARE_NATIVE_FUNCTION(set_interval);
- JS_DECLARE_NATIVE_FUNCTION(set_timeout);
- JS_DECLARE_NATIVE_FUNCTION(clear_interval);
- JS_DECLARE_NATIVE_FUNCTION(clear_timeout);
};
void run_animation_frame_callbacks(DOM::Document&, double now);
diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
index dc734395af..fda12c65dd 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
@@ -5,6 +5,9 @@
// FIXME: Support VoidFunction in the IDL parser
callback VoidFunction = undefined ();
+// https://html.spec.whatwg.org/#timerhandler
+typedef (DOMString or Function) TimerHandler;
+
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
interface mixin WindowOrWorkerGlobalScope {
[Replaceable] readonly attribute USVString origin;
@@ -18,10 +21,10 @@ interface mixin WindowOrWorkerGlobalScope {
ByteString atob(DOMString data);
// timers
- // FIXME: long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments);
- // FIXME: undefined clearTimeout(optional long id = 0);
- // FIXME: long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments);
- // FIXME: undefined clearInterval(optional long id = 0);
+ long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments);
+ undefined clearTimeout(optional long id = 0);
+ long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments);
+ undefined clearInterval(optional long id = 0);
// microtask queuing
undefined queueMicrotask(VoidFunction callback);