LibWeb: Implement pausing the event loop a bit closer to the spec

Namely, this is to update the rendering before pausing the event loop.
This commit is contained in:
Timothy Flynn 2024-11-05 08:54:10 -05:00 committed by Andreas Kling
parent 5431db8c1c
commit f4111ef1e1
Notes: github-actions[bot] 2024-11-06 09:51:32 +00:00
3 changed files with 60 additions and 6 deletions

View file

@ -605,4 +605,46 @@ double EventLoop::compute_deadline() const
return deadline;
}
EventLoop::PauseHandle::PauseHandle(EventLoop& event_loop, JS::Object const& global, HighResolutionTime::DOMHighResTimeStamp time_before_pause)
: event_loop(event_loop)
, global(global)
, time_before_pause(time_before_pause)
{
}
EventLoop::PauseHandle::~PauseHandle()
{
event_loop->unpause({}, *global, time_before_pause);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#pause
EventLoop::PauseHandle EventLoop::pause()
{
// 1. Let global be the current global object.
auto& global = current_principal_global_object();
// 2. Let timeBeforePause be the current high resolution time given global.
auto time_before_pause = HighResolutionTime::current_high_resolution_time(global);
// 3. If necessary, update the rendering or user interface of any Document or navigable to reflect the current state.
if (!m_is_running_rendering_task)
update_the_rendering();
// 4. Wait until the condition goal is met. While a user agent has a paused task, the corresponding event loop must
// not run further tasks, and any script in the currently running task must block. User agents should remain
// responsive to user input while paused, however, albeit in a reduced capacity since the event loop will not be
// doing anything.
m_execution_paused = true;
return PauseHandle { *this, global, time_before_pause };
}
void EventLoop::unpause(Badge<PauseHandle>, JS::Object const& global, HighResolutionTime::DOMHighResTimeStamp time_before_pause)
{
m_execution_paused = false;
// FIXME: 5. Record pause duration given the duration from timeBeforePause to the current high resolution time given global.
[[maybe_unused]] auto pause_duration = HighResolutionTime::current_high_resolution_time(global) - time_before_pause;
}
}