mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Expose CallbackObject more.
This will make it easier to use new fields added to it.
This commit is contained in:
parent
11c21d3b1d
commit
b8554abaa4
3 changed files with 31 additions and 22 deletions
|
@ -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()) {
|
||||
|
|
|
@ -5565,6 +5565,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'dom::bindings::callback::CallbackContainer',
|
||||
'dom::bindings::callback::CallbackInterface',
|
||||
'dom::bindings::callback::CallbackFunction',
|
||||
'dom::bindings::callback::CallbackObject',
|
||||
'dom::bindings::callback::ExceptionHandling',
|
||||
'dom::bindings::callback::wrap_call_this_object',
|
||||
'dom::bindings::conversions::ConversionBehavior',
|
||||
|
@ -6339,8 +6340,8 @@ impl CallbackContainer for ${type} {
|
|||
${type}::new(callback)
|
||||
}
|
||||
|
||||
fn callback(&self) -> *mut JSObject {
|
||||
self.parent.callback()
|
||||
fn callback_holder(&self) -> &CallbackObject {
|
||||
self.parent.callback_holder()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6619,11 +6620,11 @@ class CallCallback(CallbackMethod):
|
|||
return "aThisObj.get()"
|
||||
|
||||
def getCallableDecl(self):
|
||||
return "rooted!(in(cx) let callable = ObjectValue(self.parent.callback()));\n"
|
||||
return "rooted!(in(cx) let callable = ObjectValue(self.callback()));\n"
|
||||
|
||||
def getCallGuard(self):
|
||||
if self.callback._treatNonObjectAsNull:
|
||||
return "!IsCallable(self.parent.callback()) || "
|
||||
return "!IsCallable(self.callback()) || "
|
||||
return ""
|
||||
|
||||
|
||||
|
@ -6638,11 +6639,11 @@ class CallbackOperationBase(CallbackMethod):
|
|||
|
||||
def getThisObj(self):
|
||||
if not self.singleOperation:
|
||||
return "self.parent.callback()"
|
||||
return "self.callback()"
|
||||
# This relies on getCallableDecl declaring a boolean
|
||||
# isCallable in the case when we're a single-operation
|
||||
# interface.
|
||||
return "if isCallable { aThisObj.get() } else { self.parent.callback() }"
|
||||
return "if isCallable { aThisObj.get() } else { self.callback() }"
|
||||
|
||||
def getCallableDecl(self):
|
||||
replacements = {
|
||||
|
@ -6654,11 +6655,11 @@ class CallbackOperationBase(CallbackMethod):
|
|||
if not self.singleOperation:
|
||||
return 'rooted!(in(cx) let callable =\n' + getCallableFromProp + ');\n'
|
||||
return (
|
||||
'let isCallable = IsCallable(self.parent.callback());\n'
|
||||
'let isCallable = IsCallable(self.callback());\n'
|
||||
'rooted!(in(cx) let callable =\n' +
|
||||
CGIndenter(
|
||||
CGIfElseWrapper('isCallable',
|
||||
CGGeneric('ObjectValue(self.parent.callback())'),
|
||||
CGGeneric('ObjectValue(self.callback())'),
|
||||
CGGeneric(getCallableFromProp))).define() + ');\n')
|
||||
|
||||
def getCallGuard(self):
|
||||
|
|
|
@ -484,7 +484,7 @@ impl EventTarget {
|
|||
|
||||
pub fn get_event_handler_common<T: CallbackContainer>(&self, ty: &str) -> Option<Rc<T>> {
|
||||
let listener = self.get_inline_event_listener(&Atom::from(ty));
|
||||
listener.map(|listener| CallbackContainer::new(listener.parent().callback()))
|
||||
listener.map(|listener| CallbackContainer::new(listener.parent().callback_holder().get()))
|
||||
}
|
||||
|
||||
pub fn has_handlers(&self) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue