Invert conditional and return early from report_pending_exception

This commit is contained in:
Florian Hartwig 2016-10-13 23:28:24 +02:00
parent 3916d1d613
commit f064d9ad83

View file

@ -202,52 +202,52 @@ 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) {
rooted!(in(cx) let mut value = UndefinedValue());
if !JS_GetPendingException(cx, value.handle_mut()) {
JS_ClearPendingException(cx);
error!("Uncaught exception: JS_GetPendingException failed");
return;
}
if !JS_IsExceptionPending(cx) { return; }
rooted!(in(cx) let mut value = UndefinedValue());
if !JS_GetPendingException(cx, value.handle_mut()) {
JS_ClearPendingException(cx);
let error_info = if value.is_object() {
rooted!(in(cx) let object = value.to_object());
let error_info = ErrorInfo::from_native_error(cx, object.handle())
.or_else(|| ErrorInfo::from_dom_exception(object.handle()));
match error_info {
Some(error_info) => error_info,
None => {
error!("Uncaught exception: failed to extract information");
return;
}
}
} 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,
}
},
_ => {
panic!("Uncaught exception: failed to stringify primitive");
},
}
};
error!("Uncaught exception: JS_GetPendingException failed");
return;
}
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());
JS_ClearPendingException(cx);
let error_info = if value.is_object() {
rooted!(in(cx) let object = value.to_object());
let error_info = ErrorInfo::from_native_error(cx, object.handle())
.or_else(|| ErrorInfo::from_dom_exception(object.handle()));
match error_info {
Some(error_info) => error_info,
None => {
error!("Uncaught exception: failed to extract information");
return;
}
}
} 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,
}
},
_ => {
panic!("Uncaught exception: failed to stringify primitive");
},
}
};
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());
}
}