diff options
author | Chris Paris <cap@chrisparis.org> | 2014-10-06 22:13:14 -1000 |
---|---|---|
committer | Chris Paris <cap@chrisparis.org> | 2015-04-11 09:34:44 -1000 |
commit | d2b0d5e04084c936a457d0718f98f860c380026b (patch) | |
tree | c7137b798b71d818dd2b6a8eaefe56560ea671f1 /components/script/dom/bindings/utils.rs | |
parent | 10c68e751912962ed1bbed137b00ce4511d46bda (diff) | |
download | servo-d2b0d5e04084c936a457d0718f98f860c380026b.tar.gz servo-d2b0d5e04084c936a457d0718f98f860c380026b.zip |
Support callback interfaces with constants.
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 34 |
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*. |