From 0607cd3fb54250f7b6e3b4028879a3eda1e3688a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 14 Jun 2015 16:01:11 +0200 Subject: [PATCH] Return Fallible from get_callable_property. --- components/script/dom/bindings/callback.rs | 10 +++++----- components/script/dom/bindings/codegen/CodegenRust.py | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 975e3cb99d9..7a1c12f64d3 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -4,6 +4,7 @@ //! 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::js::JSRef; use dom::bindings::utils::Reflectable; @@ -93,22 +94,21 @@ impl CallbackInterface { } /// Returns the property with the given `name`, if it is a callable object, - /// or `Err(())` otherwise. If it returns `Err(())`, a JSAPI exception is - /// pending. + /// or an error otherwise. pub fn get_callable_property(&self, cx: *mut JSContext, name: &str) - -> Result { + -> Fallible { let mut callable = UndefinedValue(); unsafe { let name = CString::new(name).unwrap(); if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 { - return Err(()); + return Err(Error::JSFailed); } if !callable.is_object() || JS_ObjectIsCallable(cx, callable.to_object()) == 0 { // FIXME(#347) //ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get()); - return Err(()); + return Err(Error::JSFailed); } } Ok(callable) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index cf7fcfd8e4c..78d8b2f7f6f 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5304,10 +5304,8 @@ class CallbackOperationBase(CallbackMethod): "methodName": self.methodName } getCallableFromProp = string.Template( - 'match self.parent.get_callable_property(cx, "${methodName}") {\n' - ' Err(_) => return Err(JSFailed),\n' - ' Ok(callable) => callable,\n' - '}').substitute(replacements) + 'try!(self.parent.get_callable_property(cx, "${methodName}"))' + ).substitute(replacements) if not self.singleOperation: return 'JS::Rooted callable(cx);\n' + getCallableFromProp return (