summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-04 21:25:00 +0100
committerLinus Groh <mail@linusgroh.de>2022-10-05 09:12:59 +0100
commit4ea6cc56bed17a0c2231c5ba56ea45dbb7ea135a (patch)
treeb2ed03a2f83aeff7d2b1c72fd806643bbcb06077 /Userland/Libraries
parentff9a80f54f09888f2057123df1c67225a52a7b35 (diff)
downloadserenity-4ea6cc56bed17a0c2231c5ba56ea45dbb7ea135a.zip
LibWeb: Move unsafe_shared_current_time() to HighResolutionTime
This doesn't belong on the EventLoop at all, as far as I can tell.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp6
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp11
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp9
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp11
-rw-r--r--Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h1
-rw-r--r--Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp3
-rw-r--r--Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp9
10 files changed, 31 insertions, 25 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index d683e554d7..a90022a777 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1450,7 +1450,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
// 3. If document is associated with an HTML parser, then:
if (m_parser) {
// 1. Let now be the current high resolution time given document's relevant global object.
- auto now = HTML::main_thread_event_loop().unsafe_shared_current_time();
+ auto now = HighResolutionTime::unsafe_shared_current_time();
// 2. If readinessValue is "complete", and document's load timing info's DOM complete time is 0,
// then set document's load timing info's DOM complete time to now.
@@ -2173,7 +2173,7 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
// then set unloadTimingInfo's unload event start time to the current high resolution time given newGlobal,
// coarsened given document's relevant settings object's cross-origin isolated capability.
unload_timing_info->unload_event_start_time = HighResolutionTime::coarsen_time(
- HTML::main_thread_event_loop().unsafe_shared_current_time(),
+ HighResolutionTime::unsafe_shared_current_time(),
relevant_settings_object().cross_origin_isolated_capability() == HTML::CanUseCrossOriginIsolatedAPIs::Yes);
}
@@ -2191,7 +2191,7 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
// then set unloadTimingInfo's unload event end time to the current high resolution time given newGlobal,
// coarsened given document's relevant settings object's cross-origin isolated capability.
unload_timing_info->unload_event_end_time = HighResolutionTime::coarsen_time(
- HTML::main_thread_event_loop().unsafe_shared_current_time(),
+ HighResolutionTime::unsafe_shared_current_time(),
relevant_settings_object().cross_origin_isolated_capability() == HTML::CanUseCrossOriginIsolatedAPIs::Yes);
}
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
index 72e347dfdd..b8df3f9c17 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
@@ -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,
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 74edfdb56b..1047cd8b94 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -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
{
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index fd30663724..e77f0e066e 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -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:
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index 34389a6ae6..f09595cc0a 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -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());
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index cfeafd2ab8..d118bcd50f 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -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.
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp
index 747d724e09..cbb220cebd 100644
--- a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp
@@ -5,7 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibWeb/HTML/EventLoop/EventLoop.h>
+#include <AK/Time.h>
#include <LibWeb/HighResolutionTime/CoarsenTime.h>
namespace Web::HighResolutionTime {
@@ -22,7 +22,14 @@ DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origi
DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability)
{
// The coarsened shared current time given an optional boolean crossOriginIsolatedCapability (default false), must return the result of calling coarsen time with the unsafe shared current time and crossOriginIsolatedCapability.
- return coarsen_time(HTML::main_thread_event_loop().unsafe_shared_current_time(), cross_origin_isolated_capability);
+ return coarsen_time(unsafe_shared_current_time(), cross_origin_isolated_capability);
+}
+
+// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
+DOMHighResTimeStamp unsafe_shared_current_time()
+{
+ // The unsafe shared current time must return the current value of the shared monotonic clock.
+ return Time::now_monotonic().to_nanoseconds() / 1e6;
}
}
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h
index c2c7bab57c..db59873427 100644
--- a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h
@@ -13,5 +13,6 @@ namespace Web::HighResolutionTime {
DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability = false);
DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability = false);
+DOMHighResTimeStamp unsafe_shared_current_time();
}
diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp
index e854ba9944..dbafe74d3e 100644
--- a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp
+++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp
@@ -7,6 +7,7 @@
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Window.h>
+#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/RequestIdleCallback/IdleDeadline.h>
namespace Web::RequestIdleCallback {
@@ -30,7 +31,7 @@ double IdleDeadline::time_remaining() const
{
auto const& event_loop = HTML::main_thread_event_loop();
// 1. Let now be a DOMHighResTimeStamp representing current high resolution time in milliseconds.
- auto now = event_loop.unsafe_shared_current_time();
+ auto now = HighResolutionTime::unsafe_shared_current_time();
// 2. Let deadline be the result of calling IdleDeadline's get deadline time algorithm.
auto deadline = event_loop.compute_deadline();
// 3. Let timeRemaining be deadline - now.
diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
index 64105d6b23..5c7084931d 100644
--- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
+++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
@@ -7,6 +7,7 @@
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/HTMLTemplateElement.h>
#include <LibWeb/HTML/Window.h>
+#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/XML/XMLDocumentBuilder.h>
inline namespace {
@@ -174,7 +175,7 @@ void XMLDocumentBuilder::document_end()
// 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 {
// 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 = HTML::main_thread_event_loop().unsafe_shared_current_time();
+ document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// 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);
@@ -182,7 +183,7 @@ void XMLDocumentBuilder::document_end()
document->dispatch_event(*content_loaded_event);
// 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 = HTML::main_thread_event_loop().unsafe_shared_current_time();
+ document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
// FIXME: Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object.
@@ -212,7 +213,7 @@ void XMLDocumentBuilder::document_end()
JS::NonnullGCPtr<HTML::Window> window = verify_cast<HTML::Window>(relevant_global_object(*document));
// 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 = HTML::main_thread_event_loop().unsafe_shared_current_time();
+ document->load_timing_info().load_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// 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()
@@ -224,7 +225,7 @@ void XMLDocumentBuilder::document_end()
// FIXME: Set the Document object's navigation id to null.
// Set the Document's load timing info's load event end time to the current high resolution time given window.
- document->load_timing_info().dom_content_loaded_event_end_time = HTML::main_thread_event_loop().unsafe_shared_current_time();
+ document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
// Assert: Document's page showing is false.
VERIFY(!document->page_showing());