Document bindings/utils.rs.

This commit is contained in:
Ms2ger 2014-11-07 11:57:37 +01:00
parent 23b75816a2
commit bfa1ab816f

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![deny(missing_doc)]
//! Various utilities to glue JavaScript and the DOM implementation together. //! Various utilities to glue JavaScript and the DOM implementation together.
use dom::bindings::codegen::PrototypeList; use dom::bindings::codegen::PrototypeList;
@ -45,14 +47,18 @@ use js::{JSPROP_ENUMERATE, JSPROP_READONLY, JSPROP_PERMANENT};
use js::JSFUN_CONSTRUCTOR; use js::JSFUN_CONSTRUCTOR;
use js; use js;
/// Proxy handler for a WindowProxy.
pub struct WindowProxyHandler(pub *const libc::c_void); pub struct WindowProxyHandler(pub *const libc::c_void);
#[allow(raw_pointer_deriving)] #[allow(raw_pointer_deriving)]
#[jstraceable] #[jstraceable]
/// Static data associated with a global object.
pub struct GlobalStaticData { pub struct GlobalStaticData {
/// The WindowProxy proxy handler for this global.
pub windowproxy_handler: WindowProxyHandler, pub windowproxy_handler: WindowProxyHandler,
} }
/// Creates a new GlobalStaticData.
pub fn GlobalStaticData() -> GlobalStaticData { pub fn GlobalStaticData() -> GlobalStaticData {
GlobalStaticData { GlobalStaticData {
windowproxy_handler: browsercontext::new_window_proxy_handler(), windowproxy_handler: browsercontext::new_window_proxy_handler(),
@ -182,18 +188,26 @@ pub static JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1;
/// Representation of an IDL constant value. /// Representation of an IDL constant value.
#[deriving(Clone)] #[deriving(Clone)]
pub enum ConstantVal { pub enum ConstantVal {
/// `long` constant.
IntVal(i32), IntVal(i32),
/// `unsigned long` constant.
UintVal(u32), UintVal(u32),
/// `double` constant.
DoubleVal(f64), DoubleVal(f64),
/// `boolean` constant.
BoolVal(bool), BoolVal(bool),
/// `null` constant.
NullVal, NullVal,
/// `undefined` constant.
VoidVal VoidVal
} }
/// Representation of an IDL constant. /// Representation of an IDL constant.
#[deriving(Clone)] #[deriving(Clone)]
pub struct ConstantSpec { pub struct ConstantSpec {
/// name of the constant.
pub name: &'static [u8], pub name: &'static [u8],
/// value of the constant.
pub value: ConstantVal pub value: ConstantVal
} }
@ -232,7 +246,9 @@ pub struct DOMClass {
/// The JSClass used for DOM object reflectors. /// The JSClass used for DOM object reflectors.
pub struct DOMJSClass { pub struct DOMJSClass {
/// The actual JSClass.
pub base: js::Class, pub base: js::Class,
/// Associated data for DOM object reflectors.
pub dom_class: DOMClass pub dom_class: DOMClass
} }
@ -248,10 +264,15 @@ pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject {
/// Contains references to lists of methods, attributes, and constants for a /// Contains references to lists of methods, attributes, and constants for a
/// given interface. /// given interface.
pub struct NativeProperties { pub struct NativeProperties {
/// Instance methods for the interface.
pub methods: Option<&'static [JSFunctionSpec]>, pub methods: Option<&'static [JSFunctionSpec]>,
/// Instance attributes for the interface.
pub attrs: Option<&'static [JSPropertySpec]>, pub attrs: Option<&'static [JSPropertySpec]>,
/// Constants for the interface.
pub consts: Option<&'static [ConstantSpec]>, pub consts: Option<&'static [ConstantSpec]>,
/// Static methods for the interface.
pub staticMethods: Option<&'static [JSFunctionSpec]>, pub staticMethods: Option<&'static [JSFunctionSpec]>,
/// Static attributes for the interface.
pub staticAttrs: Option<&'static [JSPropertySpec]>, pub staticAttrs: Option<&'static [JSPropertySpec]>,
} }
@ -416,6 +437,7 @@ pub fn initialize_global(global: *mut JSObject) {
/// A trait to provide access to the `Reflector` for a DOM object. /// A trait to provide access to the `Reflector` for a DOM object.
pub trait Reflectable { pub trait Reflectable {
/// Returns the receiver's reflector.
fn reflector<'a>(&'a self) -> &'a Reflector; fn reflector<'a>(&'a self) -> &'a Reflector;
} }
@ -468,6 +490,10 @@ impl Reflector {
} }
} }
/// Gets the property `id` on `proxy`'s prototype. If it exists, `*found` is
/// set to true and `*vp` to the value, otherwise `*found` is set to false.
///
/// Returns false on JSAPI failure.
pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, found: *mut bool, pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, found: *mut bool,
vp: *mut JSVal) -> bool { vp: *mut JSVal) -> bool {
unsafe { unsafe {
@ -585,6 +611,7 @@ pub fn get_dictionary_property(cx: *mut JSContext,
Ok(Some(value)) Ok(Some(value))
} }
/// Returns whether `proxy` has a property `id` on its prototype.
pub fn HasPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool { pub fn HasPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool {
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler); // MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
let mut found = false; let mut found = false;
@ -639,6 +666,7 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut
} }
} }
/// Deletes the property `id` from `object`.
pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: *mut JSObject, pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: *mut JSObject,
id: jsid, bp: &mut bool) -> bool { id: jsid, bp: &mut bool) -> bool {
let mut value = UndefinedValue(); let mut value = UndefinedValue();
@ -652,6 +680,7 @@ pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: *mut JSObject,
/// Results of `xml_name_type`. /// Results of `xml_name_type`.
#[deriving(PartialEq)] #[deriving(PartialEq)]
#[allow(missing_doc)]
pub enum XMLName { pub enum XMLName {
QName, QName,
Name, Name,