Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / performance / PerformanceObserverEntryList.cpp
blobaf4d867cd7d71d7a3ccfb470886837b44f69bfbe
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"
11 #include "nsString.h"
12 #include "PerformanceResourceTiming.h"
14 using namespace mozilla;
15 using namespace mozilla::dom;
17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceObserverEntryList, mOwner,
18 mEntries)
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)
26 NS_INTERFACE_MAP_END
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) {
38 aRetval.Clear();
39 RefPtr<nsAtom> name =
40 aFilter.mName.WasPassed() ? NS_Atomize(aFilter.mName.Value()) : nullptr;
41 RefPtr<nsAtom> entryType = aFilter.mEntryType.WasPassed()
42 ? NS_Atomize(aFilter.mEntryType.Value())
43 : nullptr;
44 for (const RefPtr<PerformanceEntry>& entry : mEntries) {
45 if (aFilter.mInitiatorType.WasPassed()) {
46 const PerformanceResourceTiming* resourceEntry =
47 entry->ToResourceTiming();
48 if (!resourceEntry) {
49 continue;
51 nsAutoString initiatorType;
52 resourceEntry->GetInitiatorType(initiatorType);
53 if (!initiatorType.Equals(aFilter.mInitiatorType.Value())) {
54 continue;
57 if (name && entry->GetName() != name) {
58 continue;
60 if (entryType && entry->GetEntryType() != entryType) {
61 continue;
64 aRetval.AppendElement(entry);
66 aRetval.Sort(PerformanceEntryComparator());
69 void PerformanceObserverEntryList::GetEntriesByType(
70 const nsAString& aEntryType, nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
71 aRetval.Clear();
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) {
84 aRetval.Clear();
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) {
90 continue;
93 if (entryType && entry->GetEntryType() != entryType) {
94 continue;
97 aRetval.AppendElement(entry);
99 aRetval.Sort(PerformanceEntryComparator());