Ambly Using JavaScriptCore C API

The Ambly 0.4.0 release involves a revision to use the low-level JavaScriptCore C API. Ambly was previously using the new Objective-C API wrapper that Apple had introduced with iOS 7.

This change broadens the usability of Ambly, making it easier to compose with projects that don't use the Objective-C API (React Native, for example). But more importantly: It fundamentally makes it possible to use Ambly in projects that don't have JavaScriptCore built with JSC_OBJC_API_ENABLED . One example is Ejecta; it is now possible to use Ambly to live-code Ejecta using ClojureScript.









To make this change essentially involved rewriting portions of the Objective-C side of the Ambly REPL to use C, using JSGlobalContextRef and related low-level API calls instead of the higher-level JSContext affordances. This really amounted to re-implementing working code to simply use analogous constructs, but all of this is internal and transparent to users.

The only visible Ambly API changes are that JSGlobalContextRef must be passed in in places where JSContext was previously. Apple makes this nearly trivial with a couple of bridging methods:

+[JSContext contextWithJSGlobalContextRef:] -[JSContext JSGlobalContextRef]

Additionally, one of the JSContext -specific ABYContextManager APIs has been deprecated as it is no longer relevant.

From my perspective, the biggest change for this release is that a lot of the code became a little more… let's say, cumbersome, owing to the verbosity of the C style and the need to do manual memory management. But in my opinion, this is definitely worth it.

Also, there is a possibility that Facebook may use JavaScriptCore as the JavaScript engine for React Native on Android. If that's the case, it may turn out that coming to grips with the JavaScriptCore C API may pay off later when updating Ambly to work with Android!