From 814c47b976e2009d41427be4faee9f8b58f276f3 Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Mon, 24 Jul 2023 18:08:44 +0200 Subject: [PATCH] Tighten the Sensor.timestamp and latest reading["timestamp"] definitions latest reading["timestamp"] was not defined strictly enough: the definition mentioned "the time origin", which is a concept that only exists related to a given environment settings object. We now have it be an "unsafe current time" as defined by the High Resolution Time specification, and its value is always set using the same monotonic clock -- if we get a timestamp directly from a device sensor (e.g. a WinRT timestamp relative to the Windows epoch) it needs to be translated into a timestamp that makes sense with the monotonic clock. Finally, Sensor.timestamp no longer just returns latest reading["timestamp"] and instead ensures that whatever "unsafe current time" the latter returns is coarsened and converted to a value relative to its relevant time origin. Related to #463. --- index.bs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/index.bs b/index.bs index 9f084d7..fb918c2 100644 --- a/index.bs +++ b/index.bs @@ -845,13 +845,10 @@ the [=sensor reading=] as arguments. The [=latest reading=] [=ordered map|map=] contains an [=map/entry=] whose [=map/key=] is "timestamp" and whose [=map/value=] is a high resolution timestamp that estimates the -[=reading timestamp=] expressed in milliseconds since the [=time origin=]. +[=reading timestamp=] expressed in milliseconds as an [=monotonic clock/unsafe current time=]. -Note: The accuracy of the [=reading timestamp=] estimate depends on the underlying -platform interfaces that expose it. - -The [=latest reading=]["timestamp"] is initially set to null, -unless the [=latest reading=] [=ordered map|map=] caches a previous [=sensor readings|reading=]. +[=Latest reading=]["timestamp"] is initially set to null, unless the [=latest reading=] [=map=] +caches a previous [=sensor readings|reading=]. The other [=map/entries=] of the [=latest reading=] [=ordered map|map=] hold the values of the different quantities measured by the [=platform sensor=]. @@ -1146,11 +1143,14 @@ with the internal slots described in the following table: ### Sensor.timestamp ### {#sensor-timestamp} -The {{Sensor/timestamp!!attribute}} getter steps are to return -the result of invoking [=get value from latest reading=] with [=this=] -and "timestamp" as arguments. +
+ The {{Sensor/timestamp}} getter steps are: -It represents a [=reading timestamp=]. + 1. Let |global| be [=this=]'s [=relevant global object=]. + 2. Let |unsafeTimestamp| be the result of invoking [=get value from latest reading=] with + [=this=] and "timestamp" as arguments. + 3. Return [=relative high resolution time=] with |unsafeTimestamp| and |global|. +
### Sensor.start() ### {#sensor-start} @@ -1437,6 +1437,21 @@ to {{SensorErrorEventInit}}. 1. Let |result| be the result of invoking |type|'s [=threshold check algorithm=] with |reading| and |sensor|'s [=latest reading=]. 1. If |result| is false, then abort these steps. + 1. If |reading|["timestamp"] [=map/exists=]: + + 1. Set |reading|["timestamp"] to the result of converting its current value in an + [=implementation-defined=] way to an [=monotonic clock/unsafe current time=] using the + same [=monotonic clock=] that is shared by [=time origins=]. + + Note: The goal of this step is to ensure that a timestamp that may have been relative to + a different time origin is converted to a value that can be used in computations with + the same [=monotonic clock=] used by the operations described in [[HR-TIME]]. + 1. Otherwise, [=map/set=] |reading|["timestamp"] to the [=unsafe shared current time=]. + + Note: In neither case is an [=monotonic clock/unsafe current time=] ever exposed to script. + {{Sensor/timestamp|Sensor.timestamp}} always returns a [=moment/coarsened moment=] relative + to a [=time origin=]. 1. [=map/For each=] |key| → value of [=latest reading=]. 1. [=map/Set=] [=latest reading=][|key|] to the corresponding value of |reading|.