Bug 1396227 - Sort performance entries by start time. r?baku draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 02 Sep 2017 21:39:19 +0900
changeset 657990 4761006774ea7d3400cd68226180fabee21d7048
parent 657984 a46a5879b8781ae9ea99f37b5d34a891f0f75047
child 657991 ea9017b0ccb1eb4d02d0eec579f66bd920eb7b5e
push id77660
push userhikezoe@mozilla.com
push dateSat, 02 Sep 2017 12:39:39 +0000
reviewersbaku
bugs1396227
milestone57.0a1
Bug 1396227 - Sort performance entries by start time. r?baku MozReview-Commit-ID: 7m4MLlOJmFZ
dom/performance/Performance.cpp
dom/performance/PerformanceEntry.h
dom/performance/PerformanceObserverEntryList.cpp
testing/web-platform/meta/performance-timeline/po-entries-sort.any.js.ini
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -31,37 +31,16 @@
 
 namespace mozilla {
 namespace dom {
 
 using namespace workers;
 
 namespace {
 
-// Helper classes
-class MOZ_STACK_CLASS PerformanceEntryComparator final
-{
-public:
-  bool Equals(const PerformanceEntry* aElem1,
-              const PerformanceEntry* aElem2) const
-  {
-    MOZ_ASSERT(aElem1 && aElem2,
-               "Trying to compare null performance entries");
-    return aElem1->StartTime() == aElem2->StartTime();
-  }
-
-  bool LessThan(const PerformanceEntry* aElem1,
-                const PerformanceEntry* aElem2) const
-  {
-    MOZ_ASSERT(aElem1 && aElem2,
-               "Trying to compare null performance entries");
-    return aElem1->StartTime() < aElem2->StartTime();
-  }
-};
-
 class PrefEnabledRunnable final
   : public WorkerCheckAPIExposureOnMainThreadRunnable
 {
 public:
   PrefEnabledRunnable(WorkerPrivate* aWorkerPrivate,
                       const nsCString& aPrefName)
     : WorkerCheckAPIExposureOnMainThreadRunnable(aWorkerPrivate)
     , mEnabled(false)
--- a/dom/performance/PerformanceEntry.h
+++ b/dom/performance/PerformanceEntry.h
@@ -89,12 +89,33 @@ public:
 protected:
   virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   nsCOMPtr<nsISupports> mParent;
   nsString mName;
   nsString mEntryType;
 };
 
+// Helper classes
+class MOZ_STACK_CLASS PerformanceEntryComparator final
+{
+public:
+  bool Equals(const PerformanceEntry* aElem1,
+              const PerformanceEntry* aElem2) const
+  {
+    MOZ_ASSERT(aElem1 && aElem2,
+               "Trying to compare null performance entries");
+    return aElem1->StartTime() == aElem2->StartTime();
+  }
+
+  bool LessThan(const PerformanceEntry* aElem1,
+                const PerformanceEntry* aElem2) const
+  {
+    MOZ_ASSERT(aElem1 && aElem2,
+               "Trying to compare null performance entries");
+    return aElem1->StartTime() < aElem2->StartTime();
+  }
+};
+
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_PerformanceEntry_h___ */
--- a/dom/performance/PerformanceObserverEntryList.cpp
+++ b/dom/performance/PerformanceObserverEntryList.cpp
@@ -61,36 +61,39 @@ PerformanceObserverEntryList::GetEntries
     }
     if (aFilter.mEntryType.WasPassed() &&
         !entry->GetEntryType().Equals(aFilter.mEntryType.Value())) {
       continue;
     }
 
     aRetval.AppendElement(entry);
   }
+  aRetval.Sort(PerformanceEntryComparator());
 }
 
 void
 PerformanceObserverEntryList::GetEntriesByType(
   const nsAString& aEntryType,
   nsTArray<RefPtr<PerformanceEntry>>& aRetval)
 {
   aRetval.Clear();
   for (const RefPtr<PerformanceEntry>& entry : mEntries) {
     if (entry->GetEntryType().Equals(aEntryType)) {
       aRetval.AppendElement(entry);
     }
   }
+  aRetval.Sort(PerformanceEntryComparator());
 }
 
 void
 PerformanceObserverEntryList::GetEntriesByName(
   const nsAString& aName,
   const Optional<nsAString>& aEntryType,
   nsTArray<RefPtr<PerformanceEntry>>& aRetval)
 {
   aRetval.Clear();
   for (const RefPtr<PerformanceEntry>& entry : mEntries) {
     if (entry->GetName().Equals(aName)) {
       aRetval.AppendElement(entry);
     }
   }
+  aRetval.Sort(PerformanceEntryComparator());
 }
deleted file mode 100644
--- a/testing/web-platform/meta/performance-timeline/po-entries-sort.any.js.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-[po-entries-sort.any.worker.html]
-  type: testharness
-  [getEntries, getEntriesByType, getEntriesByName sort order]
-    expected: FAIL
-
-
-[po-entries-sort.any.html]
-  type: testharness
-  [getEntries, getEntriesByType, getEntriesByName sort order]
-    expected: FAIL
-