mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:22:07 +00:00
LibWeb: Make HTML::Timer GC-allocated
These are the timers used internally by setTimeout() and setInterval().
This commit is contained in:
parent
c569c88e63
commit
c7ac82ec33
4 changed files with 26 additions and 11 deletions
|
@ -10,24 +10,29 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
NonnullRefPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
||||
JS::NonnullGCPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
||||
{
|
||||
return adopt_ref(*new Timer(window, milliseconds, move(callback), id));
|
||||
return *window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id);
|
||||
}
|
||||
|
||||
Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
||||
: m_window(window)
|
||||
, m_callback(move(callback))
|
||||
, m_id(id)
|
||||
{
|
||||
m_timer = Core::Timer::create_single_shot(milliseconds, [this, callback = move(callback)] {
|
||||
NonnullRefPtr strong_timer { *this };
|
||||
callback();
|
||||
m_timer = Core::Timer::create_single_shot(milliseconds, [this] {
|
||||
m_callback();
|
||||
});
|
||||
}
|
||||
|
||||
void Timer::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_window.ptr());
|
||||
}
|
||||
|
||||
Timer::~Timer()
|
||||
{
|
||||
m_window.deallocate_timer_id({}, m_id);
|
||||
}
|
||||
|
||||
void Timer::start()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue