aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/callback.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2017-01-06 16:13:10 +0100
committerMs2ger <Ms2ger@gmail.com>2017-01-09 09:47:33 +0100
commitaa93260f1e415d9e00acbcf07879004f110947b2 (patch)
treec25df0912601eb157c605f80d6da65fd12e9a402 /components/script/dom/bindings/callback.rs
parent6a9e2fd7fb2b985909efeb71ed050c19bb2818d3 (diff)
downloadservo-aa93260f1e415d9e00acbcf07879004f110947b2.tar.gz
servo-aa93260f1e415d9e00acbcf07879004f110947b2.zip
Change the order of code in callback.rs to make more sense.
Diffstat (limited to 'components/script/dom/bindings/callback.rs')
-rw-r--r--components/script/dom/bindings/callback.rs68
1 files changed, 35 insertions, 33 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs
index efe1b8a5681..a9846477ac4 100644
--- a/components/script/dom/bindings/callback.rs
+++ b/components/script/dom/bindings/callback.rs
@@ -30,34 +30,6 @@ pub enum ExceptionHandling {
Rethrow,
}
-/// A common base class for representing IDL callback function types.
-#[derive(JSTraceable, PartialEq)]
-pub struct CallbackFunction {
- object: CallbackObject,
-}
-
-impl CallbackFunction {
- /// Create a new `CallbackFunction` for this object.
- pub fn new() -> CallbackFunction {
- CallbackFunction {
- object: CallbackObject {
- callback: Heap::default(),
- },
- }
- }
-
- /// 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);
- }
-}
-
-/// A common base class for representing IDL callback interface types.
-#[derive(JSTraceable, PartialEq)]
-pub struct CallbackInterface {
- object: CallbackObject,
-}
/// A common base class for representing IDL callback function and
/// callback interface types.
@@ -73,6 +45,7 @@ impl PartialEq for CallbackObject {
}
}
+
/// A trait to be implemented by concrete IDL callback function and
/// callback interface types.
pub trait CallbackContainer {
@@ -82,20 +55,42 @@ pub trait CallbackContainer {
fn callback(&self) -> *mut JSObject;
}
-impl CallbackInterface {
- /// Returns the underlying `JSObject`.
- pub fn callback(&self) -> *mut JSObject {
- self.object.callback.get()
- }
+
+/// A common base class for representing IDL callback function types.
+#[derive(JSTraceable, PartialEq)]
+pub struct CallbackFunction {
+ object: CallbackObject,
}
impl CallbackFunction {
+ /// Create a new `CallbackFunction` for this object.
+ pub fn new() -> CallbackFunction {
+ CallbackFunction {
+ object: CallbackObject {
+ callback: Heap::default(),
+ },
+ }
+ }
+
+ /// 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()
}
}
+
+/// A common base class for representing IDL callback interface types.
+#[derive(JSTraceable, PartialEq)]
+pub struct CallbackInterface {
+ object: CallbackObject,
+}
+
impl CallbackInterface {
/// Create a new CallbackInterface object for the given `JSObject`.
pub fn new() -> CallbackInterface {
@@ -112,6 +107,11 @@ impl CallbackInterface {
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> {
@@ -132,6 +132,7 @@ impl CallbackInterface {
}
}
+
/// Wraps the reflector for `p` into the compartment of `cx`.
pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext,
p: &T,
@@ -146,6 +147,7 @@ pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext,
}
}
+
/// A class that performs whatever setup we need to safely make a call while
/// this class is on the stack. After `new` returns, the call is safe to make.
pub struct CallSetup {