mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
auto merge of #3937 : Ms2ger/servo/docs-bindings, r=jdm
This commit is contained in:
commit
fe11a75f79
4 changed files with 47 additions and 5 deletions
|
@ -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)]
|
||||||
|
|
||||||
//! Base classes to work with IDL callbacks.
|
//! Base classes to work with IDL callbacks.
|
||||||
|
|
||||||
use dom::bindings::global::global_object_for_js_object;
|
use dom::bindings::global::global_object_for_js_object;
|
||||||
|
@ -33,6 +35,7 @@ pub struct CallbackFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallbackFunction {
|
impl CallbackFunction {
|
||||||
|
/// Create a new `CallbackFunction` for this object.
|
||||||
pub fn new(callback: *mut JSObject) -> CallbackFunction {
|
pub fn new(callback: *mut JSObject) -> CallbackFunction {
|
||||||
CallbackFunction {
|
CallbackFunction {
|
||||||
object: CallbackObject {
|
object: CallbackObject {
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
||||||
//! Conversions of Rust values to and from `JSVal`.
|
//! Conversions of Rust values to and from `JSVal`.
|
||||||
|
|
||||||
use dom::bindings::js::{JS, JSRef, Root};
|
use dom::bindings::js::{JS, JSRef, Root};
|
||||||
|
@ -29,10 +31,15 @@ use std::slice;
|
||||||
|
|
||||||
use dom::bindings::codegen::PrototypeList;
|
use dom::bindings::codegen::PrototypeList;
|
||||||
|
|
||||||
|
/// A trait to retrieve the constants necessary to check if a `JSObject`
|
||||||
|
/// implements a given interface.
|
||||||
// FIXME (https://github.com/rust-lang/rfcs/pull/4)
|
// FIXME (https://github.com/rust-lang/rfcs/pull/4)
|
||||||
// remove Option<Self> arguments.
|
// remove Option<Self> arguments.
|
||||||
pub trait IDLInterface {
|
pub trait IDLInterface {
|
||||||
|
/// Returns the prototype ID.
|
||||||
fn get_prototype_id(_: Option<Self>) -> PrototypeList::id::ID;
|
fn get_prototype_id(_: Option<Self>) -> PrototypeList::id::ID;
|
||||||
|
/// Returns the prototype depth, i.e., the number of interfaces this
|
||||||
|
/// interface inherits from.
|
||||||
fn get_prototype_depth(_: Option<Self>) -> uint;
|
fn get_prototype_depth(_: Option<Self>) -> uint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
||||||
//! Utilities for tracing JS-managed values.
|
//! Utilities for tracing JS-managed values.
|
||||||
//!
|
//!
|
||||||
//! The lifetime of DOM objects is managed by the SpiderMonkey Garbage
|
//! The lifetime of DOM objects is managed by the SpiderMonkey Garbage
|
||||||
|
@ -58,6 +60,12 @@ use dom::node::{Node, TrustedNodeAddress};
|
||||||
use dom::bindings::utils::WindowProxyHandler;
|
use dom::bindings::utils::WindowProxyHandler;
|
||||||
use html5ever::tree_builder::QuirksMode;
|
use html5ever::tree_builder::QuirksMode;
|
||||||
|
|
||||||
|
/// A trait to allow tracing (only) DOM objects.
|
||||||
|
pub trait JSTraceable {
|
||||||
|
/// Trace `self`.
|
||||||
|
fn trace(&self, trc: *mut JSTracer);
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> JSTraceable for JS<T> {
|
impl<T: Reflectable> JSTraceable for JS<T> {
|
||||||
fn trace(&self, trc: *mut JSTracer) {
|
fn trace(&self, trc: *mut JSTracer) {
|
||||||
trace_reflector(trc, "", self.reflector());
|
trace_reflector(trc, "", self.reflector());
|
||||||
|
@ -66,11 +74,6 @@ impl<T: Reflectable> JSTraceable for JS<T> {
|
||||||
|
|
||||||
no_jsmanaged_fields!(Reflector)
|
no_jsmanaged_fields!(Reflector)
|
||||||
|
|
||||||
/// A trait to allow tracing (only) DOM objects.
|
|
||||||
pub trait JSTraceable {
|
|
||||||
fn trace(&self, trc: *mut JSTracer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trace a `JSVal`.
|
/// Trace a `JSVal`.
|
||||||
pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
|
pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
|
||||||
if !val.is_markable() {
|
if !val.is_markable() {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue