Question

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!

Was it helpful?

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.

OTHER TIPS

In case it simplifies things for readers hitting this question, the citeproc-js implementation of CSL now contains a string-based XML parser written in pure JavaScript. No exceptional setup is required beyond the essentials: if the processor is fed a valid XML string, it will work with it.

(Posting as the author and maintainer of citeproc-js)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top