some nashorn testing/ jrunscript patch

Jim Laskey (Oracle) james.laskey at oracle.com
Thu Jan 10 12:12:03 PST 2013


Thanks Andreas.  Looks good, but I'll get Sundar (jrunscript expert) to review everything first.

Cheers,

-- Jim


On 2013-01-10, at 3:45 PM, Andreas Rieber <rieberandreas at gmail.com> wrote:

> Hi Jim,
> 
> please find attached the jrunscript patch(es). The small Nashorn patch took me a while to find out... The jdk8 patch is hg export -g like expected on openjdk.java.net contributing page. I also updated the jtreg test.
> 
> The patch for jdk8 has a new file for the formatting. Tricky part for printf/sprintf was to do the type conversion of the javascript types. The init.js file will now work with Nashorn and Rhino.
> 
> nashorn> printf("%5d %f %s %B %c %<d %n", 1, 2, "3", true, "a");
>    1 2.000000 3 TRUE a 97
> nashorn> printf("java.util.Date(): %1$tm %1$te, %1$tY%n", new java.util.Date());
> java.util.Date(): 01 10, 2013
> nashorn> printf("javascript Date(): %1$tm %1$te, %1$tY%n", new Date());
> javascript Date(): 01 10, 2013
> nashorn> printf("%c %c %c %d %d%n", 'a', "b", 65, -1, "Hello");
> a b A -1 72
> nashorn>
> 
> The jdk8 patch works also for jdk7u as that's where i started.
> I will see if i get scriptpad sample also working.
> 
> - Andreas
> 
> 
> On 08.01.13 19:12, Jim Laskey (Oracle) wrote:
>> On 2013-01-08, at 1:22 PM, Andreas Rieber <rieberandreas at gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> i tested Nashorn with a project i am currently working on (scripting
>>> java). The first thing i spotted is that Rhino comes with print() and
>>> println() as default functions in:
>>> 
>>> jdk8/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java
>>> 
>>> while Nashorn has only a print():
>>> 
>>> jdk8/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
>>> jdk8/nashorn/src/jdk/nashorn/api/scripting/resources/engine.js
>>> 
>>> Will this be changed or is that a migration issue?
>> We opted for print because we were primarily using V8 performance tests and v8 only supports print.  Standalone rhino does not support println either.  We did have a switch for turning on println, but it fell out of favour to be consistent with other VMs.
>> 
>> You can duplicate the behaviour with;
>> 
>> function print(s) { java.lang.System.out.print("" + s); }
>> function println(s) { java.lang.System.out.println("" + s); }
>> 
>> 
>>> importClass works only with: load("nashorn:mozilla_compat.js");
>>> What is with importPackage (also used in jrunscript)?
>>> 
>> importClass is being phased out since it duplicates the builtin behaviour of Packages and JavaClass.
>> 
>> importPackage(java.awt);
>> importClass(java.awt.Frame);
>> 
>> is just
>> 
>> var awt = java.awt;
>> var Frame = java.awt.Frame;
>> 
>> 
>>> Next problem i had was related to java array creation. Here the sample
>>> from JSE 7 Documentation "Java Scripting Programmer's Guide":
>>> 
>>> // create Java String array of 5 elements
>>> var a = java.lang.reflect.Array.newInstance(java.lang.String, 5);
>>> 
>>> // Accessing elements and length access is by usual Java syntax
>>> a[0] = "scripting is great!";
>>> print(a.length);
>>> 
>>> It works with Rhino but fails with Nashorn:
>>> 
>>> Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(java.lang.Class, int[]), (java.lang.Class, int)] or the variable arity signatures [(java.lang.Class, int...)] of the method java.lang.reflect.Array.newInstance match the argument types [org.dynalang.dynalink.beans.StaticClass, java.lang.Integer]
>>> 
>>> The default number type for Rhino in vararg functions is double while
>>> Nashorn has also integer (nice), might be a migration issue.
>> 
>> We are pushing the Java syntax here to eliminate confusion between the java class and the JavaClass javascript object.  This eliminates the confusion when accessing members of the (String) class when a javascript object and members of the class itself when a java object.
>> 
>> jjs> java.lang.String
>> [JavaClass java.lang.String]
>> jjs> java.lang.String.class
>> class java.lang.String
>> 
>> so
>> 
>> var a = java.lang.reflect.Array.newInstance(java.lang.String.class, 5);
>> 
>>> Is jrunscript and the scriptpad sample application
>>> (jdk8/jdk/src/share/sample/scripting/scriptpad) now also developed
>>> under Nashorn project? I would like to contribute a patch for
>>> jrunscript (printf never worked and i added also a sprintf), the
>>> scriptpad needed only a few fixes to work with Rhino. I signed the OCA
>>> recently.
>> Contributions welcome.
>> 
>> I just see Attila answered differently, but both forms work.
>> 
>> 
>>> best regards
>>> Andreas
>>> 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: jrunscript_nashorn.patch
Url: http://mail.openjdk.java.net/pipermail/nashorn-dev/attachments/20130110/02ddb21e/jrunscript_nashorn.patch 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: jrunscript_jdk8.patch
Url: http://mail.openjdk.java.net/pipermail/nashorn-dev/attachments/20130110/02ddb21e/jrunscript_jdk8.patch 
-------------- next part --------------



More information about the nashorn-dev mailing list