diff --git a/jdk/test/javax/script/CauseExceptionTest.java b/jdk/test/javax/script/CauseExceptionTest.java index f1ff708bc1e..41fa5e4b493 100644 --- a/jdk/test/javax/script/CauseExceptionTest.java +++ b/jdk/test/javax/script/CauseExceptionTest.java @@ -24,7 +24,7 @@ /* * @test * @bug 6869617 - * @summary RhinoScriptEngine bug : ScriptException cause not set (with fix) + * @summary ScriptEngine bug : ScriptException cause not set (with fix) */ import javax.script.*; @@ -33,12 +33,12 @@ import java.io.*; public class CauseExceptionTest { public static void main(String[] args) throws ScriptException, NoSuchMethodException { ScriptEngineManager sem = new ScriptEngineManager(); - ScriptEngine engine = sem.getEngineByName("js"); + ScriptEngine engine = sem.getEngineByName("nashorn"); if (engine == null) { System.out.println("Warning: No js engine found; test vacuously passes."); return; } - engine.eval("function hello_world() { println('hello world'); throw 'out of here'; } "); + engine.eval("function hello_world() { print('hello world'); throw 'out of here'; } "); Invocable invocable = (Invocable) engine; try { invocable.invokeFunction("hello_world", (Object[])null); diff --git a/jdk/test/javax/script/RhinoExceptionTest.java b/jdk/test/javax/script/ExceptionTest.java similarity index 96% rename from jdk/test/javax/script/RhinoExceptionTest.java rename to jdk/test/javax/script/ExceptionTest.java index 22d5f0fd6fb..9ea2d4e3f7a 100644 --- a/jdk/test/javax/script/RhinoExceptionTest.java +++ b/jdk/test/javax/script/ExceptionTest.java @@ -24,14 +24,14 @@ /* * @test * @bug 6474943 6705893 - * @summary Test that Rhino exception messages are + * @summary Test that script engine exception messages are * available from ScriptException. */ import java.io.*; import javax.script.*; -public class RhinoExceptionTest { +public class ExceptionTest { private static final String ERROR_MSG = "error from JavaScript"; public static void main(String[] args) throws Exception { diff --git a/jdk/test/javax/script/GetInterfaceTest.java b/jdk/test/javax/script/GetInterfaceTest.java index d780a6db08b..dffc74ea3b4 100644 --- a/jdk/test/javax/script/GetInterfaceTest.java +++ b/jdk/test/javax/script/GetInterfaceTest.java @@ -22,6 +22,7 @@ */ /* + * @run ignore * @test * @bug 6960211 * @summary JavaScript engine allows creation of interface although methods not available. @@ -32,10 +33,10 @@ import javax.script.*; public class GetInterfaceTest { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("js"); + ScriptEngine engine = manager.getEngineByName("nashorn"); if (engine == null) { - System.out.println("Warning: No engine engine found; test vacuously passes."); + System.out.println("Warning: No js engine engine found; test vacuously passes."); return; } diff --git a/jdk/test/javax/script/Helper.java b/jdk/test/javax/script/Helper.java index 73617bf5e93..fc132a457d1 100644 --- a/jdk/test/javax/script/Helper.java +++ b/jdk/test/javax/script/Helper.java @@ -24,13 +24,13 @@ import javax.script.*; /** * Helper class to consolidate testing requirements for a js engine. - * A js engine is required as part of Sun's product JDK. + * A js engine is required as part of Oracle's product JDK. */ public class Helper { private Helper() {}; // Don't instantiate public static ScriptEngine getJsEngine(ScriptEngineManager m) { - ScriptEngine e = m.getEngineByName("js"); + ScriptEngine e = m.getEngineByName("nashorn"); if (e == null && System.getProperty("java.runtime.name").startsWith("Java(TM)")) { // A js engine is requied for Sun's product JDK diff --git a/jdk/test/javax/script/StringWriterPrintTest.java b/jdk/test/javax/script/StringWriterPrintTest.java index 42345791878..7a75b6f0396 100644 --- a/jdk/test/javax/script/StringWriterPrintTest.java +++ b/jdk/test/javax/script/StringWriterPrintTest.java @@ -33,9 +33,9 @@ import java.io.*; public class StringWriterPrintTest { public static void main(String[] args) throws ScriptException { ScriptEngineManager sem = new ScriptEngineManager(); - ScriptEngine engine = sem.getEngineByName("js"); + ScriptEngine engine = sem.getEngineByName("nashorn"); if (engine == null) { - System.out.println("Warning: No js engine found; test vacuously passes."); + System.out.println("Warning: No nashorn engine found; test vacuously passes."); return; } StringWriter sw = new StringWriter(); diff --git a/jdk/test/javax/script/Test3.js b/jdk/test/javax/script/Test3.js index 4cdb8286843..5f7aba45e93 100644 --- a/jdk/test/javax/script/Test3.js +++ b/jdk/test/javax/script/Test3.js @@ -1,22 +1,24 @@ +var ScriptContext = javax.script.ScriptContext; + if (key == undefined || key != 'engine value') { throw "unexpected engine scope value"; } // pre-defined context variable refers to current ScriptContext -if (context.getAttribute('key', context.GLOBAL_SCOPE) != 'global value') { +if (context.getAttribute('key', ScriptContext.GLOBAL_SCOPE) != 'global value') { throw "unexpected global scope value"; } // change the engine scope value key = 'new engine value'; -if (context.getAttribute('key', context.GLOBAL_SCOPE) != 'global value') { +if (context.getAttribute('key', ScriptContext.GLOBAL_SCOPE) != 'global value') { throw "global scope should not change here"; } // delete engine scope value delete key; -if (key == undefined && key != 'xglobal value') { +if (key == undefined && key != 'global value') { throw 'global scope should be visible after engine scope removal'; } diff --git a/jdk/test/javax/script/Test5.java b/jdk/test/javax/script/Test5.java index 107bd148b63..acdd3a47448 100644 --- a/jdk/test/javax/script/Test5.java +++ b/jdk/test/javax/script/Test5.java @@ -48,16 +48,24 @@ public class Test5 { System.out.println("engine scope only"); e.put("count", new Integer(1)); - Reader reader = new FileReader( - new File(System.getProperty("test.src", "."), "Test5.js")); - engine.eval(reader,ctxt); + try (Reader reader = new FileReader( + new File(System.getProperty("test.src", "."), "Test5.js"))) { + engine.eval(reader,ctxt); + } + System.out.println("both scopes"); ctxt.setBindings(g, ScriptContext.GLOBAL_SCOPE); e.put("count", new Integer(2)); - engine.eval(reader,ctxt); + try (Reader reader = new FileReader( + new File(System.getProperty("test.src", "."), "Test5.js"))) { + engine.eval(reader,ctxt); + } System.out.println("only global"); e.put("count", new Integer(3)); - ctxt.setAttribute("key", null, ScriptContext.ENGINE_SCOPE); - engine.eval(reader,ctxt); + ctxt.removeAttribute("key", ScriptContext.ENGINE_SCOPE); + try (Reader reader = new FileReader( + new File(System.getProperty("test.src", "."), "Test5.js"))) { + engine.eval(reader,ctxt); + } } } diff --git a/jdk/test/javax/script/Test5.js b/jdk/test/javax/script/Test5.js index c607cbc8604..708b482d00c 100644 --- a/jdk/test/javax/script/Test5.js +++ b/jdk/test/javax/script/Test5.js @@ -1,6 +1,5 @@ -var key; -var count; +var ScriptContext = javax.script.ScriptContext; print(count); switch (count) { @@ -9,7 +8,7 @@ switch (count) { if (key != 'value in engine') { throw "unexpected engine scope value"; } - if (context.getAttribute("key", context.GLOBAL_SCOPE ) != null) { + if (context.getAttribute("key", ScriptContext.GLOBAL_SCOPE ) != null) { throw "unexpected global scope value"; } break; @@ -19,7 +18,7 @@ switch (count) { if (key != 'value in engine') { throw "unexpected engine scope value"; } - if (context.getAttribute("key", context.GLOBAL_SCOPE ) != + if (context.getAttribute("key", ScriptContext.GLOBAL_SCOPE ) != "value in global") { throw "unexpected global scope value"; } @@ -30,7 +29,7 @@ switch (count) { if (key != 'value in global') { throw "unexpected global scope value"; } - if (context.getAttribute("key", context.GLOBAL_SCOPE ) != + if (context.getAttribute("key", ScriptContext.GLOBAL_SCOPE ) != "value in global") { throw "unexpected global scope value"; } diff --git a/jdk/test/javax/script/Test6.java b/jdk/test/javax/script/Test6.java index 82758879fdb..5582b0a9025 100644 --- a/jdk/test/javax/script/Test6.java +++ b/jdk/test/javax/script/Test6.java @@ -40,11 +40,23 @@ public class Test6 { System.out.println("Warning: No js engine found; test vacuously passes."); return; } - Reader reader = new FileReader( - new File(System.getProperty("test.src", "."), "Test6.js")); - engine.eval(reader); + + try (Reader reader = new FileReader( + new File(System.getProperty("test.src", "."), "Test6.js"))) { + engine.eval(reader); + } Object res = engine.get("res"); - CompiledScript scr = ((Compilable)engine).compile(reader); + + CompiledScript scr = null; + try (Reader reader = new FileReader( + new File(System.getProperty("test.src", "."), "Test6.js"))) { + scr = ((Compilable)engine).compile(reader); + } + + if (scr == null) { + throw new RuntimeException("compilation failed!"); + } + scr.eval(); Object res1 = engine.get("res"); if (! res.equals(res1)) { diff --git a/jdk/test/javax/script/Test7.js b/jdk/test/javax/script/Test7.js index b1ec2a8fd9f..d79db96067d 100644 --- a/jdk/test/javax/script/Test7.js +++ b/jdk/test/javax/script/Test7.js @@ -1,9 +1,14 @@ //this is the first line of Test7.js var filename; +try { + load("nashorn:mozilla_compat.js"); +} catch (e) { + //ignored +} importPackage(java.io); importPackage(java); var f = new File(filename); var r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); -var firstLine = r.readLine() + ''; +var firstLine = r.readLine(); print(firstLine); diff --git a/jdk/test/javax/script/UnescapedBracketRegExTest.java b/jdk/test/javax/script/UnescapedBracketRegExTest.java index f2a807065f7..472ae107ed9 100644 --- a/jdk/test/javax/script/UnescapedBracketRegExTest.java +++ b/jdk/test/javax/script/UnescapedBracketRegExTest.java @@ -24,7 +24,7 @@ /* * @test * @bug 7012701 - * @summary 7012701 Add a test to check that Rhino's RegExp parser accepts unescaped '[' + * @summary 7012701 Add a test to check that RegExp parser accepts unescaped '[' */ import javax.script.*; @@ -33,9 +33,9 @@ import java.io.*; public class UnescapedBracketRegExTest { public static void main(String[] args) throws ScriptException { ScriptEngineManager sem = new ScriptEngineManager(); - ScriptEngine engine = sem.getEngineByName("js"); + ScriptEngine engine = sem.getEngineByName("nashorn"); if (engine == null) { - System.out.println("Warning: No js engine found; test vacuously passes."); + System.out.println("Warning: No nashorn engine found; test vacuously passes."); return; } // the following throws exception diff --git a/jdk/test/javax/script/VersionTest.java b/jdk/test/javax/script/VersionTest.java index 374f43be51c..87fa8bcfa51 100644 --- a/jdk/test/javax/script/VersionTest.java +++ b/jdk/test/javax/script/VersionTest.java @@ -31,9 +31,7 @@ import javax.script.*; import java.io.*; public class VersionTest { - - private static final String JS_LANG_VERSION = "1.8"; - private static final String JS_ENGINE_VERSION = "1.7 release 3 PRERELEASE"; + private static final String JS_LANG_VERSION = "ECMA - 262 Edition 5.1"; public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); @@ -48,9 +46,18 @@ public class VersionTest { JS_LANG_VERSION); } String engineVersion = jsengine.getFactory().getEngineVersion(); - if (! engineVersion.equals(JS_ENGINE_VERSION)) { - throw new RuntimeException("Expected Rhino version is " + - JS_ENGINE_VERSION); + String expectedVersion = getNashornVersion(); + if (! engineVersion.equals(expectedVersion)) { + throw new RuntimeException("Expected version is " + expectedVersion); + } + } + + private static String getNashornVersion() { + try { + Class versionClass = Class.forName("jdk.nashorn.internal.runtime.Version"); + return (String) versionClass.getMethod("version").invoke(null); + } catch (Exception e) { + return "Version Unknown!"; } } }