mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: Expose new methods for obtaining a global that require a realm. (#36116)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
73e7d38a8d
commit
1df1ba58d6
7 changed files with 42 additions and 19 deletions
|
@ -12,7 +12,7 @@ use crate::dom::bindings::iterable::{Iterable, IterableIterator};
|
|||
use crate::dom::bindings::root::{Dom, DomRoot, Root};
|
||||
use crate::dom::bindings::trace::JSTraceable;
|
||||
use crate::dom::globalscope::{GlobalScope, GlobalScopeHelpers};
|
||||
use crate::realms::AlreadyInRealm;
|
||||
use crate::realms::{AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
|
||||
/// Create the reflector for a new DOM object and yield ownership to the
|
||||
|
@ -43,6 +43,16 @@ where
|
|||
}
|
||||
|
||||
pub(crate) trait DomGlobalGeneric<D: DomTypes>: DomObject {
|
||||
/// Returns the [`GlobalScope`] of the realm that the [`DomObject`] was created in. If this
|
||||
/// object is a `Node`, this will be different from it's owning `Document` if adopted by. For
|
||||
/// `Node`s it's almost always better to use `NodeTraits::owning_global`.
|
||||
fn global_(&self, realm: InRealm) -> DomRoot<D::GlobalScope>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
D::GlobalScope::from_reflector(self, realm)
|
||||
}
|
||||
|
||||
/// Returns the [`GlobalScope`] of the realm that the [`DomObject`] was created in. If this
|
||||
/// object is a `Node`, this will be different from it's owning `Document` if adopted by. For
|
||||
/// `Node`s it's almost always better to use `NodeTraits::owning_global`.
|
||||
|
@ -51,17 +61,21 @@ pub(crate) trait DomGlobalGeneric<D: DomTypes>: DomObject {
|
|||
Self: Sized,
|
||||
{
|
||||
let realm = AlreadyInRealm::assert_for_cx(D::GlobalScope::get_cx());
|
||||
D::GlobalScope::from_reflector(self, &realm)
|
||||
D::GlobalScope::from_reflector(self, InRealm::already(&realm))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DomTypes, T: DomObject> DomGlobalGeneric<D> for T {}
|
||||
|
||||
pub(crate) trait DomGlobal {
|
||||
fn global_(&self, realm: InRealm) -> DomRoot<GlobalScope>;
|
||||
fn global(&self) -> DomRoot<GlobalScope>;
|
||||
}
|
||||
|
||||
impl<T: DomGlobalGeneric<crate::DomTypeHolder>> DomGlobal for T {
|
||||
fn global_(&self, realm: InRealm) -> DomRoot<GlobalScope> {
|
||||
<Self as DomGlobalGeneric<crate::DomTypeHolder>>::global_(self, realm)
|
||||
}
|
||||
fn global(&self) -> DomRoot<GlobalScope> {
|
||||
<Self as DomGlobalGeneric<crate::DomTypeHolder>>::global(self)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue