aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py13
-rw-r--r--components/script/dom/bindings/interface.rs30
2 files changed, 21 insertions, 22 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index dea8532beb5..8fc5ca34dee 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2513,12 +2513,13 @@ class CGWrapGlobalMethod(CGAbstractMethod):
let raw = Box::into_raw(object);
let _rt = RootedTraceable::new(&*raw);
-rooted!(in(cx) let obj =
- create_global_object(
- cx,
- &*(&Class.base as *const js::jsapi::Class as *const _),
- raw as *const libc::c_void,
- _trace));
+rooted!(in(cx) let mut obj = ptr::null_mut());
+create_global_object(
+ cx,
+ &*(&Class.base as *const js::jsapi::Class as *const _),
+ raw as *const libc::c_void,
+ _trace,
+ obj.handle_mut());
assert!(!obj.is_null());
(*raw).init_reflector(obj.get());
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index ffb33f8f438..d92510754d5 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -218,35 +218,33 @@ pub unsafe fn create_global_object(
cx: *mut JSContext,
class: &'static JSClass,
private: *const libc::c_void,
- trace: TraceHook)
- -> *mut JSObject {
+ trace: TraceHook,
+ rval: MutableHandleObject) {
+ assert!(rval.is_null());
+
let mut options = CompartmentOptions::default();
options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
options.creationOptions_.traceGlobal_ = Some(trace);
options.creationOptions_.sharedMemoryAndAtomics_ = true;
- rooted!(in(cx) let obj =
- JS_NewGlobalObject(cx,
- class,
- ptr::null_mut(),
- OnNewGlobalHookOption::DontFireOnNewGlobalHook,
- &options));
- if obj.is_null() {
- return ptr::null_mut();
- }
+ rval.set(JS_NewGlobalObject(cx,
+ class,
+ ptr::null_mut(),
+ OnNewGlobalHookOption::DontFireOnNewGlobalHook,
+ &options));
+ assert!(!rval.is_null());
// Initialize the reserved slots before doing anything that can GC, to
// 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> =
box [0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH];
- JS_SetReservedSlot(obj.get(),
+ JS_SetReservedSlot(rval.get(),
DOM_PROTOTYPE_SLOT,
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
- let _ac = JSAutoCompartment::new(cx, obj.get());
- JS_FireOnNewGlobalObject(cx, obj.handle());
- obj.get()
+ let _ac = JSAutoCompartment::new(cx, rval.get());
+ JS_FireOnNewGlobalObject(cx, rval.handle());
}
/// Create and define the interface object of a callback interface.