some nashorn testing

Andreas Rieber rieberandreas at gmail.com
Tue Jan 8 09:22:14 PST 2013


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?

importClass works only with: load("nashorn:mozilla_compat.js");
What is with importPackage (also used in jrunscript)?

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.

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.

best regards
Andreas



More information about the nashorn-dev mailing list