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 -->
This commit is contained in:
bors-servo 2016-09-27 09:58:42 -05:00 committed by GitHub
commit 06bb57bdcb
2 changed files with 18 additions and 12 deletions

View file

@ -2383,16 +2383,8 @@ class CGAbstractMethod(CGThing):
if self.catchPanic:
body = CGWrapper(CGIndenter(body),
pre="let result = panic::catch_unwind(AssertUnwindSafe(|| {\n",
post=("""}));
match result {
Ok(result) => result,
Err(error) => {
store_panic_result(error);
return%s;
}
}
""" % ("" if self.returnType == "void" else " false")))
pre="return wrap_panic(|| {\n",
post=("""}, %s);""" % ("()" if self.returnType == "void" else "false")))
return CGWrapper(CGIndenter(body),
pre=self.definition_prologue(),
@ -5566,6 +5558,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings::utils::resolve_global',
'dom::bindings::utils::set_dictionary_property',
'dom::bindings::utils::trace_global',
'dom::bindings::utils::wrap_panic',
'dom::bindings::trace::JSTraceable',
'dom::bindings::trace::RootedTraceable',
'dom::bindings::callback::CallSetup',
@ -5617,14 +5610,12 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'libc',
'util::prefs::PREFS',
'script_runtime::maybe_take_panic_result',
'script_runtime::store_panic_result',
'std::borrow::ToOwned',
'std::cmp',
'std::mem',
'std::num',
'std::os',
'std::panic',
'std::panic::AssertUnwindSafe',
'std::ptr',
'std::str',
'std::rc',