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 #include "PerformanceObserverEntryList.h"
9 #include "mozilla/dom/Performance.h"
10 #include "mozilla/dom/PerformanceObserverEntryListBinding.h"
12 #include "PerformanceResourceTiming.h"
14 using namespace mozilla
;
15 using namespace mozilla::dom
;
17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceObserverEntryList
, mOwner
,
20 NS_IMPL_CYCLE_COLLECTING_ADDREF(PerformanceObserverEntryList
)
21 NS_IMPL_CYCLE_COLLECTING_RELEASE(PerformanceObserverEntryList
)
23 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceObserverEntryList
)
24 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
25 NS_INTERFACE_MAP_ENTRY(nsISupports
)
28 PerformanceObserverEntryList::~PerformanceObserverEntryList() = default;
30 JSObject
* PerformanceObserverEntryList::WrapObject(
31 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
32 return PerformanceObserverEntryList_Binding::Wrap(aCx
, this, aGivenProto
);
35 void PerformanceObserverEntryList::GetEntries(
36 const PerformanceEntryFilterOptions
& aFilter
,
37 nsTArray
<RefPtr
<PerformanceEntry
>>& aRetval
) {
40 aFilter
.mName
.WasPassed() ? NS_Atomize(aFilter
.mName
.Value()) : nullptr;
41 RefPtr
<nsAtom
> entryType
= aFilter
.mEntryType
.WasPassed()
42 ? NS_Atomize(aFilter
.mEntryType
.Value())
44 for (const RefPtr
<PerformanceEntry
>& entry
: mEntries
) {
45 if (aFilter
.mInitiatorType
.WasPassed()) {
46 const PerformanceResourceTiming
* resourceEntry
=
47 entry
->ToResourceTiming();
51 nsAutoString initiatorType
;
52 resourceEntry
->GetInitiatorType(initiatorType
);
53 if (!initiatorType
.Equals(aFilter
.mInitiatorType
.Value())) {
57 if (name
&& entry
->GetName() != name
) {
60 if (entryType
&& entry
->GetEntryType() != entryType
) {
64 aRetval
.AppendElement(entry
);
66 aRetval
.Sort(PerformanceEntryComparator());
69 void PerformanceObserverEntryList::GetEntriesByType(
70 const nsAString
& aEntryType
, nsTArray
<RefPtr
<PerformanceEntry
>>& aRetval
) {
72 RefPtr
<nsAtom
> entryType
= NS_Atomize(aEntryType
);
73 for (const RefPtr
<PerformanceEntry
>& entry
: mEntries
) {
74 if (entry
->GetEntryType() == entryType
) {
75 aRetval
.AppendElement(entry
);
78 aRetval
.Sort(PerformanceEntryComparator());
81 void PerformanceObserverEntryList::GetEntriesByName(
82 const nsAString
& aName
, const Optional
<nsAString
>& aEntryType
,
83 nsTArray
<RefPtr
<PerformanceEntry
>>& aRetval
) {
85 RefPtr
<nsAtom
> name
= NS_Atomize(aName
);
86 RefPtr
<nsAtom
> entryType
=
87 aEntryType
.WasPassed() ? NS_Atomize(aEntryType
.Value()) : nullptr;
88 for (const RefPtr
<PerformanceEntry
>& entry
: mEntries
) {
89 if (entry
->GetName() != name
) {
93 if (entryType
&& entry
->GetEntryType() != entryType
) {
97 aRetval
.AppendElement(entry
);
99 aRetval
.Sort(PerformanceEntryComparator());