aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/error.rs
diff options
context:
space:
mode:
authorchansuke <chansuke@georepublic.de>2018-09-18 23:24:15 +0900
committerJosh Matthews <josh@joshmatthews.net>2018-09-19 17:40:47 -0400
commitc37a345dc9f4dda6ea29c42f96f6c7201c42cbac (patch)
tree1f05b49bac02318455a59d5b143c186fd872bdb9 /components/script/dom/bindings/error.rs
parent2ca7a134736bb4759ff209c1bc0b6dc3cc1984c9 (diff)
downloadservo-c37a345dc9f4dda6ea29c42f96f6c7201c42cbac.tar.gz
servo-c37a345dc9f4dda6ea29c42f96f6c7201c42cbac.zip
Format script component
Diffstat (limited to 'components/script/dom/bindings/error.rs')
-rw-r--r--components/script/dom/bindings/error.rs58
1 files changed, 30 insertions, 28 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs
index 7c68de0df18..ce045b2c9d3 100644
--- a/components/script/dom/bindings/error.rs
+++ b/components/script/dom/bindings/error.rs
@@ -126,7 +126,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: &GlobalScope, resu
Error::JSFailed => {
assert!(JS_IsExceptionPending(cx));
return;
- }
+ },
};
assert!(!JS_IsExceptionPending(cx));
@@ -149,8 +149,7 @@ pub struct ErrorInfo {
}
impl ErrorInfo {
- unsafe fn from_native_error(cx: *mut JSContext, object: HandleObject)
- -> Option<ErrorInfo> {
+ unsafe fn from_native_error(cx: *mut JSContext, object: HandleObject) -> Option<ErrorInfo> {
let report = JS_ErrorFromException(cx, object);
if report.is_null() {
return None;
@@ -205,7 +204,9 @@ impl ErrorInfo {
/// The `dispatch_event` argument is temporary and non-standard; passing false
/// prevents dispatching the `error` event.
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool) {
- if !JS_IsExceptionPending(cx) { return; }
+ if !JS_IsExceptionPending(cx) {
+ return;
+ }
rooted!(in(cx) let mut value = UndefinedValue());
if !JS_GetPendingException(cx, value.handle_mut()) {
@@ -219,23 +220,19 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
rooted!(in(cx) let object = value.to_object());
ErrorInfo::from_native_error(cx, object.handle())
.or_else(|| ErrorInfo::from_dom_exception(object.handle()))
- .unwrap_or_else(|| {
- ErrorInfo {
- message: format!("uncaught exception: unknown (can't convert to string)"),
- filename: String::new(),
- lineno: 0,
- column: 0,
- }
+ .unwrap_or_else(|| ErrorInfo {
+ message: format!("uncaught exception: unknown (can't convert to string)"),
+ filename: String::new(),
+ lineno: 0,
+ column: 0,
})
} else {
match USVString::from_jsval(cx, value.handle(), ()) {
- Ok(ConversionResult::Success(USVString(string))) => {
- ErrorInfo {
- message: format!("uncaught exception: {}", string),
- filename: String::new(),
- lineno: 0,
- column: 0,
- }
+ Ok(ConversionResult::Success(USVString(string))) => ErrorInfo {
+ message: format!("uncaught exception: {}", string),
+ filename: String::new(),
+ lineno: 0,
+ column: 0,
},
_ => {
panic!("Uncaught exception: failed to stringify primitive");
@@ -243,15 +240,13 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
}
};
- error!("Error at {}:{}:{} {}",
- error_info.filename,
- error_info.lineno,
- error_info.column,
- error_info.message);
+ error!(
+ "Error at {}:{}:{} {}",
+ error_info.filename, error_info.lineno, error_info.column, error_info.message
+ );
if dispatch_event {
- GlobalScope::from_context(cx)
- .report_an_error(error_info, value.handle());
+ GlobalScope::from_context(cx).report_an_error(error_info, value.handle());
}
}
@@ -259,14 +254,21 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
/// given DOM type.
pub unsafe fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) {
debug_assert!(!JS_IsExceptionPending(cx));
- let error = format!("\"this\" object does not implement interface {}.",
- proto_id_to_name(proto_id));
+ let error = format!(
+ "\"this\" object does not implement interface {}.",
+ proto_id_to_name(proto_id)
+ );
throw_type_error(cx, &error);
}
impl Error {
/// Convert this error value to a JS value, consuming it in the process.
- pub unsafe fn to_jsval(self, cx: *mut JSContext, global: &GlobalScope, rval: MutableHandleValue) {
+ pub unsafe fn to_jsval(
+ self,
+ cx: *mut JSContext,
+ global: &GlobalScope,
+ rval: MutableHandleValue,
+ ) {
assert!(!JS_IsExceptionPending(cx));
throw_dom_exception(cx, global, self);
assert!(JS_IsExceptionPending(cx));