I've created a WebView which responds to a URL change event.
The crash happens most often when calling a delegate multiple times very quickly, but have been able to reproduce when my WebView isn't completely instantiated on first load as well (although rare). If I click a button in my WebView that changes the URL even three times very quickly, I get the crash every time.
Since EXC_BAD_ACCESS commonly relates to referencing an object which no longer exists, I saw this line as suspect in MochaJSDelegate:
var dynamicFunction = eval('(function (' + args.join(', ') + ') { return dynamicHandler.apply(this, arguments); })')
If I replace with this, it works flawlessly:
delegateClassDesc.addInstanceMethodWithSelector_function_(selector, function() {
func.apply(delegateClassDesc, arguments);
})
Somewhere along the way of using eval and calling the two anonymous functions (see also dynamicHandler function), a disconnect exists with memory management. Note that with my workaround, I'm unable to access the function parameters in my delegate function, so it's not a real solution for the MochaJSDelegate library.
As a result I ended up creating the class delegate manually myself (allowing me to access arguments), but it'd be nice if I could have both arguments and no crashing in the current lib so I don't have to do it manually in my app.
If you have any ideas with that broad overview let me know! I can setup an example if you aren't sure just based on that information where the issue is.
Thanks!
I've created a WebView which responds to a URL change event.
The crash happens most often when calling a delegate multiple times very quickly, but have been able to reproduce when my WebView isn't completely instantiated on first load as well (although rare). If I click a button in my WebView that changes the URL even three times very quickly, I get the crash every time.
Since
EXC_BAD_ACCESScommonly relates to referencing an object which no longer exists, I saw this line as suspect in MochaJSDelegate:If I replace with this, it works flawlessly:
Somewhere along the way of using
evaland calling the two anonymous functions (see alsodynamicHandlerfunction), a disconnect exists with memory management. Note that with my workaround, I'm unable to access the function parameters in my delegate function, so it's not a real solution for the MochaJSDelegate library.As a result I ended up creating the class delegate manually myself (allowing me to access arguments), but it'd be nice if I could have both arguments and no crashing in the current lib so I don't have to do it manually in my app.
If you have any ideas with that broad overview let me know! I can setup an example if you aren't sure just based on that information where the issue is.
Thanks!