mirror of
https://github.com/servo/servo.git
synced 2025-06-18 05:14:28 +00:00
Invert conditional and return early from report_pending_exception
This commit is contained in:
parent
3916d1d613
commit
f064d9ad83
1 changed files with 42 additions and 42 deletions
|
@ -202,52 +202,52 @@ impl ErrorInfo {
|
||||||
/// The `dispatch_event` argument is temporary and non-standard; passing false
|
/// The `dispatch_event` argument is temporary and non-standard; passing false
|
||||||
/// prevents dispatching the `error` event.
|
/// prevents dispatching the `error` event.
|
||||||
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool) {
|
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool) {
|
||||||
if JS_IsExceptionPending(cx) {
|
if !JS_IsExceptionPending(cx) { return; }
|
||||||
rooted!(in(cx) let mut value = UndefinedValue());
|
|
||||||
if !JS_GetPendingException(cx, value.handle_mut()) {
|
|
||||||
JS_ClearPendingException(cx);
|
|
||||||
error!("Uncaught exception: JS_GetPendingException failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
rooted!(in(cx) let mut value = UndefinedValue());
|
||||||
|
if !JS_GetPendingException(cx, value.handle_mut()) {
|
||||||
JS_ClearPendingException(cx);
|
JS_ClearPendingException(cx);
|
||||||
let error_info = if value.is_object() {
|
error!("Uncaught exception: JS_GetPendingException failed");
|
||||||
rooted!(in(cx) let object = value.to_object());
|
return;
|
||||||
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 {}:{}:{} {}",
|
JS_ClearPendingException(cx);
|
||||||
error_info.filename,
|
let error_info = if value.is_object() {
|
||||||
error_info.lineno,
|
rooted!(in(cx) let object = value.to_object());
|
||||||
error_info.column,
|
let error_info = ErrorInfo::from_native_error(cx, object.handle())
|
||||||
error_info.message);
|
.or_else(|| ErrorInfo::from_dom_exception(object.handle()));
|
||||||
|
match error_info {
|
||||||
if dispatch_event {
|
Some(error_info) => error_info,
|
||||||
GlobalScope::from_context(cx)
|
None => {
|
||||||
.report_an_error(error_info, value.handle());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue