Bug 1440195 For timestamps that are absolute, specify a null context pointer r?baku
Note that by not using the same context pointer for all timestamps within a single
'communication group' (that is, all things that can communication to each other
in JavaScript), it's possible to observe time going backwards.
Imagine comparing
performance.timeOrigin + performance.now() < new File([], "").lastModified
In theory this should always be true. However, if performance.now() was jittered
up (using one context pointer, because it is a relative timestamp) and File was
jittered down (using a null context pointer, because it is an absolute timestamp)
then this may evaluate to False.
I think this is okay.
MozReview-Commit-ID: BfgbmGS8XdD
--- a/dom/file/BaseBlobImpl.cpp
+++ b/dom/file/BaseBlobImpl.cpp
@@ -59,17 +59,18 @@ BaseBlobImpl::GetType(nsAString& aType)
aType = mContentType;
}
int64_t
BaseBlobImpl::GetLastModified(ErrorResult& aRv)
{
MOZ_ASSERT(mIsFile, "Should only be called on files");
if (IsDateUnknown()) {
- mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now());
+ mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now(), 0);
+ // mLastModificationDate is an absolute timestamp so we supply a zero context mix-in
}
return mLastModificationDate / PR_USEC_PER_MSEC;
}
void
BaseBlobImpl::SetLastModified(int64_t aLastModified)
{
--- a/dom/file/MultipartBlobImpl.cpp
+++ b/dom/file/MultipartBlobImpl.cpp
@@ -264,17 +264,18 @@ MultipartBlobImpl::SetLengthAndModifiedD
mLength = totalLength;
if (mIsFile) {
// We cannot use PR_Now() because bug 493756 and, for this reason:
// var x = new Date(); var f = new File(...);
// x.getTime() < f.dateModified.getTime()
// could fail.
mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(
- lastModifiedSet ? lastModified * PR_USEC_PER_MSEC : JS_Now());
+ lastModifiedSet ? lastModified * PR_USEC_PER_MSEC : JS_Now(), 0);
+ // mLastModificationDate is an absolute timestamp so we supply a zero context mix-in
}
}
void
MultipartBlobImpl::GetMozFullPathInternal(nsAString& aFilename,
ErrorResult& aRv) const
{
if (!mIsFromNsIFile || mBlobImpls.Length() == 0) {
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -552,17 +552,17 @@ nsRFPService::ReduceTimePrecisionAsUSecs
/* static */
double
nsRFPService::ReduceTimePrecisionAsUSecsWrapper(double aTime)
{
return nsRFPService::ReduceTimePrecisionImpl(
aTime,
MicroSeconds,
TimerResolution(),
- 0,
+ 0, /* For absolute timestamps (all the JS engine does), supply zero context mixin */
TimerPrecisionType::All);
}
/* static */
double
nsRFPService::ReduceTimePrecisionAsMSecs(
double aTime,
int64_t aContextMixin,