Bug 1440195 For timestamps that are absolute, specify a null context pointer r=baku a=jcristau
authorTom Ritter <tom@mozilla.com>
Wed, 28 Feb 2018 15:37:26 -0600
changeset 462739 f5fca57484d031e2337eb959d857107207c8f21a
parent 462738 e2434dc015192883bdb5cd01012d1b4d38ca5747
child 462740 86ba2db234ae739265e73a863a0ed3c4360bcc35
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, jcristau
bugs1440195
milestone60.0
Bug 1440195 For timestamps that are absolute, specify a null context pointer r=baku a=jcristau 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
dom/file/BaseBlobImpl.cpp
dom/file/MultipartBlobImpl.cpp
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- 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,