Here’s another gif album cover collab with Anamanaguchi. For their Summer Singles 2020 collection.
How to keep JSContext from crashing your iOS 7 app
I found a pretty sneaky JavaScript Core bug recently which was triggered by getting an exception when evaluating JavaScript with a JSContext. When the JSContext that caught the exception is deallocated, it would crash my app. Luckily I ran into this not long before WWDC so I was able to get some help with it in the WebKit lab. As it turns out there was a bug in JSContext’s dealloc method that was only just recently fixed, but unfortunately we won’t see that fix until iOS8 is out. If you need to support iOS 7 and want to use JSContext to evaluate JS, the fix is very simple; before your context gets released, simply nil out its exception property. Here’s a simple code example:
@autoreleasepool {
JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init];
[context evaluateScript:@"bad"];
// This needs to get nil'd before deallocation
context.exception = nil;
}
So save yourself the trouble and make sure to always clear the exception of any contexts you have used to evaluate code before deallocating it if you’re targeting iOS 7.