Sundararajan's Weblog

Scripting updates...

Guest Author
It has been a while. I've not updated on scripting.dev.java.net project and related activities. Here it is ...

You probably know this already, but just in case you missed: JavaFX Script has jsr-223 script engine for it (included in javafxrt.jar). See also:

Join the discussion

Comments ( 4 )
  • Chris Winters Thursday, June 7, 2007
    The original Rhino defined a 'load()' function that allowed you to bring in symbols from a different script file to your scope. I've been huntring around for an equivalent in the Java 6 (or 7) implementation but am coming up short. Any pointers?
    Or is it something we should just copy-n-paste over :-)
  • A. Sundararajan Thursday, June 7, 2007
    There is no built-in "load" function to load scripts from files/URLs. But, it is possible to write one - the trick is to expose current engine object as a variable and call ScriptEngine.eval overloads to load scripts from URLs, Files or Strings. Or it is possible to use JavaScript built-in "eval" function. Within "jrunscript" tool there is a load function. You may want to consult the source code of "jrunscript" tool from openjdk.
  • Chris Winters Friday, June 8, 2007
    I see. I'm curious as to why it was left out from Rhino as it's pretty useful -- even though it's fairly straightforward to roll your own :-) Are there tricky security implications? Was Rhino's implementation buggy? Or was it deemed just not necessary?
  • A. Sundararajan Friday, June 8, 2007
    No, Rhino core never had "load" function. Only Rhino shell tool (whose language independent equivalent is jrunscript in JDK 6) has the "load" function defined. As for security is concerned, the usual Java networking policy [for remote loading of scripts] and file system policy [for file scripts] will be used. There is one tricky issue though -- let us say, you are writing a browser like app in Java with support for JavaScript [or any jsr-223 compliant language] and your app could load scripts from multiple sites. You may want to attach permission set based on script origin site -- much like applets are constrained by applet origin. This is really tricky. I guess you need to work with explicit AccessControlContexts/DomainCombiner/doPrivileged etc.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.