mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-01 16:02:53 +00:00
LibWeb: Report performance based timestamps relative to ESO time origin
This commit is contained in:
parent
8963e62a5e
commit
7488136a51
Notes:
github-actions[bot]
2025-01-27 13:54:36 +00:00
Author: https://github.com/tcl3
Commit: 7488136a51
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3341
12 changed files with 248 additions and 28 deletions
|
@ -11,23 +11,15 @@
|
|||
|
||||
namespace Web::HighResolutionTime {
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
|
||||
DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
||||
// https://w3c.github.io/hr-time/#dfn-estimated-monotonic-time-of-the-unix-epoch
|
||||
DOMHighResTimeStamp estimated_monotonic_time_of_the_unix_epoch()
|
||||
{
|
||||
(void)global;
|
||||
|
||||
// To get time origin timestamp, given a global object global, run the following steps, which return a duration:
|
||||
// FIXME: 1. Let timeOrigin be global's relevant settings object's time origin.
|
||||
auto time_origin = 0;
|
||||
|
||||
// Each group of environment settings objects that could possibly communicate in any way
|
||||
// has an estimated monotonic time of the Unix epoch, a moment on the monotonic clock,
|
||||
// whose value is initialized by the following steps:
|
||||
|
||||
// !. Let wall time be the wall clock's unsafe current time.
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
auto wall_time = tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
|
||||
// 1. Let wall time be the wall clock's unsafe current time.
|
||||
auto wall_time = wall_clock_unsafe_current_time();
|
||||
|
||||
// 2. Let monotonic time be the monotonic clock's unsafe current time.
|
||||
auto monotonic_time = unsafe_shared_current_time();
|
||||
|
@ -37,9 +29,18 @@ DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
|||
|
||||
// 4. Initialize the estimated monotonic time of the Unix epoch to the result of calling coarsen time with epoch time
|
||||
auto estimated_monotonic_time = coarsen_time(epoch_time);
|
||||
return estimated_monotonic_time;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
|
||||
DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
||||
{
|
||||
// To get time origin timestamp, given a global object global, run the following steps, which return a duration:
|
||||
// 1. Let timeOrigin be global's relevant settings object's time origin.
|
||||
auto time_origin = HTML::relevant_principal_settings_object(global).time_origin();
|
||||
|
||||
// 2. Return the duration from the estimated monotonic time of the Unix epoch to timeOrigin.
|
||||
return estimated_monotonic_time - time_origin;
|
||||
return time_origin - estimated_monotonic_time_of_the_unix_epoch();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-coarsen-time
|
||||
|
@ -75,8 +76,9 @@ DOMHighResTimeStamp relative_high_resolution_time(DOMHighResTimeStamp time, JS::
|
|||
// https://w3c.github.io/hr-time/#dfn-relative-high-resolution-coarse-time
|
||||
DOMHighResTimeStamp relative_high_resolution_coarsen_time(DOMHighResTimeStamp coarsen_time, JS::Object const& global)
|
||||
{
|
||||
// The relative high resolution coarse time given a DOMHighResTimeStamp coarseTime and a global object global, is the difference between coarseTime and the result of calling get time origin timestamp with global.
|
||||
return coarsen_time - get_time_origin_timestamp(global);
|
||||
// The relative high resolution coarse time given a moment from the monotonic clock coarseTime and a global object global, is the duration from global's relevant settings object's time origin to coarseTime.
|
||||
auto time_origin = HTML::relevant_principal_settings_object(global).time_origin();
|
||||
return coarsen_time - time_origin;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
|
||||
|
@ -86,6 +88,12 @@ DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_cap
|
|||
return coarsen_time(unsafe_shared_current_time(), cross_origin_isolated_capability);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#wall-clock-unsafe-current-time
|
||||
DOMHighResTimeStamp wall_clock_unsafe_current_time()
|
||||
{
|
||||
return UnixDateTime::now().nanoseconds_since_epoch() / 1.0e6;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
|
||||
DOMHighResTimeStamp unsafe_shared_current_time()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue