ericwlange / AndroidJSCore

AndroidJSCore allows Android developers to use JavaScript natively in their apps.
468 stars 78 forks source link

JavaScript Syntax error #46

Closed whkailee closed 7 years ago

whkailee commented 8 years ago

Hi, I have a large js file(which I use for iOS JavaScriptCore without any issue) to load into JSContext, and it throws JSException like "unexpected script end". There is no more information I can find such as which line and what exactly is missing.

ericwlange commented 7 years ago

That generally implies that there is a mismatched closing quote, brace, bracket or paren somewhere. As you haven't posted the code, I can't debug it. One suggestion: open a node console and see if it loads correctly.

machine:~ me$ cd /path/to/js/file
machine:~ me$ node
> var code = String(fs.readFileSync('file.js'))
> eval(code)

If the last line executes without throwing an exception, the file is probably fine. It's a good check to see if iOS JavaScriptCore is ignoring something.

The other possibility is that you are using some ES6 extensions to JavaScript. Later versions of iOS may support it. AndroidJSCore is using only an ES5 compliant version of JS at the moment.

whkailee commented 7 years ago

Thanks that method helps. I use minified JavaScript files and it can get ride of all the syntax errors.