Skip to content

Truly independent web browser

LibWeb: Initialize the estimated monotonic time of the Unix epoch once

Luke Wilded1290cba0490
diff --git a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
index 174f649f376..8c145b7b03a 100644
--- a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
+++ b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
@@ -18,18 +18,22 @@ DOMHighResTimeStamp estimated_monotonic_time_of_the_unix_epoch()
// 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:
-
- // 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();
-
- // 3. Let epoch time be monotonic time - (wall time - Unix epoch)
- auto epoch_time = monotonic_time - (wall_time - 0);
-
- // 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);
+ // AD-HOC: The estimate is initialized once per process, since nothing shares it between processes, though
+ // environment settings objects in different processes can communicate.
+ static DOMHighResTimeStamp const estimated_monotonic_time = [] {
+ // 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();
+
+ // 3. Let epoch time be monotonic time - (wall time - Unix epoch)
+ auto epoch_time = monotonic_time - (wall_time - 0);
+
+ // 4. Initialize the estimated monotonic time of the Unix epoch to the result of calling coarsen time with
+ // epoch time
+ return coarsen_time(epoch_time);
+ }();
return estimated_monotonic_time;
}