/* * Copyright (c) 2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::HTML { // https://html.spec.whatwg.org/#timerhandler using TimerHandler = Variant, DeprecatedString>; // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope class WindowOrWorkerGlobalScopeMixin { public: virtual ~WindowOrWorkerGlobalScopeMixin(); virtual Bindings::PlatformObject& this_impl() = 0; virtual Bindings::PlatformObject const& this_impl() const = 0; // JS API functions WebIDL::ExceptionOr origin() const; bool is_secure_context() const; bool cross_origin_isolated() const; WebIDL::ExceptionOr btoa(String const& data) const; WebIDL::ExceptionOr atob(String const& data) const; void queue_microtask(WebIDL::CallbackType&); WebIDL::ExceptionOr structured_clone(JS::Value, StructuredSerializeOptions const&) const; JS::NonnullGCPtr fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const; i32 set_timeout(TimerHandler, i32 timeout, JS::MarkedVector arguments); i32 set_interval(TimerHandler, i32 timeout, JS::MarkedVector 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 arguments, Repeat repeat, Optional previous_id = {}, Optional base_url = {}); IDAllocator m_timer_id_allocator; HashMap> m_timers; }; }