calatrava/calatrava-ios — pull request #8 by jagregory (2013-03-13 08:07:58+00:00)
Title: [ios] Safer javascript execution

Whenever javascript is executed in the web views, namely to render pages or fire events, there's the possibility the call might throw an exception; when an exception is uncaught, the whole javascript execution fails and the app becomes useless.

This change wraps every call to the javascript runtime in a try...catch block and returns any unhandled exceptions to the caller (in string form, as you can't return objects). If the resulting string contains an exception, it's rethrown as a native NSException. This makes the app fail fast if there's a javascript error, I think that's the right thing to do.

Effectively, every native call to javascript has changed from:

``` javascript
views.something.render('abc');
```

to looking like this:

``` javascript
(function() {
try {
return views.something.render('abc');
} catch (ex) {
return '@@EX@@' + ex.toString() + '\n' + ex.stack.toString();
}
})();
```