From JS to Java objects?
Rick Bullotta
rick.bullotta at thingworx.com
Tue Oct 8 05:32:29 PDT 2013
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: nashorn-dev-bounces at openjdk.java.net [mailto:nashorn-dev-bounces at openjdk.java.net] On Behalf Of Tal Liron
Sent: Tuesday, October 08, 2013 8:26 AM
To: nashorn-dev at openjdk.java.net
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,
>
More information about the nashorn-dev
mailing list