diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-09-27 09:58:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-27 09:58:42 -0500 |
commit | 06bb57bdcb7eb60ffe4058ced7301a5f285eede5 (patch) | |
tree | 7c38e8886bc8e8873ffb0cb0fd657aebf5dd633f /components/script/dom/bindings/utils.rs | |
parent | 1ed3521dcfdf573dd68afe18148e785a8af2389a (diff) | |
parent | 4654dd91a8d95a5b3350cf7b956a591080372cce (diff) | |
download | servo-06bb57bdcb7eb60ffe4058ced7301a5f285eede5.tar.gz servo-06bb57bdcb7eb60ffe4058ced7301a5f285eede5.zip |
Auto merge of #13406 - Mylainos:issue-13377, r=jdm
Extract panic-catching for JS engine callbacks into a separate function
All of our generated code for script contains inline code like this:
```
let result = panic::catch_unwind(AssertUnwindSafe(|| {
...
};
match result {
Ok(result) => result,
Err(error) => {
store_panic_result(error);
return false;
}
}
```
This PR change it to something like this:
```
wrap_panic(|| { ... }, false)
```
---
- [X] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [X] These changes fix #13377
- [ ] There are tests for these changes
<!-- 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/13406)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 32ffe4109ae..4a7d4d698fb 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -32,8 +32,11 @@ use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult}; use js::jsval::{JSVal, UndefinedValue}; use js::rust::{GCMethods, ToString}; use libc; +use script_runtime::store_panic_result; use std::ffi::CString; use std::os::raw::c_void; +use std::panic; +use std::panic::AssertUnwindSafe; use std::ptr; use std::slice; @@ -513,3 +516,15 @@ unsafe extern "C" fn instance_class_has_proto_at_depth(clasp: *const js::jsapi:: pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks { instanceClassMatchesProto: Some(instance_class_has_proto_at_depth), }; + +/// Generic wrapper for JS engine callbacks panic-catching +pub fn wrap_panic<T: FnMut() -> R, R>(function: T, generic_return_type: R) -> R { + let result = panic::catch_unwind(AssertUnwindSafe(function)); + match result { + Ok(result) => result, + Err(error) => { + store_panic_result(error); + generic_return_type + } + } +} |