Review request JDK-8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine

A. Sundararajan sundararajan.athijegannathan at oracle.com
Wed Feb 27 03:16:21 PST 2013


Hi Andreas,

The issue is that user script can't be used "as is" between jjs, 
jrunscript, nodejar. i.e., user script has to use print or println based 
on which tool runs the script and load mozilla_compat.js conditionally 
(although loading again won't harm in this case) and so on.

Not sure if that is desirable. I'll discuss and then file a bug.

Thanks
-Sundar

On Wednesday 27 February 2013 04:40 PM, Andreas Rieber wrote:
> Hi Sundar,
>
> i had the same thought like Hannes. It would be more 'compatible' when 
> it comes to jsr223 adding print, println and the load 
> mozilla_compat.js in the engine.js file. This does not affect 
> standalone Nashorn. Just an idea...
>
> Andreas
>
> diff -r a90094ae5be3 src/jdk/nashorn/api/scripting/resources/engine.js
> --- a/src/jdk/nashorn/api/scripting/resources/engine.js    Tue Feb 26 
> 22:57:51 2013 +0530
> +++ b/src/jdk/nashorn/api/scripting/resources/engine.js    Wed Feb 27 
> 12:01:36 2013 +0100
> @@ -39,10 +39,22 @@
>      }
>  });
>
> -function print(str) {
> -    var writer = context.getWriter();
> -    if (! (writer instanceof java.io.PrintWriter)) {
> -        writer = new java.io.PrintWriter(writer);
> +function print(str, newline) {
> +    if (typeof(str) == 'undefined') {
> +        str = 'undefined';
> +    } else if (str == null) {
> +        str = 'null';
>      }
> -    writer.println(String(str));
> +    var out = context.getWriter();
> +    if (!(out instanceof java.io.PrintWriter))
> +        out = new java.io.PrintWriter(out);
> +    out.print(String(str));
> +    if (newline) out.print("\n");
> +    out.flush();
>  }
> +
> +function println(str) {
> +    print(str, true);
> +}
> +
> +load("nashorn:mozilla_compat.js");
>
>
>
> On 27.02.13 11:48, A. Sundararajan wrote:
>> Well, the tests do assume things about the underlying engine - such 
>> as engine version, language version, language extensions like java 
>> support and so on. (like importPackage). We used to depend on rhino 
>> engine - I made nashorn dependency and used explicit dependency to 
>> use other js engines.
>>
>> -Sundar
>>
>> On Wednesday 27 February 2013 03:21 PM, Hannes Wallnoefer wrote:
>>> Looks good to me.
>>>
>>> I'm wondering if we shouldn't leave the engine name as "js" in the 
>>> tests though, as part of their purpose seems to test the standard JS 
>>> engine?
>>>
>>> Hannes
>>>
>>> Am 2013-02-27 07:14, schrieb A. Sundararajan:
>>>> Please review http://cr.openjdk.java.net/~sundar/8009115/
>>>>
>>>> README has details on changes: 
>>>> http://cr.openjdk.java.net/~sundar/8009115/README
>>>>
>>>> -Sundar



More information about the nashorn-dev mailing list