mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01: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,
|
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.
|
/// A common base class for representing IDL callback function types.
|
||||||
#[derive(JSTraceable, PartialEq)]
|
#[derive(JSTraceable, PartialEq)]
|
||||||
pub struct CallbackFunction {
|
pub struct CallbackFunction {
|
||||||
|
@ -51,51 +77,20 @@ impl CallbackFunction {
|
||||||
pub fn init(&mut self, callback: *mut JSObject) {
|
pub fn init(&mut self, callback: *mut JSObject) {
|
||||||
self.object.callback.set(callback);
|
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.
|
/// A common base class for representing IDL callback interface types.
|
||||||
#[derive(JSTraceable, PartialEq)]
|
#[derive(JSTraceable, PartialEq)]
|
||||||
pub struct CallbackInterface {
|
pub struct CallbackInterface {
|
||||||
object: CallbackObject,
|
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 {
|
impl CallbackInterface {
|
||||||
/// Create a new CallbackInterface object for the given `JSObject`.
|
/// Create a new CallbackInterface object for the given `JSObject`.
|
||||||
pub fn new() -> CallbackInterface {
|
pub fn new() -> CallbackInterface {
|
||||||
|
@ -112,6 +107,11 @@ impl CallbackInterface {
|
||||||
self.object.callback.set(callback);
|
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,
|
/// Returns the property with the given `name`, if it is a callable object,
|
||||||
/// or an error otherwise.
|
/// or an error otherwise.
|
||||||
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str) -> Fallible<JSVal> {
|
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`.
|
/// Wraps the reflector for `p` into the compartment of `cx`.
|
||||||
pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext,
|
pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext,
|
||||||
p: &T,
|
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
|
/// 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.
|
/// this class is on the stack. After `new` returns, the call is safe to make.
|
||||||
pub struct CallSetup {
|
pub struct CallSetup {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue