aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r--components/script/dom/bindings/utils.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index c8a4e6a9da7..7d4bf9b88c7 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -180,36 +180,38 @@ unsafe impl Sync for NativeProperties {}
pub type NonNullJSNative =
unsafe extern "C" fn (arg1: *mut JSContext, arg2: c_uint, arg3: *mut JSVal) -> JSBool;
-/// Creates the *interface prototype object* and the *interface object* (if
-/// needed).
+/// Creates the *interface prototype object* (if a `proto_class` is given)
+/// and the *interface object* (if a `constructor` is given).
/// Fails on JSAPI failure.
pub fn do_create_interface_objects(cx: *mut JSContext, global: *mut JSObject,
receiver: *mut JSObject,
proto_proto: *mut JSObject,
- proto_class: &'static JSClass,
+ proto_class: Option<&'static JSClass>,
constructor: Option<(NonNullJSNative, &'static str, u32)>,
dom_class: *const DOMClass,
members: &'static NativeProperties)
-> *mut JSObject {
- let proto = create_interface_prototype_object(cx, global, proto_proto,
- proto_class, members);
-
unsafe {
- JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
- PrivateValue(dom_class as *const libc::c_void));
- }
-
- match constructor {
- Some((native, name, nargs)) => {
+ let proto = match proto_class {
+ Some(proto_class) => {
+ let proto = create_interface_prototype_object(cx, global, proto_proto,
+ proto_class, members);
+ JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
+ PrivateValue(dom_class as *const libc::c_void));
+ proto
+ },
+ None => ptr::null_mut()
+ };
+
+ if let Some((native, name, nargs)) = constructor {
let s = CString::new(name).unwrap();
create_interface_object(cx, global, receiver,
native, nargs, proto,
members, s.as_ptr())
- },
- None => (),
- }
+ }
- proto
+ proto
+ }
}
/// Creates the *interface object*.