These days I tried to replace the (almost exciting but mysterious) rhino by the uprising javax.script technology which would be included in the next big Java release (Mustang aka jdk1.6, available in ?late october 2006?).
I am using rhino for 2 years and I am steadily excited about it. I love java's capabilities (you may call it complexity), and I love javascript's simplicity. With rhino, they link together not only two technologies, but also different users: backend-framework-hardcore-java-application-developers on one side, lightweight-changeable-customizing-script-coders on the other side. This works great on our CMS, and I wont`change it - up to now.
With jsr223, the java community process decided to go one step beyond. Jsr223 describes an abstract API for the integration arbitrary script engines. Wow - that sounds great! You are free to choose the script engine - if you hate rhino( aka EcmaScript aka JavaScript), use groovy instead. Or any other script language available.
So I went out and redesigned our application:
OK - I redesigned the app it kept it running!
But quickly I stumbled into a problem. The follwing javascript wont work anymore:
Exception in thread “main” javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: “foo” is not defined. (#3) in at line number 3
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:93)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:230)
at test.main(test.java:11)
Thats crucial, because in java you often have to deal with null values and you need a convenient way to handle them in javascript. Note: The example above works fine with plain rhino!
The following workaround is not very suprising:
if ( typeof(foo) == ' undefined' )
...
The other point which isn`t suprising is what read in Sundararajan blog:
javascript in javax.script won`t support bytecode mode - it only runs in interpreted mode.
At this time I cannot estimate the effects, but it does not sound joyful: I assume, that the interpreted mode wont run as fast as the compiled/bytecode mode. With these two disadvantages I will continue the javax.script integration only if they are solved.
If anyone had solved the null problem - it would be great if you can send me the solution!