From 51a52a867c43eba9a31327b9733a7247d2392d4c Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 11 Apr 2024 22:42:35 +0200 Subject: [PATCH] LibWeb: Use "current high resolution time" AO where relevant And updating some spec comments to latest spec where it is not relevant. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 2 +- Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 7 ++----- Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 8 ++++---- Userland/Libraries/LibWeb/HTML/Window.cpp | 3 +-- .../Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp | 2 +- Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp | 8 ++++---- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 8141828f527..b25551180a7 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2148,7 +2148,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 = HighResolutionTime::unsafe_shared_current_time(); + auto now = HighResolutionTime::current_high_resolution_time(relevant_global_object(*this)); // 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. diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index c17ef937335..09285c391b2 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -179,10 +179,7 @@ void EventLoop::process() // 1. Let oldestTask be null. JS::GCPtr oldest_task; - // 2. Let taskStartTime be the current high resolution time. - // 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 + // 2. Set taskStartTime to the 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, @@ -377,7 +374,7 @@ void EventLoop::process() // - hasARenderingOpportunity is false // 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. + // 1. Set this event loop's last idle period start time to the unsafe shared current time. m_last_idle_period_start_time = HighResolutionTime::unsafe_shared_current_time(); // 2. Let computeDeadline be the following steps: diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index af761cdcd92..0b01da57572 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -293,7 +293,7 @@ void HTMLParser::the_end(JS::NonnullGCPtr document, JS::GCPtrload_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document)); // 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); @@ -301,7 +301,7 @@ void HTMLParser::the_end(JS::NonnullGCPtr document, JS::GCPtrdispatch_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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document)); // FIXME: 4. Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object. @@ -331,7 +331,7 @@ void HTMLParser::the_end(JS::NonnullGCPtr document, JS::GCPtr(relevant_global_object(*document)); // 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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().load_event_start_time = HighResolutionTime::current_high_resolution_time(window); // 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() @@ -343,7 +343,7 @@ void HTMLParser::the_end(JS::NonnullGCPtr document, JS::GCPtrload_timing_info().load_event_end_time = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().load_event_end_time = HighResolutionTime::current_high_resolution_time(window); // 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 183131131a5..352a49732f6 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -604,8 +604,7 @@ bool Window::has_transient_activation() const static constexpr HighResolutionTime::DOMHighResTimeStamp transient_activation_duration_ms = 5000; // When the current high resolution time given W - auto unsafe_shared_time = HighResolutionTime::unsafe_shared_current_time(); - auto current_time = HighResolutionTime::relative_high_resolution_time(unsafe_shared_time, realm().global_object()); + auto current_time = HighResolutionTime::current_high_resolution_time(*this); // is greater than or equal to the last activation timestamp in W if (current_time >= m_last_activation_timestamp) { diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp index d738b14aa52..de155cdde14 100644 --- a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp +++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp @@ -38,7 +38,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 = HighResolutionTime::unsafe_shared_current_time(); + auto now = HighResolutionTime::current_high_resolution_time(global_object()); // 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 5fb0a47cd14..30b06f9b2cf 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -201,7 +201,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: queue_global_task(HTML::Task::Source::DOMManipulation, m_document, [document = m_document] { // 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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document)); // 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); @@ -209,7 +209,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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document)); // FIXME: Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object. @@ -239,7 +239,7 @@ void XMLDocumentBuilder::document_end() JS::NonnullGCPtr window = verify_cast(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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().load_event_start_time = HighResolutionTime::current_high_resolution_time(window); // 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() @@ -251,7 +251,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 = HighResolutionTime::unsafe_shared_current_time(); + document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(window); // Assert: Document's page showing is false. VERIFY(!document->page_showing());