Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / performance / PerformanceEntry.h
blob37a13105f9e2980da2e80b770c989676fdb8380d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PerformanceEntry_h___
8 #define mozilla_dom_PerformanceEntry_h___
10 #include "nsDOMNavigationTiming.h"
11 #include "nsString.h"
12 #include "nsWrapperCache.h"
13 #include "nsAtom.h"
14 #include "mozilla/dom/PerformanceObserverBinding.h"
16 class nsISupports;
18 namespace mozilla::dom {
19 class PerformanceResourceTiming;
21 // http://www.w3.org/TR/performance-timeline/#performanceentry
22 class PerformanceEntry : public nsISupports, public nsWrapperCache {
23 protected:
24 virtual ~PerformanceEntry();
26 public:
27 PerformanceEntry(nsISupports* aParent, const nsAString& aName,
28 const nsAString& aEntryType);
30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceEntry)
33 nsISupports* GetParentObject() const { return mParent; }
35 void GetName(nsAString& aName) const {
36 if (mName) {
37 mName->ToString(aName);
41 const nsAtom* GetName() const { return mName; }
43 void GetEntryType(nsAString& aEntryType) const {
44 if (mEntryType) {
45 mEntryType->ToString(aEntryType);
49 const nsAtom* GetEntryType() const { return mEntryType; }
51 void SetEntryType(const nsAString& aEntryType) {
52 mEntryType = NS_Atomize(aEntryType);
55 virtual DOMHighResTimeStamp StartTime() const { return 0; }
57 // This is used by the Gecko Profiler only for adding precise markers.
58 // It's not exposed to JS.
59 virtual DOMHighResTimeStamp UnclampedStartTime() const {
60 MOZ_ASSERT(false, "UnclampedStartTime should not be called on this class.");
61 return 0;
64 virtual DOMHighResTimeStamp Duration() const { return 0; }
66 virtual const PerformanceResourceTiming* ToResourceTiming() const {
67 return nullptr;
70 virtual bool ShouldAddEntryToObserverBuffer(
71 PerformanceObserverInit& aOption) const;
73 virtual void BufferEntryIfNeeded() {}
75 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
77 protected:
78 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
80 private:
81 nsCOMPtr<nsISupports> mParent;
82 RefPtr<nsAtom> mName;
83 RefPtr<nsAtom> mEntryType;
86 // Helper classes
87 class MOZ_STACK_CLASS PerformanceEntryComparator final {
88 public:
89 bool Equals(const PerformanceEntry* aElem1,
90 const PerformanceEntry* aElem2) const {
91 MOZ_ASSERT(aElem1 && aElem2, "Trying to compare null performance entries");
92 return aElem1->StartTime() == aElem2->StartTime();
95 bool LessThan(const PerformanceEntry* aElem1,
96 const PerformanceEntry* aElem2) const {
97 MOZ_ASSERT(aElem1 && aElem2, "Trying to compare null performance entries");
98 return aElem1->StartTime() < aElem2->StartTime();
102 } // namespace mozilla::dom
104 #endif /* mozilla_dom_PerformanceEntry_h___ */