aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/callback.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2015-11-17 16:52:17 +0100
committerMs2ger <Ms2ger@gmail.com>2015-11-18 11:14:05 +0100
commit0c61be7a577b99dc138eb6a2e46fb9276df0870d (patch)
tree8188a7ed8f86ce1fab95f7aa4ff5c43819e4520d /components/script/dom/bindings/callback.rs
parentceb72e54e469bb3811fb641e7c38f476781a5720 (diff)
downloadservo-0c61be7a577b99dc138eb6a2e46fb9276df0870d.tar.gz
servo-0c61be7a577b99dc138eb6a2e46fb9276df0870d.zip
Rustfmt some of script.
Diffstat (limited to 'components/script/dom/bindings/callback.rs')
-rw-r--r--components/script/dom/bindings/callback.rs52
1 files changed, 27 insertions, 25 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs
index 182af6656b8..10b19acc601 100644
--- a/components/script/dom/bindings/callback.rs
+++ b/components/script/dom/bindings/callback.rs
@@ -8,9 +8,9 @@ use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::global_root_from_object;
use dom::bindings::reflector::Reflectable;
use js::jsapi::GetGlobalForObjectCrossCompartment;
+use js::jsapi::JSAutoCompartment;
use js::jsapi::{Heap, MutableHandleObject, RootedObject, RootedValue};
use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject};
-use js::jsapi::{JSAutoCompartment};
use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment};
use js::jsapi::{JS_BeginRequest, JS_EndRequest};
use js::jsapi::{JS_GetProperty, JS_IsExceptionPending, JS_ReportPendingException};
@@ -28,13 +28,13 @@ pub enum ExceptionHandling {
/// Report any exception and don't throw it to the caller code.
Report,
/// Throw any exception to the caller code.
- Rethrow
+ Rethrow,
}
/// A common base class for representing IDL callback function types.
#[derive(JSTraceable, PartialEq)]
pub struct CallbackFunction {
- object: CallbackObject
+ object: CallbackObject,
}
impl CallbackFunction {
@@ -42,8 +42,8 @@ impl CallbackFunction {
pub fn new() -> CallbackFunction {
CallbackFunction {
object: CallbackObject {
- callback: Heap::default()
- }
+ callback: Heap::default(),
+ },
}
}
@@ -57,7 +57,7 @@ impl CallbackFunction {
/// A common base class for representing IDL callback interface types.
#[derive(JSTraceable, PartialEq)]
pub struct CallbackInterface {
- object: CallbackObject
+ object: CallbackObject,
}
/// A common base class for representing IDL callback function and
@@ -103,8 +103,8 @@ impl CallbackInterface {
pub fn new() -> CallbackInterface {
CallbackInterface {
object: CallbackObject {
- callback: Heap::default()
- }
+ callback: Heap::default(),
+ },
}
}
@@ -116,21 +116,18 @@ impl CallbackInterface {
/// 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> {
+ pub fn get_callable_property(&self, cx: *mut JSContext, name: &str) -> Fallible<JSVal> {
let mut callable = RootedValue::new(cx, UndefinedValue());
let obj = RootedObject::new(cx, self.callback());
unsafe {
let c_name = CString::new(name).unwrap();
- if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
- callable.handle_mut()) {
+ if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(), callable.handle_mut()) {
return Err(Error::JSFailed);
}
- if !callable.ptr.is_object() ||
- !IsCallable(callable.ptr.to_object()) {
- return Err(Error::Type(
- format!("The value of the {} property is not callable", name)));
+ if !callable.ptr.is_object() || !IsCallable(callable.ptr.to_object()) {
+ return Err(Error::Type(format!("The value of the {} property is not callable",
+ name)));
}
}
Ok(callable.ptr)
@@ -172,15 +169,17 @@ impl CallSetup {
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
let global = global_root_from_object(callback.callback());
let cx = global.r().get_cx();
- unsafe { JS_BeginRequest(cx); }
+ unsafe {
+ JS_BeginRequest(cx);
+ }
let exception_compartment = unsafe {
GetGlobalForObjectCrossCompartment(callback.callback())
};
CallSetup {
- exception_compartment:
- RootedObject::new_with_addr(cx, exception_compartment,
- unsafe { return_address() }),
+ exception_compartment: RootedObject::new_with_addr(cx,
+ exception_compartment,
+ unsafe { return_address() }),
cx: cx,
old_compartment: unsafe { JS_EnterCompartment(cx, callback.callback()) },
handling: handling,
@@ -195,10 +194,11 @@ impl CallSetup {
impl Drop for CallSetup {
fn drop(&mut self) {
- unsafe { JS_LeaveCompartment(self.cx, self.old_compartment); }
- let need_to_deal_with_exception =
- self.handling == ExceptionHandling::Report &&
- unsafe { JS_IsExceptionPending(self.cx) };
+ unsafe {
+ JS_LeaveCompartment(self.cx, self.old_compartment);
+ }
+ let need_to_deal_with_exception = self.handling == ExceptionHandling::Report &&
+ unsafe { JS_IsExceptionPending(self.cx) };
if need_to_deal_with_exception {
unsafe {
let old_global = RootedObject::new(self.cx, self.exception_compartment.ptr);
@@ -212,6 +212,8 @@ impl Drop for CallSetup {
}
}
}
- unsafe { JS_EndRequest(self.cx); }
+ unsafe {
+ JS_EndRequest(self.cx);
+ }
}
}