mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Change the order of code in callback.rs to make more sense.
This commit is contained in:
parent
6a9e2fd7fb
commit
aa93260f1e
1 changed files with 39 additions and 37 deletions
|
@ -30,6 +30,32 @@ pub enum ExceptionHandling {
|
|||
Rethrow,
|
||||
}
|
||||
|
||||
|
||||
/// A common base class for representing IDL callback function and
|
||||
/// callback interface types.
|
||||
#[derive(JSTraceable)]
|
||||
struct CallbackObject {
|
||||
/// The underlying `JSObject`.
|
||||
callback: Heap<*mut JSObject>,
|
||||
}
|
||||
|
||||
impl PartialEq for CallbackObject {
|
||||
fn eq(&self, other: &CallbackObject) -> bool {
|
||||
self.callback.get() == other.callback.get()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A trait to be implemented by concrete IDL callback function and
|
||||
/// callback interface types.
|
||||
pub trait CallbackContainer {
|
||||
/// Create a new CallbackContainer object for the given `JSObject`.
|
||||
fn new(callback: *mut JSObject) -> Rc<Self>;
|
||||
/// Returns the underlying `JSObject`.
|
||||
fn callback(&self) -> *mut JSObject;
|
||||
}
|
||||
|
||||
|
||||
/// A common base class for representing IDL callback function types.
|
||||
#[derive(JSTraceable, PartialEq)]
|
||||
pub struct CallbackFunction {
|
||||
|
@ -51,51 +77,20 @@ impl CallbackFunction {
|
|||
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,
|
||||
}
|
||||
|
||||
/// A common base class for representing IDL callback function and
|
||||
/// callback interface types.
|
||||
#[derive(JSTraceable)]
|
||||
struct CallbackObject {
|
||||
/// The underlying `JSObject`.
|
||||
callback: Heap<*mut JSObject>,
|
||||
}
|
||||
|
||||
impl PartialEq for CallbackObject {
|
||||
fn eq(&self, other: &CallbackObject) -> bool {
|
||||
self.callback.get() == other.callback.get()
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait to be implemented by concrete IDL callback function and
|
||||
/// callback interface types.
|
||||
pub trait CallbackContainer {
|
||||
/// Create a new CallbackContainer object for the given `JSObject`.
|
||||
fn new(callback: *mut JSObject) -> Rc<Self>;
|
||||
/// Returns the underlying `JSObject`.
|
||||
fn callback(&self) -> *mut JSObject;
|
||||
}
|
||||
|
||||
impl CallbackInterface {
|
||||
/// Returns the underlying `JSObject`.
|
||||
pub fn callback(&self) -> *mut JSObject {
|
||||
self.object.callback.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl CallbackFunction {
|
||||
/// Returns the underlying `JSObject`.
|
||||
pub fn callback(&self) -> *mut JSObject {
|
||||
self.object.callback.get()
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue