javascriptiosobjective-cwebkitjavascriptcore

JavaScriptCore - Accessing DOMParser in iOS


I'm building an app for iPhone which will hopefully use the new JavaScriptCore framework added to iOS 7. I am using javascript as I need to add a javascript library citeproc-js to my project. I can get this library up and running by loading it in a UIWebView but I need to use it from a background thread so am trying to load it in a JSContext instead.

The problem I'm having is the library relies on using the DOMParser of webkit but the parser never loads when the framework is loaded into a JSContext.

Should it be possible to access a DOMParser from a JSContext? If not is there an alternative?

Thanks!


Solution

  • The JavaScript API provided by JSContext is actually the core API of the language - it even lacks stuff like console.log and setTimeout, because those are provided by browsers. Because DOMParser is another API defined outside of JavaScriptCore it shouldn't be accessible in JSContext.

    What you can do is expose a native XML parser like TBXML to the JSContext via the JSExport mechanism and consume that instead.