script/dom/
performanceobserverentrylist.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use crate::dom::bindings::cell::DomRefCell;
8use crate::dom::bindings::codegen::Bindings::PerformanceObserverEntryListBinding::PerformanceObserverEntryListMethods;
9use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::bindings::str::DOMString;
12use crate::dom::globalscope::GlobalScope;
13use crate::dom::performance::PerformanceEntryList;
14use crate::dom::performanceentry::PerformanceEntry;
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct PerformanceObserverEntryList {
19    reflector_: Reflector,
20    entries: DomRefCell<PerformanceEntryList>,
21}
22
23impl PerformanceObserverEntryList {
24    fn new_inherited(entries: PerformanceEntryList) -> PerformanceObserverEntryList {
25        PerformanceObserverEntryList {
26            reflector_: Reflector::new(),
27            entries: DomRefCell::new(entries),
28        }
29    }
30
31    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
32    pub(crate) fn new(
33        global: &GlobalScope,
34        entries: PerformanceEntryList,
35        can_gc: CanGc,
36    ) -> DomRoot<PerformanceObserverEntryList> {
37        let observer_entry_list = PerformanceObserverEntryList::new_inherited(entries);
38        reflect_dom_object(Box::new(observer_entry_list), global, can_gc)
39    }
40}
41
42impl PerformanceObserverEntryListMethods<crate::DomTypeHolder> for PerformanceObserverEntryList {
43    // https://w3c.github.io/performance-timeline/#dom-performanceobserver
44    fn GetEntries(&self) -> Vec<DomRoot<PerformanceEntry>> {
45        self.entries
46            .borrow()
47            .get_entries_by_name_and_type(None, None)
48    }
49
50    // https://w3c.github.io/performance-timeline/#dom-performanceobserver
51    fn GetEntriesByType(&self, entry_type: DOMString) -> Vec<DomRoot<PerformanceEntry>> {
52        self.entries
53            .borrow()
54            .get_entries_by_name_and_type(None, Some(entry_type))
55    }
56
57    // https://w3c.github.io/performance-timeline/#dom-performanceobserver
58    fn GetEntriesByName(
59        &self,
60        name: DOMString,
61        entry_type: Option<DOMString>,
62    ) -> Vec<DomRoot<PerformanceEntry>> {
63        self.entries
64            .borrow()
65            .get_entries_by_name_and_type(Some(name), entry_type)
66    }
67}