Nashorn ScriptObject suggestion
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Fri Mar 7 16:57:02 UTC 2014
Hi,
When you use javax.script API to evaluate scripts using nashorn engine,
script objects are wrapped as instances of a class named
jdk.nashorn.api.scripting.ScriptObjectMirror. This class implements
javax.script.Bindings (and so java.util.Map) as well.
ScriptObject cannot safely implement java.util.Map. Nashorn engine
requires global instance to be set as thread local (implementation
detail). When access is made from java code, we've to set/reset thread
local. Doing that in ScriptObject will have perf. implications.
ScriptObjectMirror takes care of set/reset thread local.
-Sundar
On Friday 07 March 2014 04:39 PM, Youssef EL HOUTI wrote:
> Hi,
> I'm working on a project when I use Nashorn with java 8 in many ways, and I
> thought that of an improvement in the class ScriptObject that doesn't cost
> much:
> What? Make ScriptObject implement Map <String,Object>
> Why?
>
> - we could call java function from javascript by passing a javascript
> Objact as argument.
> - we could get a js function result (JSON) in java without casting...
> - ScriptObject already define almost all the methods needed (if not all)
>
> thank you for your time and please let me know if it's a bad suggestion why?
> I would be glad to help coding that.
> Best Regards.
More information about the nashorn-dev
mailing list