Skip to main content

script/dom/bindings/
reflector.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 script_bindings::reflector::DomGlobalGeneric;
6use script_bindings::root::DomRoot;
7
8use crate::DomTypeHolder;
9use crate::dom::types::GlobalScope;
10
11pub(crate) trait DomGlobal {
12    /// Returns the [relevant global] in the same realm as the callee object.
13    /// Will enter the realm of the global to ensure the global is only
14    /// accessed from the correct realm.
15    ///
16    /// [relevant global]: https://html.spec.whatwg.org/multipage/#concept-relevant-global
17    fn global(&self) -> DomRoot<GlobalScope>;
18}
19
20impl<T: DomGlobalGeneric<DomTypeHolder>> DomGlobal for T {
21    fn global(&self) -> DomRoot<GlobalScope> {
22        <Self as DomGlobalGeneric<DomTypeHolder>>::global_from_reflector(self)
23    }
24}