1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibWeb: Move timer implementations to WindowOrWorkerGlobalScopeMixin

This is where it belongs according to the spec, and where these methods'
IDL will be placed.

This forces us to implement a few steps closer to the spec as well.
This commit is contained in:
Timothy Flynn 2023-03-14 06:59:23 -04:00 committed by Tim Flynn
parent b579093ad0
commit dd992e7dad
5 changed files with 164 additions and 146 deletions

View file

@ -7,6 +7,9 @@
#pragma once
#include <AK/Forward.h>
#include <AK/HashMap.h>
#include <AK/IDAllocator.h>
#include <AK/Variant.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Fetch/Request.h>
#include <LibWeb/Forward.h>
@ -14,6 +17,9 @@
namespace Web::HTML {
// https://html.spec.whatwg.org/#timerhandler
using TimerHandler = Variant<JS::Handle<WebIDL::CallbackType>, DeprecatedString>;
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
class WindowOrWorkerGlobalScopeMixin {
public:
@ -31,6 +37,24 @@ public:
void queue_microtask(WebIDL::CallbackType&);
WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Value, StructuredSerializeOptions const&) const;
JS::NonnullGCPtr<JS::Promise> fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const;
i32 set_timeout(TimerHandler, i32 timeout, JS::MarkedVector<JS::Value> arguments);
i32 set_interval(TimerHandler, i32 timeout, JS::MarkedVector<JS::Value> arguments);
void clear_timeout(i32);
void clear_interval(i32);
protected:
void visit_edges(JS::Cell::Visitor&);
private:
enum class Repeat {
Yes,
No,
};
i32 run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments, Repeat repeat, Optional<i32> previous_id = {}, Optional<AK::URL> base_url = {});
IDAllocator m_timer_id_allocator;
HashMap<int, JS::NonnullGCPtr<Timer>> m_timers;
};
}