mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Return Fallible from get_callable_property.
This commit is contained in:
parent
6b886e545d
commit
0607cd3fb5
2 changed files with 7 additions and 9 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
//! Base classes to work with IDL callbacks.
|
//! Base classes to work with IDL callbacks.
|
||||||
|
|
||||||
|
use dom::bindings::error::{Fallible, Error};
|
||||||
use dom::bindings::global::global_object_for_js_object;
|
use dom::bindings::global::global_object_for_js_object;
|
||||||
use dom::bindings::js::JSRef;
|
use dom::bindings::js::JSRef;
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
|
@ -93,22 +94,21 @@ impl CallbackInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 `Err(())` otherwise. If it returns `Err(())`, a JSAPI exception is
|
/// or an error otherwise.
|
||||||
/// pending.
|
|
||||||
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str)
|
pub fn get_callable_property(&self, cx: *mut JSContext, name: &str)
|
||||||
-> Result<JSVal, ()> {
|
-> Fallible<JSVal> {
|
||||||
let mut callable = UndefinedValue();
|
let mut callable = UndefinedValue();
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = CString::new(name).unwrap();
|
let name = CString::new(name).unwrap();
|
||||||
if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 {
|
if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 {
|
||||||
return Err(());
|
return Err(Error::JSFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !callable.is_object() ||
|
if !callable.is_object() ||
|
||||||
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
|
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
|
||||||
// FIXME(#347)
|
// FIXME(#347)
|
||||||
//ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
|
//ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
|
||||||
return Err(());
|
return Err(Error::JSFailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(callable)
|
Ok(callable)
|
||||||
|
|
|
@ -5304,10 +5304,8 @@ class CallbackOperationBase(CallbackMethod):
|
||||||
"methodName": self.methodName
|
"methodName": self.methodName
|
||||||
}
|
}
|
||||||
getCallableFromProp = string.Template(
|
getCallableFromProp = string.Template(
|
||||||
'match self.parent.get_callable_property(cx, "${methodName}") {\n'
|
'try!(self.parent.get_callable_property(cx, "${methodName}"))'
|
||||||
' Err(_) => return Err(JSFailed),\n'
|
).substitute(replacements)
|
||||||
' Ok(callable) => callable,\n'
|
|
||||||
'}').substitute(replacements)
|
|
||||||
if not self.singleOperation:
|
if not self.singleOperation:
|
||||||
return 'JS::Rooted<JS::Value> callable(cx);\n' + getCallableFromProp
|
return 'JS::Rooted<JS::Value> callable(cx);\n' + getCallableFromProp
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue