Skip to content

Commit

Permalink
Bug 1767063 - make PerformanceEntry.mEpoch narrowing conversion expli…
Browse files Browse the repository at this point in the history
…cit. r=sefeng

The converted value gets passed into TimingNotification which assigns the value
into a PerformanceEntry (this is the only usage). Since PerformanceEntry is
defined in WebIDL, we could not change its types (which is double for mEpoch) so
we were forced to safely convert the value where we did.

I don't think the existing conversion code had any bugs since we converted a
64-bit signed integer timestamp into uint64_t (safe) into a double (which is
safe for the reasons mentioned in the code comments).

Differential Revision: https://phabricator.services.mozilla.com/D145142
  • Loading branch information
mcomella committed May 18, 2022
1 parent b60432d commit 3f9fef6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dom/performance/Performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void Performance::LogEntry(PerformanceEntry* aEntry,

void Performance::TimingNotification(PerformanceEntry* aEntry,
const nsACString& aOwner,
uint64_t aEpoch) {
const double aEpoch) {
PerformanceEntryEventInit init;
init.mBubbles = false;
init.mCancelable = false;
Expand Down
2 changes: 1 addition & 1 deletion dom/performance/Performance.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Performance : public DOMEventTargetHelper {

void LogEntry(PerformanceEntry* aEntry, const nsACString& aOwner) const;
void TimingNotification(PerformanceEntry* aEntry, const nsACString& aOwner,
uint64_t epoch);
const double aEpoch);

void RunNotificationObserversTask();
void QueueEntry(PerformanceEntry* aEntry);
Expand Down
8 changes: 6 additions & 2 deletions dom/performance/PerformanceMainThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ void PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) {
MOZ_ASSERT(NS_IsMainThread());

nsAutoCString uri;
uint64_t markCreationEpoch = 0;
double markCreationEpoch = 0;

if (StaticPrefs::dom_performance_enable_user_timing_logging() ||
StaticPrefs::dom_performance_enable_notify_performance_timing()) {
Expand All @@ -419,7 +419,11 @@ void PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) {
// If we have no URI, just put in "none".
uri.AssignLiteral("none");
}
markCreationEpoch = static_cast<uint64_t>(PR_Now() / PR_USEC_PER_MSEC);

// PR_Now() returns a signed 64-bit integer. Since it represents a
// timestamp, only ~32-bits will represent the value which should safely fit
// into a double.
markCreationEpoch = static_cast<double>(PR_Now() / PR_USEC_PER_MSEC);

if (StaticPrefs::dom_performance_enable_user_timing_logging()) {
Performance::LogEntry(aEntry, uri);
Expand Down

0 comments on commit 3f9fef6

Please sign in to comment.