There is JSAdapter support in nashorn (like jdk6/7 Rhino supported). JSAdapter is used within script to intercept get/put/call etc. Also it is possible to supply your own impl of jdk.nashorn.api.scripting.JSObject -- which can be used with natural script syntax from script. You can intercept calls, property access in your code.

Hope this helps
-Sundar

On Tuesday 08 October 2013 02:32 PM, Rick Bullotta wrote:
On a related topic, I'm particularly interested in better understanding the 
*Adapter model in Nashorn and how it compares to Rhino, particularly in terms 
of custom adapters.

In Rhino, we use custom adapters to intercept get/set/delete/put and other 
methods to allow dynamic access to a variety of data structures and objects (we 
can virtualize properties and functions this way, versus automatic reflection 
and type munging), and it isn't at all clear how to do this with Nashorn.

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Tal Liron
Sent: Tuesday, October 08, 2013 8:26 AM
To: [email protected]
Subject: Re: From JS to Java objects?

Sorry about that, was trying to be succinct.

In detail: I'm creating Nashorn scripts programmatically from Java (using 
Context.compileScript and ScriptRuntime.apply), and receiving native results 
that need some massaging in order to be usable in Java.
(Specifically I'm working on creating a Nashorn adapter for Scripturian.)

However, I mostly found the answers myself:

1. It's possible to call NativeJava.to (equivalent to Java.to in JavaScript) 2. 
More efficient is to test specifically for NativeArray results and wrap them in 
a ListAdapter, which makes them conform to the List interface. This is what 
NativeJava.to does internally.

On 10/08/2013 08:12 PM, Jim Laskey (Oracle) wrote:
Please be more specific with an example.  I assume you want to extend
a Java class or some such requirement,


Reply via email to