mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Clean up the functions to retrieve a global root from JS objects
This commit is contained in:
parent
e179cb02ff
commit
34858fd0c9
2 changed files with 23 additions and 28 deletions
|
@ -164,7 +164,7 @@ impl CallSetup {
|
|||
/// Performs the setup needed to make a call.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
|
||||
let global = global_root_from_object(callback.callback());
|
||||
let global = unsafe { global_root_from_object(callback.callback()) };
|
||||
let cx = global.r().get_cx();
|
||||
|
||||
let exception_compartment = unsafe {
|
||||
|
|
|
@ -302,13 +302,13 @@ impl GlobalRoot {
|
|||
|
||||
/// Returns the global object of the realm that the given DOM object's reflector was created in.
|
||||
pub fn global_root_from_reflector<T: Reflectable>(reflector: &T) -> GlobalRoot {
|
||||
global_root_from_object(*reflector.reflector().get_jsobject())
|
||||
unsafe { global_root_from_object(*reflector.reflector().get_jsobject()) }
|
||||
}
|
||||
|
||||
/// Returns the Rust global object from a JS global object.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn global_root_from_global(global: *mut JSObject) -> GlobalRoot {
|
||||
unsafe {
|
||||
unsafe fn global_root_from_global(global: *mut JSObject) -> GlobalRoot {
|
||||
assert!(!global.is_null());
|
||||
let clasp = JS_GetClass(global);
|
||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||
match root_from_object(global) {
|
||||
|
@ -323,23 +323,18 @@ pub fn global_root_from_global(global: *mut JSObject) -> GlobalRoot {
|
|||
|
||||
panic!("found DOM global that doesn't unwrap to Window or WorkerGlobalScope")
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global object of the realm that the given JS object was created in.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn global_root_from_object(obj: *mut JSObject) -> GlobalRoot {
|
||||
unsafe {
|
||||
pub unsafe fn global_root_from_object(obj: *mut JSObject) -> GlobalRoot {
|
||||
assert!(!obj.is_null());
|
||||
let global = GetGlobalForObjectCrossCompartment(obj);
|
||||
global_root_from_global(global)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global object for the given JSContext
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn global_root_from_context(cx: *mut JSContext) -> GlobalRoot {
|
||||
unsafe {
|
||||
pub unsafe fn global_root_from_context(cx: *mut JSContext) -> GlobalRoot {
|
||||
let global = CurrentGlobalOrNull(cx);
|
||||
assert!(!global.is_null());
|
||||
global_root_from_global(global)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue