mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +00:00
LibWeb: Clear all active timers when document is destroyed
This change implements a step from the document's destroy procedure in the specification, saying that all active timers should be cleared. By doing this, we also fix the leaking of a document in case where we have navigated away from a page that has scheduled timers that haven't yet been triggered.
This commit is contained in:
parent
73ef102b01
commit
67c727177e
6 changed files with 44 additions and 1 deletions
|
@ -34,6 +34,7 @@ void Timer::visit_edges(Cell::Visitor& visitor)
|
|||
|
||||
Timer::~Timer()
|
||||
{
|
||||
VERIFY(!m_timer->is_active());
|
||||
}
|
||||
|
||||
void Timer::start()
|
||||
|
@ -41,4 +42,9 @@ void Timer::start()
|
|||
m_timer->start();
|
||||
}
|
||||
|
||||
void Timer::stop()
|
||||
{
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
virtual ~Timer() override;
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
Timer(JS::Object& window, i32 milliseconds, Function<void()> callback, i32 id);
|
||||
|
|
|
@ -183,15 +183,26 @@ i32 WindowOrWorkerGlobalScopeMixin::set_interval(TimerHandler handler, i32 timeo
|
|||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout
|
||||
void WindowOrWorkerGlobalScopeMixin::clear_timeout(i32 id)
|
||||
{
|
||||
if (auto timer = m_timers.get(id); timer.has_value())
|
||||
timer.value()->stop();
|
||||
m_timers.remove(id);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval
|
||||
void WindowOrWorkerGlobalScopeMixin::clear_interval(i32 id)
|
||||
{
|
||||
if (auto timer = m_timers.get(id); timer.has_value())
|
||||
timer.value()->stop();
|
||||
m_timers.remove(id);
|
||||
}
|
||||
|
||||
void WindowOrWorkerGlobalScopeMixin::clear_map_of_active_timers()
|
||||
{
|
||||
for (auto& it : m_timers)
|
||||
it.value->stop();
|
||||
m_timers.clear();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps
|
||||
// With no active script fix from https://github.com/whatwg/html/pull/9712
|
||||
i32 WindowOrWorkerGlobalScopeMixin::run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments, Repeat repeat, Optional<i32> previous_id)
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
i32 set_interval(TimerHandler, i32 timeout, JS::MarkedVector<JS::Value> arguments);
|
||||
void clear_timeout(i32);
|
||||
void clear_interval(i32);
|
||||
void clear_map_of_active_timers();
|
||||
|
||||
PerformanceTimeline::PerformanceEntryTuple& relevant_performance_entry_tuple(FlyString const& entry_type);
|
||||
void queue_performance_entry(JS::NonnullGCPtr<PerformanceTimeline::PerformanceEntry> new_entry);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue