Bug 1186489 - Apply the performance.now() resolution clamping in workers as well. r=froydnj, a=lizzard
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 22 Jul 2015 13:22:16 -0400
changeset 281732 15b3cf5a28315068105dcd0d65e80599f99ef2ba
parent 281731 81288e78a1d4cb2020d1232c7c137410c63a652d
child 281733 d0d33fb9835e7daebd4e0936e7c0b89a88dd1aca
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lizzard
bugs1186489
milestone41.0a2
Bug 1186489 - Apply the performance.now() resolution clamping in workers as well. r=froydnj, a=lizzard
dom/base/nsPerformance.cpp
dom/workers/Performance.cpp
--- a/dom/base/nsPerformance.cpp
+++ b/dom/base/nsPerformance.cpp
@@ -497,18 +497,19 @@ nsPerformance::Navigation()
   }
   return mNavigation;
 }
 
 DOMHighResTimeStamp
 nsPerformance::Now() const
 {
   double nowTimeMs = GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
-  // Round down to the nearest 0.005ms (5us), because if the timer is too
-  // accurate people can do nasty timing attacks with it.
+  // Round down to the nearest 5us, because if the timer is too accurate people
+  // can do nasty timing attacks with it.  See similar code in the worker
+  // Performance implementation.
   const double maxResolutionMs = 0.005;
   return floor(nowTimeMs / maxResolutionMs) * maxResolutionMs;
 }
 
 JSObject*
 nsPerformance::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
 {
   return PerformanceBinding::Wrap(cx, this, aGivenProto);
--- a/dom/workers/Performance.cpp
+++ b/dom/workers/Performance.cpp
@@ -28,17 +28,22 @@ Performance::WrapObject(JSContext* aCx, 
   return PerformanceBinding_workers::Wrap(aCx, this, aGivenProto);
 }
 
 DOMHighResTimeStamp
 Performance::Now() const
 {
   TimeDuration duration =
     TimeStamp::Now() - mWorkerPrivate->NowBaseTimeStamp();
-  return duration.ToMilliseconds();
+  double nowTime = duration.ToMilliseconds();
+  // Round down to the nearest 5us, because if the timer is too accurate people
+  // can do nasty timing attacks with it.  See similar code in the non-worker
+  // Performance implementation.
+  const double maxResolutionMs = 0.005;
+  return floor(nowTime / maxResolutionMs) * maxResolutionMs;
 }
 
 // To be removed once bug 1124165 lands
 bool
 Performance::IsPerformanceTimingAttribute(const nsAString& aName)
 {
   // In workers we just support navigationStart.
   return aName.EqualsASCII("navigationStart");