Skip to content

Commit 51a52a8

Browse files
shannonboothawesomekling
authored andcommitted
LibWeb: Use "current high resolution time" AO where relevant
And updating some spec comments to latest spec where it is not relevant.
1 parent 33bd6cf commit 51a52a8

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

Userland/Libraries/LibWeb/DOM/Document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
21482148
// 3. If document is associated with an HTML parser, then:
21492149
if (m_parser) {
21502150
// 1. Let now be the current high resolution time given document's relevant global object.
2151-
auto now = HighResolutionTime::unsafe_shared_current_time();
2151+
auto now = HighResolutionTime::current_high_resolution_time(relevant_global_object(*this));
21522152

21532153
// 2. If readinessValue is "complete", and document's load timing info's DOM complete time is 0,
21542154
// then set document's load timing info's DOM complete time to now.

Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ void EventLoop::process()
179179
// 1. Let oldestTask be null.
180180
JS::GCPtr<Task> oldest_task;
181181

182-
// 2. Let taskStartTime be the current high resolution time.
183-
// FIXME: 'current high resolution time' in hr-time-3 takes a global object,
184-
// the HTML spec has not been updated to reflect this, let's use the shared timer.
185-
// - https://github.com/whatwg/html/issues/7776
182+
// 2. Set taskStartTime to the unsafe shared current time.
186183
double task_start_time = HighResolutionTime::unsafe_shared_current_time();
187184

188185
// 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()
377374
// - hasARenderingOpportunity is false
378375
// FIXME: has_a_rendering_opportunity is always true
379376
if (m_type == Type::Window && !task_queue.has_runnable_tasks() && m_microtask_queue->is_empty() /*&& !has_a_rendering_opportunity*/) {
380-
// 1. Set this event loop's last idle period start time to the current high resolution time.
377+
// 1. Set this event loop's last idle period start time to the unsafe shared current time.
381378
m_last_idle_period_start_time = HighResolutionTime::unsafe_shared_current_time();
382379

383380
// 2. Let computeDeadline be the following steps:

Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ void HTMLParser::the_end(JS::NonnullGCPtr<DOM::Document> document, JS::GCPtr<HTM
293293
// 6. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps:
294294
queue_global_task(HTML::Task::Source::DOMManipulation, *document, [document = document] {
295295
// 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.
296-
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
296+
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document));
297297

298298
// 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
299299
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded);
300300
content_loaded_event->set_bubbles(true);
301301
document->dispatch_event(content_loaded_event);
302302

303303
// 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.
304-
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
304+
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document));
305305

306306
// FIXME: 4. Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object.
307307

@@ -331,7 +331,7 @@ void HTMLParser::the_end(JS::NonnullGCPtr<DOM::Document> document, JS::GCPtr<HTM
331331
auto& window = verify_cast<Window>(relevant_global_object(*document));
332332

333333
// 4. Set the Document's load timing info's load event start time to the current high resolution time given window.
334-
document->load_timing_info().load_event_start_time = HighResolutionTime::unsafe_shared_current_time();
334+
document->load_timing_info().load_event_start_time = HighResolutionTime::current_high_resolution_time(window);
335335

336336
// 5. Fire an event named load at window, with legacy target override flag set.
337337
// 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<DOM::Document> document, JS::GCPtr<HTM
343343
// FIXME: 7. Set the Document object's navigation id to null.
344344

345345
// 8. Set the Document's load timing info's load event end time to the current high resolution time given window.
346-
document->load_timing_info().load_event_end_time = HighResolutionTime::unsafe_shared_current_time();
346+
document->load_timing_info().load_event_end_time = HighResolutionTime::current_high_resolution_time(window);
347347

348348
// 9. Assert: Document's page showing is false.
349349
VERIFY(!document->page_showing());

Userland/Libraries/LibWeb/HTML/Window.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,7 @@ bool Window::has_transient_activation() const
604604
static constexpr HighResolutionTime::DOMHighResTimeStamp transient_activation_duration_ms = 5000;
605605

606606
// When the current high resolution time given W
607-
auto unsafe_shared_time = HighResolutionTime::unsafe_shared_current_time();
608-
auto current_time = HighResolutionTime::relative_high_resolution_time(unsafe_shared_time, realm().global_object());
607+
auto current_time = HighResolutionTime::current_high_resolution_time(*this);
609608

610609
// is greater than or equal to the last activation timestamp in W
611610
if (current_time >= m_last_activation_timestamp) {

Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ double IdleDeadline::time_remaining() const
3838
{
3939
auto const& event_loop = HTML::main_thread_event_loop();
4040
// 1. Let now be a DOMHighResTimeStamp representing current high resolution time in milliseconds.
41-
auto now = HighResolutionTime::unsafe_shared_current_time();
41+
auto now = HighResolutionTime::current_high_resolution_time(global_object());
4242
// 2. Let deadline be the result of calling IdleDeadline's get deadline time algorithm.
4343
auto deadline = event_loop.compute_deadline();
4444
// 3. Let timeRemaining be deadline - now.

Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ void XMLDocumentBuilder::document_end()
201201
// Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps:
202202
queue_global_task(HTML::Task::Source::DOMManipulation, m_document, [document = m_document] {
203203
// 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.
204-
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
204+
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document));
205205

206206
// Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
207207
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded);
208208
content_loaded_event->set_bubbles(true);
209209
document->dispatch_event(content_loaded_event);
210210

211211
// 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.
212-
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
212+
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document));
213213

214214
// FIXME: Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the Document object's relevant settings object.
215215

@@ -239,7 +239,7 @@ void XMLDocumentBuilder::document_end()
239239
JS::NonnullGCPtr<HTML::Window> window = verify_cast<HTML::Window>(relevant_global_object(*document));
240240

241241
// Set the Document's load timing info's load event start time to the current high resolution time given window.
242-
document->load_timing_info().load_event_start_time = HighResolutionTime::unsafe_shared_current_time();
242+
document->load_timing_info().load_event_start_time = HighResolutionTime::current_high_resolution_time(window);
243243

244244
// Fire an event named load at window, with legacy target override flag set.
245245
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
@@ -251,7 +251,7 @@ void XMLDocumentBuilder::document_end()
251251
// FIXME: Set the Document object's navigation id to null.
252252

253253
// Set the Document's load timing info's load event end time to the current high resolution time given window.
254-
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
254+
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::current_high_resolution_time(window);
255255

256256
// Assert: Document's page showing is false.
257257
VERIFY(!document->page_showing());

0 commit comments

Comments
 (0)