diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-03-14 06:55:34 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-03-14 09:07:40 -0400 |
commit | b579093ad02dbfe04dc332a0036c5a71fca39fa2 (patch) | |
tree | 2fa056c2d98a487bbce4fecf08d0d260477d3b45 /Userland | |
parent | ea11a843327560087079273a9287df51be272d87 (diff) | |
download | serenity-b579093ad02dbfe04dc332a0036c5a71fca39fa2.zip |
LibWeb: Change HTML::Timer to store its owning window as a JS::Object
Rather than being limited to a Window object, it will also need to be
ownable by a WorkerGlobalScope.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Timer.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Timer.h | 6 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Timer.cpp b/Userland/Libraries/LibWeb/HTML/Timer.cpp index 28fcfde499..8357cf758a 100644 --- a/Userland/Libraries/LibWeb/HTML/Timer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Timer.cpp @@ -4,19 +4,20 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibJS/Runtime/Object.h> #include <LibWeb/HTML/Timer.h> #include <LibWeb/HTML/Window.h> #include <LibWeb/Platform/Timer.h> namespace Web::HTML { -JS::NonnullGCPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id) +JS::NonnullGCPtr<Timer> Timer::create(JS::Object& window_or_worker_global_scope, i32 milliseconds, Function<void()> callback, i32 id) { - return window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id); + return window_or_worker_global_scope.heap().allocate_without_realm<Timer>(window_or_worker_global_scope, milliseconds, move(callback), id); } -Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id) - : m_window(window) +Timer::Timer(JS::Object& window_or_worker_global_scope, i32 milliseconds, Function<void()> callback, i32 id) + : m_window_or_worker_global_scope(window_or_worker_global_scope) , m_callback(move(callback)) , m_id(id) { @@ -28,7 +29,7 @@ Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id void Timer::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(m_window.ptr()); + visitor.visit(m_window_or_worker_global_scope.ptr()); } Timer::~Timer() diff --git a/Userland/Libraries/LibWeb/HTML/Timer.h b/Userland/Libraries/LibWeb/HTML/Timer.h index 2f1aab762e..fb931e7be5 100644 --- a/Userland/Libraries/LibWeb/HTML/Timer.h +++ b/Userland/Libraries/LibWeb/HTML/Timer.h @@ -20,18 +20,18 @@ class Timer final : public JS::Cell { JS_CELL(Timer, JS::Cell); public: - static JS::NonnullGCPtr<Timer> create(Window&, i32 milliseconds, Function<void()> callback, i32 id); + static JS::NonnullGCPtr<Timer> create(JS::Object&, i32 milliseconds, Function<void()> callback, i32 id); virtual ~Timer() override; void start(); private: - Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id); + Timer(JS::Object& window, i32 milliseconds, Function<void()> callback, i32 id); virtual void visit_edges(Cell::Visitor&) override; RefPtr<Platform::Timer> m_timer; - JS::NonnullGCPtr<Window> m_window; + JS::NonnullGCPtr<JS::Object> m_window_or_worker_global_scope; Function<void()> m_callback; i32 m_id { 0 }; }; |