rsingla / jslint4java

Automatically exported from code.google.com/p/jslint4java
Other
0 stars 0 forks source link

Error trying to evaluate a javascript string java.lang.ClassCastException #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i've imported the library in my application to try to evaluate the correctness 
of some javascript string but when i try to generate a report from the JSLint  
class, i get this error : 

Exception in thread "main" java.lang.ClassCastException: 
org.mozilla.javascript.UniqueTag cannot be cast to 
org.mozilla.javascript.Function
    at com.googlecode.jslint4java.JSLint$3.run(JSLint.java:217)
    at org.mozilla.javascript.Context.call(Context.java:521)
    at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:535)
    at com.googlecode.jslint4java.JSLint.doLint(JSLint.java:213)
    at com.googlecode.jslint4java.JSLint.report(JSLint.java:340)
    at Main.main(Main.java:23)

The code that i try to execute is this one : 

ContextFactory cf = new ContextFactory();
        Context cx = cf.enterContext();
        String js = "new Date();";
        ScriptableObject so = cx.initStandardObjects();
        JSLint l = new JSLint(cf, so);

        String er = l.report(js, true);
        er.toString();

Am i doing something wrong ? 

I simply want to evaluate a string and check if it is a valid javascript (no 
syntax error) .

Original issue reported on code.google.com by Alessio....@gmail.com on 9 Jan 2012 at 9:33

GoogleCodeExporter commented 9 years ago
Firstly, if you're only concerned with “is it JavaScript,” would just 
evaluating be enough?  JSLint holds code to a higher standard than “no syntax 
errors.”

The problem is that you're not initialising JSLint correctly.  You need to 
start with JSLintBuilder, not JSLint.  My apologies that this isn't clear 
enough from the Javadoc.  In particular, jslint4java shouldn't require you to 
manage ContextFactory objects.

I'll update the Javadoc to make this clear.

Original comment by d...@happygiraffe.net on 10 Jan 2012 at 7:58

GoogleCodeExporter commented 9 years ago

Original comment by d...@happygiraffe.net on 10 Jan 2012 at 8:00

GoogleCodeExporter commented 9 years ago
Docs fixed in a476fd423f828b08fad4767953b4f10a4e1d46a0.

Original comment by d...@happygiraffe.net on 11 Jan 2012 at 8:12