Bug 1396227 - Sort performance entries by start time. r?baku
MozReview-Commit-ID: 7m4MLlOJmFZ
--- 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
-