JavaScriptCore Compatibility issue

Hey there. I am using JavaScriptCore to import a large JS library into my project and using swift to call my JS code. JavaScriptCore works magic for that and it works flawlessly on ios 11.4+


However--- the exact same file fails to load on pre 11.4 giving a javascript error.


My question is--- what changes between iOS versions to make javascript run successfully on particular versions but not on others.


Is it because we are using webkit which uses a different version of the javascript engine or something like that? Just trying to figure out how to try to support older ios versions and also ensure future compatibility.


Thanks!


  if let jsPath = Bundle.main.path(forResource: "bcoin", ofType: "js"),
     let js =  try? String.init(contentsOfFile: jsPath)

   let loaded = context.evaluateScript("\(js)")


Pre iOS 11.4 gives this JS error:

JS ERROR: SyntaxError: Unexpected keyword 'this'. Expected ')' to end an 'if' condition.


11.4+, no error. Why the difference?

JavaScriptCore is regularly updated to support updates to the JavaScript language. I don’t follow these updates closely — JavaScript, and web development in general, are largely outside of my area of expertise — but it’s perfectly normal for older releases of JavaScriptCore to fail if you give them JavaScript that uses these new features.

As to what’s going on with your specific case, it’s hard to say without looking at the JavaScript itself. My recommendation is that you dig into the JavaScript to work out exactly what JavaScriptCore is complaining about.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
JavaScriptCore Compatibility issue
 
 
Q