1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibWeb: Move unsafe_shared_current_time() to HighResolutionTime

This doesn't belong on the EventLoop at all, as far as I can tell.
This commit is contained in:
Linus Groh 2022-10-04 21:25:00 +01:00
parent ff9a80f54f
commit 4ea6cc56be
10 changed files with 31 additions and 25 deletions

View file

@ -108,7 +108,7 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
auto browsing_context = adopt_ref(*new BrowsingContext(page, container));
// 2. Let unsafeContextCreationTime be the unsafe shared current time.
[[maybe_unused]] auto unsafe_context_creation_time = HTML::main_thread_event_loop().unsafe_shared_current_time();
[[maybe_unused]] auto unsafe_context_creation_time = HighResolutionTime::unsafe_shared_current_time();
// 3. If creator is non-null, then set browsingContext's creator origin to return creator's origin,
// browsingContext's creator URL to return creator's URL,

View file

@ -12,6 +12,7 @@
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/Timer.h>
@ -92,7 +93,7 @@ void EventLoop::process()
// FIXME: 'current high resolution time' in hr-time-3 takes a global object,
// the HTML spec has not been updated to reflect this, let's use the shared timer.
// - https://github.com/whatwg/html/issues/7776
double task_start_time = unsafe_shared_current_time();
double task_start_time = HighResolutionTime::unsafe_shared_current_time();
// 3. Let taskQueue be one of the event loop's task queues, chosen in an implementation-defined manner,
// with the constraint that the chosen task queue must contain at least one runnable task.
@ -204,7 +205,7 @@ void EventLoop::process()
// FIXME: has_a_rendering_opportunity is always true
if (m_type == Type::Window && !task_queue.has_runnable_tasks() && m_microtask_queue.is_empty() /*&& !has_a_rendering_opportunity*/) {
// 1. Set this event loop's last idle period start time to the current high resolution time.
m_last_idle_period_start_time = unsafe_shared_current_time();
m_last_idle_period_start_time = HighResolutionTime::unsafe_shared_current_time();
// 2. Let computeDeadline be the following steps:
// NOTE: instead of passing around a function we use this event loop, which has compute_deadline()
@ -375,12 +376,6 @@ Vector<JS::Handle<HTML::Window>> EventLoop::same_loop_windows() const
return windows;
}
// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
double EventLoop::unsafe_shared_current_time() const
{
return Time::now_monotonic().to_nanoseconds() / 1e6;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model:last-idle-period-start-time
double EventLoop::compute_deadline() const
{

View file

@ -71,7 +71,6 @@ public:
void register_environment_settings_object(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject&);
void unregister_environment_settings_object(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject&);
double unsafe_shared_current_time() const;
double compute_deadline() const;
private:

View file

@ -28,6 +28,7 @@
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Parser/HTMLToken.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/SVG/TagNames.h>
@ -238,7 +239,7 @@ void HTMLParser::the_end()
// 6. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps:
old_queue_global_task_with_document(HTML::Task::Source::DOMManipulation, *m_document, [document = m_document]() mutable {
// 1. Set the Document's load timing info's DOM content loaded event start time to the current high resolution time given the Document's relevant global object.
document->load_timing_info().dom_content_loaded_event_start_time = main_thread_event_loop().unsafe_shared_current_time();
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded);
@ -246,7 +247,7 @@ void HTMLParser::the_end()
document->dispatch_event(*content_loaded_event);
// 3. Set the Document's load timing info's DOM content loaded event end time to the current high resolution time given the Document's relevant global object.
document->load_timing_info().dom_content_loaded_event_end_time = main_thread_event_loop().unsafe_shared_current_time();
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
// FIXME: 4. Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object.
@ -277,7 +278,7 @@ void HTMLParser::the_end()
JS::NonnullGCPtr<Window> window = document->window();
// 4. Set the Document's load timing info's load event start time to the current high resolution time given window.
document->load_timing_info().load_event_start_time = main_thread_event_loop().unsafe_shared_current_time();
document->load_timing_info().load_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// 5. Fire an event named load at window, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
@ -289,7 +290,7 @@ void HTMLParser::the_end()
// FIXME: 7. Set the Document object's navigation id to null.
// 8. Set the Document's load timing info's load event end time to the current high resolution time given window.
document->load_timing_info().load_event_end_time = main_thread_event_loop().unsafe_shared_current_time();
document->load_timing_info().load_event_end_time = HighResolutionTime::unsafe_shared_current_time();
// 9. Assert: Document's page showing is false.
VERIFY(!document->page_showing());

View file

@ -43,6 +43,7 @@
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/Timer.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Page/Page.h>
@ -652,7 +653,7 @@ void Window::invoke_idle_callbacks()
auto& event_loop = main_thread_event_loop();
// 1. If the user-agent believes it should end the idle period early due to newly scheduled high-priority work, return from the algorithm.
// 2. Let now be the current time.
auto now = event_loop.unsafe_shared_current_time();
auto now = HighResolutionTime::unsafe_shared_current_time();
// 3. If now is less than the result of calling getDeadline and the window's list of runnable idle callbacks is not empty:
if (now < event_loop.compute_deadline() && !m_runnable_idle_callbacks.is_empty()) {
// 1. Pop the top callback from window's list of runnable idle callbacks.