mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +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:
parent
ff9a80f54f
commit
4ea6cc56be
10 changed files with 31 additions and 25 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue