Script arrays are accessed via JSObject as well. You've JSObject.get/setSlot methods to access array elements. Array length can be accessed using JSObject.getMember("length")

-Sundar

On Sunday 09 June 2013 10:48 PM, Mani Sarkar wrote:


---------- Forwarded message ----------
From: *Mani Sarkar* <[email protected] <mailto:[email protected]>>
Date: Sun, Jun 9, 2013 at 11:30 AM
Subject: Re: Nashorn: Javascript to Java call question
To: [email protected] <mailto:[email protected]>


Hi guys,

I have resolved the earlier error that I reported, I thought I was using the correct jdk but then I wasn't and switching to the latest version of the OpenJDK (nashorn) source and then bootstrapping to the image created by the build process fixed it (hinted by you) - thanks for that.

I'm now able to access the member elements, returned by Javascript through the JSObject. Although the JSON I created also contained an array of string elements, which I wasn't able to access but got [object Array] when I printed it to console.

I tried casting it to org.json.JSONArray but it was of no use. Then I came across the link http://cr.openjdk.java.net/~hannesw/8007060/webrev.01/src/jdk/nashorn/internal/objects/NativeFunction.java.html <http://cr.openjdk.java.net/%7Ehannesw/8007060/webrev.01/src/jdk/nashorn/internal/objects/NativeFunction.java.html>, and applying the checks on the object to see if it can be converted or not I got the output: function.apply.expects.array (didn't pass any of the checks, and terminated at the last else).

Is there a JSONArray object within the nashorn package that I could use? Do you have any other example for that?

Thanks.

Regards.
Mani


On Fri, Jun 7, 2013 at 8:03 PM, Mani Sarkar <[email protected] <mailto:[email protected]>> wrote:

    Thanks Sundar, Jim for the explanation.

    I extracted the jsobjectTest() from ScriptEngineTest.java as it is
    and compiled and ran it, when I run it I still get the same error
    that I got with my example. I have put all of this in a gist to
    demonstrate what I was doing:
    https://gist.github.com/neomatrix369/5731520

    I also ran the ScriptEngineTest using the jtreg command and that
    ran successfully:

     ~/jtreg/linux/bin/jtreg -jdk:/usr/lib/jdk1.8.0
    -Xbootclasspath/p:$HOME/sources/jdk8_tl/nashorn/dist/nashorn.jar
    -verbose:fail test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java

    Regards,
    mani


--
*Twitter:* @theNeomatrix369 *Blog:* http://neomatrix369.wordpress.com
*JUG activity:* LJC Advocate (@adoptopenjdk & @adoptajsr programs)
*Meet-a-Project:* https://github.com/MutabilityDetector
*Bitbucket:*https://bitbucket.org/neomatrix369 ***Github:*https://github.com/neomatrix369 <https://github.com/neomatrix369>
*LinkedIn:* http://uk.linkedin.com/pub/mani-sarkar/71/a77/39b
*Devoxx UK 2013* was a grand success: http://www.devoxx.com/display/UK13/Home

*/Don't chase success, rather aim for "Excellence", and success will come chasing after you!/*

Reply via email to