mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Pass a MutableHandleObject to create_global_object
This commit is contained in:
parent
5f59bb2e0c
commit
0729000b56
2 changed files with 21 additions and 22 deletions
|
@ -2513,12 +2513,13 @@ class CGWrapGlobalMethod(CGAbstractMethod):
|
||||||
let raw = Box::into_raw(object);
|
let raw = Box::into_raw(object);
|
||||||
let _rt = RootedTraceable::new(&*raw);
|
let _rt = RootedTraceable::new(&*raw);
|
||||||
|
|
||||||
rooted!(in(cx) let obj =
|
rooted!(in(cx) let mut obj = ptr::null_mut());
|
||||||
create_global_object(
|
create_global_object(
|
||||||
cx,
|
cx,
|
||||||
&*(&Class.base as *const js::jsapi::Class as *const _),
|
&*(&Class.base as *const js::jsapi::Class as *const _),
|
||||||
raw as *const libc::c_void,
|
raw as *const libc::c_void,
|
||||||
_trace));
|
_trace,
|
||||||
|
obj.handle_mut());
|
||||||
assert!(!obj.is_null());
|
assert!(!obj.is_null());
|
||||||
|
|
||||||
(*raw).init_reflector(obj.get());
|
(*raw).init_reflector(obj.get());
|
||||||
|
|
|
@ -218,35 +218,33 @@ pub unsafe fn create_global_object(
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
class: &'static JSClass,
|
class: &'static JSClass,
|
||||||
private: *const libc::c_void,
|
private: *const libc::c_void,
|
||||||
trace: TraceHook)
|
trace: TraceHook,
|
||||||
-> *mut JSObject {
|
rval: MutableHandleObject) {
|
||||||
|
assert!(rval.is_null());
|
||||||
|
|
||||||
let mut options = CompartmentOptions::default();
|
let mut options = CompartmentOptions::default();
|
||||||
options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
|
options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
|
||||||
options.creationOptions_.traceGlobal_ = Some(trace);
|
options.creationOptions_.traceGlobal_ = Some(trace);
|
||||||
options.creationOptions_.sharedMemoryAndAtomics_ = true;
|
options.creationOptions_.sharedMemoryAndAtomics_ = true;
|
||||||
|
|
||||||
rooted!(in(cx) let obj =
|
rval.set(JS_NewGlobalObject(cx,
|
||||||
JS_NewGlobalObject(cx,
|
|
||||||
class,
|
class,
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
|
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
|
||||||
&options));
|
&options));
|
||||||
if obj.is_null() {
|
assert!(!rval.is_null());
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the reserved slots before doing anything that can GC, to
|
// Initialize the reserved slots before doing anything that can GC, to
|
||||||
// avoid getting trace hooks called on a partially initialized object.
|
// avoid getting trace hooks called on a partially initialized object.
|
||||||
JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, PrivateValue(private));
|
JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, PrivateValue(private));
|
||||||
let proto_array: Box<ProtoOrIfaceArray> =
|
let proto_array: Box<ProtoOrIfaceArray> =
|
||||||
box [0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH];
|
box [0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH];
|
||||||
JS_SetReservedSlot(obj.get(),
|
JS_SetReservedSlot(rval.get(),
|
||||||
DOM_PROTOTYPE_SLOT,
|
DOM_PROTOTYPE_SLOT,
|
||||||
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
|
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
|
||||||
|
|
||||||
let _ac = JSAutoCompartment::new(cx, obj.get());
|
let _ac = JSAutoCompartment::new(cx, rval.get());
|
||||||
JS_FireOnNewGlobalObject(cx, obj.handle());
|
JS_FireOnNewGlobalObject(cx, rval.handle());
|
||||||
obj.get()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and define the interface object of a callback interface.
|
/// Create and define the interface object of a callback interface.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue