Bug 1186489. Apply the performance.now() resolution clamping in workers as well. r=froydnj

This commit is contained in:
Boris Zbarsky 2015-07-22 13:22:16 -04:00
parent f6c9647300
commit 596c29aaff
2 changed files with 9 additions and 3 deletions

View File

@ -502,8 +502,9 @@ 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;
}

View File

@ -33,7 +33,12 @@ 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