From 18cff5e0be2c2ac96e472e5d9dedd1303e036515 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 29 Sep 2020 18:31:07 +0200 Subject: [PATCH] LibWeb: Implement performance.timeOrigin This is the origin timestamp of the same monotonic clock used for the performance.now() timestamp. I got a little confused while implementing this, since the numbers are very low. That's because it uses the CLOCK_MONOTONIC system clock, which we start counting from 0 at boot. :^) --- Libraries/LibWeb/HighResolutionTime/Performance.cpp | 6 ++++++ Libraries/LibWeb/HighResolutionTime/Performance.h | 1 + Libraries/LibWeb/HighResolutionTime/Performance.idl | 1 + 3 files changed, 8 insertions(+) diff --git a/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Libraries/LibWeb/HighResolutionTime/Performance.cpp index 0567260a63..77a905e9fd 100644 --- a/Libraries/LibWeb/HighResolutionTime/Performance.cpp +++ b/Libraries/LibWeb/HighResolutionTime/Performance.cpp @@ -44,6 +44,12 @@ Performance::~Performance() { } +double Performance::time_origin() const +{ + auto origin = m_timer.origin_time(); + return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0); +} + void Performance::ref_event_target() { m_window.ref(); diff --git a/Libraries/LibWeb/HighResolutionTime/Performance.h b/Libraries/LibWeb/HighResolutionTime/Performance.h index 588652400d..3d3bad0c65 100644 --- a/Libraries/LibWeb/HighResolutionTime/Performance.h +++ b/Libraries/LibWeb/HighResolutionTime/Performance.h @@ -42,6 +42,7 @@ public: ~Performance(); double now() const { return m_timer.elapsed(); } + double time_origin() const; virtual void ref_event_target() override; virtual void unref_event_target() override; diff --git a/Libraries/LibWeb/HighResolutionTime/Performance.idl b/Libraries/LibWeb/HighResolutionTime/Performance.idl index 33a0656167..4acb463f7a 100644 --- a/Libraries/LibWeb/HighResolutionTime/Performance.idl +++ b/Libraries/LibWeb/HighResolutionTime/Performance.idl @@ -1,3 +1,4 @@ interface Performance : EventTarget { double now(); + readonly attribute double timeOrigin; }