diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-04-13 14:34:39 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-04-13 14:34:39 -0500 |
commit | 1f9c2f9b34dede8182f45655b03380f8c26f3475 (patch) | |
tree | 307f2ee1ea15bc8fc8ce418650bf4bef10f43516 /components/script/dom/bindings/utils.rs | |
parent | 74c847a17fb560dd4cd62069778776f6f06df19f (diff) | |
parent | d2b0d5e04084c936a457d0718f98f860c380026b (diff) | |
download | servo-1f9c2f9b34dede8182f45655b03380f8c26f3475.tar.gz servo-1f9c2f9b34dede8182f45655b03380f8c26f3475.zip |
Auto merge of #3726 - ChrisParis:callback-constants, r=jdm
This addresses https://github.com/servo/servo/issues/3149. The immediate purpose is to support the constants in NodeFilter. The changes mostly follow the current Gecko Codegen.py. The main gist is that the generation of certain code artifacts is now gated by hasInterfaceObject() or hasInterfacePrototypeObject(), rather than by isCallback().
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*. |