diff options
author | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-01-30 21:45:18 -0500 |
---|---|---|
committer | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-02-03 09:54:39 -0500 |
commit | 8e65782efb547eba812106df056199b87ae9eb2a (patch) | |
tree | a4f466b3dd066bd225d74b50a1bb99b391182283 /components/script/dom/performance.rs | |
parent | 5f55cd5d71df9c555fbc24777168396ddd539f28 (diff) | |
download | servo-8e65782efb547eba812106df056199b87ae9eb2a.tar.gz servo-8e65782efb547eba812106df056199b87ae9eb2a.zip |
Expose DOMHighResTimeStamps at lower res
Diffstat (limited to 'components/script/dom/performance.rs')
-rw-r--r-- | components/script/dom/performance.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/components/script/dom/performance.rs b/components/script/dom/performance.rs index b1f72f405f2..33e39303cb4 100644 --- a/components/script/dom/performance.rs +++ b/components/script/dom/performance.rs @@ -401,12 +401,12 @@ impl PerformanceMethods for Performance { // https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now fn Now(&self) -> DOMHighResTimeStamp { - Finite::wrap(self.now()) + reduce_timing_resolution(self.now()) } // https://www.w3.org/TR/hr-time-2/#dom-performance-timeorigin fn TimeOrigin(&self) -> DOMHighResTimeStamp { - Finite::wrap(self.navigation_start_precise as f64) + reduce_timing_resolution(self.navigation_start_precise as f64) } // https://www.w3.org/TR/performance-timeline-2/#dom-performance-getentries @@ -525,3 +525,14 @@ impl PerformanceMethods for Performance { SetOnresourcetimingbufferfull ); } + +// https://www.w3.org/TR/hr-time-2/#clock-resolution +pub fn reduce_timing_resolution(exact: f64) -> DOMHighResTimeStamp { + // We need a granularity no finer than 5 microseconds. + // 5 microseconds isn't an exactly representable f64 so WPT tests + // might occasionally corner-case on rounding. + // web-platform-tests/wpt#21526 wants us to use an integer number of + // microseconds; the next divisor of milliseconds up from 5 microseconds + // is 10, which is 1/100th of a millisecond. + Finite::wrap((exact * 100.0).floor() / 100.0) +} |