script/dom/
testbindingsetlikewithinterface.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
5// check-tidy: no specs after this line
6
7use dom_struct::dom_struct;
8use indexmap::IndexSet;
9use js::rust::HandleObject;
10
11use super::bindings::like::Setlike;
12use crate::dom::bindings::cell::DomRefCell;
13use crate::dom::bindings::codegen::Bindings::TestBindingSetlikeWithInterfaceBinding::TestBindingSetlikeWithInterfaceMethods;
14use crate::dom::bindings::error::Fallible;
15use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
16use crate::dom::bindings::root::DomRoot;
17use crate::dom::globalscope::GlobalScope;
18use crate::dom::testbinding::TestBinding;
19use crate::script_runtime::CanGc;
20use crate::setlike;
21
22// setlike<TestBinding>
23#[dom_struct]
24pub(crate) struct TestBindingSetlikeWithInterface {
25    reflector: Reflector,
26    #[custom_trace]
27    internal: DomRefCell<IndexSet<DomRoot<TestBinding>>>,
28}
29
30impl TestBindingSetlikeWithInterface {
31    fn new(
32        global: &GlobalScope,
33        proto: Option<HandleObject>,
34        can_gc: CanGc,
35    ) -> DomRoot<TestBindingSetlikeWithInterface> {
36        reflect_dom_object_with_proto(
37            Box::new(TestBindingSetlikeWithInterface {
38                reflector: Reflector::new(),
39                internal: DomRefCell::new(IndexSet::new()),
40            }),
41            global,
42            proto,
43            can_gc,
44        )
45    }
46}
47
48impl TestBindingSetlikeWithInterfaceMethods<crate::DomTypeHolder>
49    for TestBindingSetlikeWithInterface
50{
51    fn Constructor(
52        global: &GlobalScope,
53        proto: Option<HandleObject>,
54        can_gc: CanGc,
55    ) -> Fallible<DomRoot<TestBindingSetlikeWithInterface>> {
56        Ok(TestBindingSetlikeWithInterface::new(global, proto, can_gc))
57    }
58
59    fn Size(&self) -> u32 {
60        self.internal.size()
61    }
62}
63
64impl Setlike for TestBindingSetlikeWithInterface {
65    type Key = DomRoot<TestBinding>;
66
67    setlike!(self, internal);
68}