summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-25 13:01:19 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-25 16:45:48 +0000
commitc21017c7e25188300838448e92567677812285e1 (patch)
tree31a15eab9c7abbc2a390b07a3586678826cbd4d8
parentf0775ea93ab66f0676993db1633c9098dfb3a3ad (diff)
downloadqtwebengine-chromium-c21017c7e25188300838448e92567677812285e1.tar.gz
[Backport] M64: Ensure clamped time always moves forward
This patch fixes a problem where performance.now or Date.now can in rare cases move slightly backwards due to a loss of arithmetic precision. BUG=801341,799127,798964 TBR=skyostil@chromium.org (cherry picked from commit 874bac6e00e5b0b5fe291cc51518e5fd1e83c69d) Reviewed-on: https://chromium-review.googlesource.com/867062 Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Commit-Queue: Sami Kyöstilä <skyostil@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#529407} Reviewed-on: https://chromium-review.googlesource.com/882783 Reviewed-by: Matt Falkenhagen <falken@chromium.org> Cr-Commit-Position: refs/branch-heads/3282@{#588} Cr-Branched-From: 5fdc0fab22ce7efd32532ee989b223fa12f8171e-refs/heads/master@{#520840} Change-Id: If5bdc9933373cf320e9cf2efe8141275ef8c40c4 Reviewed-by: Michael Brüning <michael.bruning@qt.io>
-rw-r--r--chromium/third_party/WebKit/Source/platform/TimeClamper.cpp6
-rw-r--r--chromium/third_party/WebKit/Source/platform/TimeClamperTest.cpp1
2 files changed, 4 insertions, 3 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/TimeClamper.cpp b/chromium/third_party/WebKit/Source/platform/TimeClamper.cpp
index 18244e769f3..2445af4fa33 100644
--- a/chromium/third_party/WebKit/Source/platform/TimeClamper.cpp
+++ b/chromium/third_party/WebKit/Source/platform/TimeClamper.cpp
@@ -18,12 +18,12 @@ TimeClamper::TimeClamper() {
double TimeClamper::ClampTimeResolution(double time_seconds) const {
DCHECK_GE(time_seconds, 0);
- double clamped_time =
- floor(time_seconds / kResolutionSeconds) * kResolutionSeconds;
+ double interval = floor(time_seconds / kResolutionSeconds);
+ double clamped_time = interval * kResolutionSeconds;
double tick_threshold = ThresholdFor(clamped_time);
if (time_seconds >= tick_threshold)
- return clamped_time + kResolutionSeconds;
+ return (interval + 1) * kResolutionSeconds;
return clamped_time;
}
diff --git a/chromium/third_party/WebKit/Source/platform/TimeClamperTest.cpp b/chromium/third_party/WebKit/Source/platform/TimeClamperTest.cpp
index 04e4622c152..b8d1e59c0aa 100644
--- a/chromium/third_party/WebKit/Source/platform/TimeClamperTest.cpp
+++ b/chromium/third_party/WebKit/Source/platform/TimeClamperTest.cpp
@@ -27,6 +27,7 @@ TEST(TimeClamperTest, TimeStampsIncreaseByFixedAmount) {
time_seconds += kInterval * 0.1) {
double clamped_time = clamper.ClampTimeResolution(time_seconds);
double delta = clamped_time - prev;
+ ASSERT_GE(delta, 0);
if (delta > kEpsilon) {
ASSERT_TRUE(std::fabs(delta - kInterval) < kEpsilon);
prev = clamped_time;