diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 518f2a653e..f4a120bc6e 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -348,6 +349,22 @@ JS::Interpreter& Document::interpreter() return JS::js_undefined(); }); + m_interpreter->global_object().put_native_function("setInterval", [this](JS::Object*, const Vector& arguments) -> JS::Value { + if (arguments.size() < 2) + return JS::js_undefined(); + ASSERT(arguments[0].is_object()); + ASSERT(arguments[0].as_object()->is_function()); + auto callback = make_handle(const_cast(arguments[0].as_object())); + + // FIXME: This timer should not be leaked! It should also be removable with clearInterval()! + (void)Core::Timer::construct( + arguments[1].to_i32(), [this, callback] { + const_cast(static_cast(callback.cell()))->call(*m_interpreter, {}); + }).leak_ref(); + + return JS::js_undefined(); + }); + m_interpreter->global_object().put_native_property( "document", [this](JS::Object*) {