Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / performance / PerformanceEventTiming.h
blob3f39610d95501ba656f90ec99b924a25317ab9eb
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_PerformanceEventTiming_h___
8 #define mozilla_dom_PerformanceEventTiming_h___
10 #include "mozilla/dom/PerformanceEntry.h"
11 #include "mozilla/EventForwards.h"
12 #include "nsRFPService.h"
13 #include "Performance.h"
14 #include "nsIWeakReferenceUtils.h"
15 #include "nsINode.h"
17 namespace mozilla {
18 class WidgetEvent;
19 namespace dom {
21 class PerformanceEventTiming final
22 : public PerformanceEntry,
23 public LinkedListElement<RefPtr<PerformanceEventTiming>> {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PerformanceEventTiming,
28 PerformanceEntry)
30 static already_AddRefed<PerformanceEventTiming> TryGenerateEventTiming(
31 const EventTarget* aTarget, const WidgetEvent* aEvent);
33 already_AddRefed<PerformanceEventTiming> Clone() {
34 RefPtr<PerformanceEventTiming> eventTiming =
35 new PerformanceEventTiming(*this);
36 return eventTiming.forget();
39 JSObject* WrapObject(JSContext* cx,
40 JS::Handle<JSObject*> aGivenProto) override;
42 DOMHighResTimeStamp ProcessingStart() const {
43 if (mCachedProcessingStart.isNothing()) {
44 mCachedProcessingStart.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
45 mProcessingStart, mPerformance->GetRandomTimelineSeed(),
46 mPerformance->GetRTPCallerType()));
48 return mCachedProcessingStart.value();
51 DOMHighResTimeStamp ProcessingEnd() const {
52 if (mCachedProcessingEnd.isNothing()) {
53 mCachedProcessingEnd.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
54 mProcessingEnd, mPerformance->GetRandomTimelineSeed(),
55 mPerformance->GetRTPCallerType()));
57 return mCachedProcessingEnd.value();
60 bool Cancelable() const { return mCancelable; }
62 nsINode* GetTarget() const;
64 void SetDuration(const DOMHighResTimeStamp aDuration) {
65 mDuration = aDuration;
68 // nsRFPService::ReduceTimePrecisionAsMSecs might causes
69 // some memory overhead, using the raw timestamp internally
70 // to avoid calling in unnecessarily.
71 DOMHighResTimeStamp RawDuration() const { return mDuration; }
73 DOMHighResTimeStamp Duration() const override {
74 if (mCachedDuration.isNothing()) {
75 mCachedDuration.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
76 mDuration, mPerformance->GetRandomTimelineSeed(),
77 mPerformance->GetRTPCallerType()));
79 return mCachedDuration.value();
82 // Similar as RawDuration; Used to avoid calling
83 // nsRFPService::ReduceTimePrecisionAsMSecs unnecessarily.
84 DOMHighResTimeStamp RawStartTime() const { return mStartTime; }
86 DOMHighResTimeStamp StartTime() const override {
87 if (mCachedStartTime.isNothing()) {
88 mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
89 mStartTime, mPerformance->GetRandomTimelineSeed(),
90 mPerformance->GetRTPCallerType()));
92 return mCachedStartTime.value();
95 bool ShouldAddEntryToBuffer(double aDuration) const;
96 bool ShouldAddEntryToObserverBuffer(PerformanceObserverInit&) const override;
98 void BufferEntryIfNeeded() override;
100 void FinalizeEventTiming(EventTarget* aTarget);
102 EventMessage GetMessage() const { return mMessage; }
104 private:
105 PerformanceEventTiming(Performance* aPerformance, const nsAString& aName,
106 const TimeStamp& aStartTime, bool aIsCacelable,
107 EventMessage aMessage);
109 PerformanceEventTiming(const PerformanceEventTiming& aEventTimingEntry);
111 ~PerformanceEventTiming() = default;
113 RefPtr<Performance> mPerformance;
115 DOMHighResTimeStamp mProcessingStart;
116 mutable Maybe<DOMHighResTimeStamp> mCachedProcessingStart;
118 DOMHighResTimeStamp mProcessingEnd;
119 mutable Maybe<DOMHighResTimeStamp> mCachedProcessingEnd;
121 nsWeakPtr mTarget;
123 DOMHighResTimeStamp mStartTime;
124 mutable Maybe<DOMHighResTimeStamp> mCachedStartTime;
126 DOMHighResTimeStamp mDuration;
127 mutable Maybe<DOMHighResTimeStamp> mCachedDuration;
129 bool mCancelable;
131 EventMessage mMessage;
133 } // namespace dom
134 } // namespace mozilla
136 #endif