From aa93260f1e415d9e00acbcf07879004f110947b2 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 6 Jan 2017 16:13:10 +0100 Subject: [PATCH] Change the order of code in callback.rs to make more sense. --- components/script/dom/bindings/callback.rs | 76 +++++++++++----------- 1 file changed, 39 insertions(+), 37 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,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; + /// 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; - /// 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 { @@ -132,6 +132,7 @@ impl CallbackInterface { } } + /// Wraps the reflector for `p` into the compartment of `cx`. pub fn wrap_call_this_object(cx: *mut JSContext, p: &T, @@ -146,6 +147,7 @@ pub fn wrap_call_this_object(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 {