Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you want to explicitly wrap a script object to a ScriptObjectMirror instance and pass along to any API (which may even accept Object), you can use jdk.nashorn.api.scripting.ScriptUtils class's wrap method. Similarly you can explicitly unwrap a ScriptObjectMirror to a script object via unwrap method. Note that unwrap won't unwrap the object if it is not a wrapper of object created with the current global object. In most instances you won't have to wrap/unwrap manually. In Java code, always operate on ScriptObjectMirror instances and in script you'll always see normal ScriptObject (unwrapped) instances automatically.

JavaDoc for

...

Nashorn specific API

...

jdk.nashorn.api.* is considered to be fairly stable the only Nashorn specific API package (extension to javax.script). Anything else is considered to be Nashorn implementation detail and can/will be changed in future.8u40 jdk.nashorn.api javadoc

jdk8: https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/index.html?jdk/nashorn/api/scripting/package-summary.html

jdk9 http://download.java.net/jdk9/docs/jdk/api/nashorn/

...

While nashorn attempts to give a seamless illusion of ScriptObjectMirrors and JSObjects, not every operation and script API (JSON, Array, Function's properties/functions) treats ScriptObjectMirror and jdk.nashorn.internal.runtime.ScriptObject uniformly. There are places where ScriptObjects work as expected but if you pass ScriptObjectMirror or your own JSObject implementation, it won't work as expected.

Security Permissions for Nashorn scripts

Nashorn script security permissions