aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/callback.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2017-01-06 18:01:10 +0100
committerMs2ger <Ms2ger@gmail.com>2017-01-09 14:17:41 +0100
commitb8554abaa4634a66f41a51d35985f24c39c392f0 (patch)
treeb8870b32c523199814dcc6716d0074f59ddcf578 /components/script/dom/bindings/callback.rs
parent11c21d3b1d0f2f202d505c79cff20bf7c883d78e (diff)
downloadservo-b8554abaa4634a66f41a51d35985f24c39c392f0.tar.gz
servo-b8554abaa4634a66f41a51d35985f24c39c392f0.zip
Expose CallbackObject more.
This will make it easier to use new fields added to it.
Diffstat (limited to 'components/script/dom/bindings/callback.rs')
-rw-r--r--components/script/dom/bindings/callback.rs34
1 files changed, 21 insertions, 13 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs
index 897cc3bd39f..067b498a35d 100644
--- a/components/script/dom/bindings/callback.rs
+++ b/components/script/dom/bindings/callback.rs
@@ -34,7 +34,7 @@ pub enum ExceptionHandling {
/// A common base class for representing IDL callback function and
/// callback interface types.
#[derive(Default, JSTraceable)]
-struct CallbackObject {
+pub struct CallbackObject {
/// The underlying `JSObject`.
callback: Heap<*mut JSObject>,
}
@@ -45,6 +45,10 @@ impl CallbackObject {
callback: Heap::default(),
}
}
+
+ pub fn get(&self) -> *mut JSObject {
+ self.callback.get()
+ }
}
impl PartialEq for CallbackObject {
@@ -59,8 +63,12 @@ impl PartialEq for CallbackObject {
pub trait CallbackContainer {
/// Create a new CallbackContainer object for the given `JSObject`.
fn new(callback: *mut JSObject) -> Rc<Self>;
+ /// Returns the underlying `CallbackObject`.
+ fn callback_holder(&self) -> &CallbackObject;
/// Returns the underlying `JSObject`.
- fn callback(&self) -> *mut JSObject;
+ fn callback(&self) -> *mut JSObject {
+ self.callback_holder().get()
+ }
}
@@ -78,16 +86,16 @@ impl CallbackFunction {
}
}
+ /// Returns the underlying `CallbackObject`.
+ pub fn callback_holder(&self) -> &CallbackObject {
+ &self.object
+ }
+
/// Initialize the callback function with a value.
/// Should be called once this object is done moving.
pub fn init(&mut self, callback: *mut JSObject) {
self.object.callback.set(callback);
}
-
- /// Returns the underlying `JSObject`.
- pub fn callback(&self) -> *mut JSObject {
- self.object.callback.get()
- }
}
@@ -105,22 +113,22 @@ impl CallbackInterface {
}
}
+ /// Returns the underlying `CallbackObject`.
+ pub fn callback_holder(&self) -> &CallbackObject {
+ &self.object
+ }
+
/// Initialize the callback function with a value.
/// Should be called once this object is done moving.
pub fn init(&mut self, callback: *mut JSObject) {
self.object.callback.set(callback);
}
- /// Returns the underlying `JSObject`.
- pub fn callback(&self) -> *mut JSObject {
- self.object.callback.get()
- }
-
/// Returns the property with the given `name`, if it is a callable object,
/// or an error otherwise.
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str) -> Fallible<JSVal> {
rooted!(in(cx) let mut callable = UndefinedValue());
- rooted!(in(cx) let obj = self.callback());
+ rooted!(in(cx) let obj = self.callback_holder().get());
unsafe {
let c_name = CString::new(name).unwrap();
if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(), callable.handle_mut()) {