Auto merge of #13755 - fhartwig:early-return, r=KiChjang

Invert conditional and return early from report_pending_exception

<!-- Please describe your changes on the following line: -->
Previously, almost the entire body of `report_pending_exception` was in a conditional branch. We now return early if the function body does not need to be executed.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13746 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they don't add any new functionality.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13755)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-13 16:40:16 -05:00 committed by GitHub
commit 3e12af5815

View file

@ -202,7 +202,8 @@ 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()); rooted!(in(cx) let mut value = UndefinedValue());
if !JS_GetPendingException(cx, value.handle_mut()) { if !JS_GetPendingException(cx, value.handle_mut()) {
JS_ClearPendingException(cx); JS_ClearPendingException(cx);
@ -248,7 +249,6 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
GlobalScope::from_context(cx) GlobalScope::from_context(cx)
.report_an_error(error_info, value.handle()); .report_an_error(error_info, value.handle());
} }
}
} }
/// Throw an exception to signal that a `JSVal` can not be converted to any of /// Throw an exception to signal that a `JSVal` can not be converted to any of