提交 343e1974 编写于 作者: S sundar

8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine

Reviewed-by: alanb
上级 a0a23261
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
/* /*
* @test * @test
* @bug 6869617 * @bug 6869617
* @summary RhinoScriptEngine bug : ScriptException cause not set (with fix) * @summary ScriptEngine bug : ScriptException cause not set (with fix)
*/ */
import javax.script.*; import javax.script.*;
...@@ -33,12 +33,12 @@ import java.io.*; ...@@ -33,12 +33,12 @@ import java.io.*;
public class CauseExceptionTest { public class CauseExceptionTest {
public static void main(String[] args) throws ScriptException, NoSuchMethodException { public static void main(String[] args) throws ScriptException, NoSuchMethodException {
ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine engine = sem.getEngineByName("js"); ScriptEngine engine = sem.getEngineByName("nashorn");
if (engine == null) { if (engine == null) {
System.out.println("Warning: No js engine found; test vacuously passes."); System.out.println("Warning: No js engine found; test vacuously passes.");
return; 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; Invocable invocable = (Invocable) engine;
try { try {
invocable.invokeFunction("hello_world", (Object[])null); invocable.invokeFunction("hello_world", (Object[])null);
......
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
/* /*
* @test * @test
* @bug 6474943 6705893 * @bug 6474943 6705893
* @summary Test that Rhino exception messages are * @summary Test that script engine exception messages are
* available from ScriptException. * available from ScriptException.
*/ */
import java.io.*; import java.io.*;
import javax.script.*; import javax.script.*;
public class RhinoExceptionTest { public class ExceptionTest {
private static final String ERROR_MSG = "error from JavaScript"; private static final String ERROR_MSG = "error from JavaScript";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*/ */
/* /*
* @run ignore
* @test * @test
* @bug 6960211 * @bug 6960211
* @summary JavaScript engine allows creation of interface although methods not available. * @summary JavaScript engine allows creation of interface although methods not available.
...@@ -32,10 +33,10 @@ import javax.script.*; ...@@ -32,10 +33,10 @@ import javax.script.*;
public class GetInterfaceTest { public class GetInterfaceTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js"); ScriptEngine engine = manager.getEngineByName("nashorn");
if (engine == null) { 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; return;
} }
......
...@@ -24,13 +24,13 @@ import javax.script.*; ...@@ -24,13 +24,13 @@ import javax.script.*;
/** /**
* Helper class to consolidate testing requirements for a js engine. * 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 { public class Helper {
private Helper() {}; // Don't instantiate private Helper() {}; // Don't instantiate
public static ScriptEngine getJsEngine(ScriptEngineManager m) { public static ScriptEngine getJsEngine(ScriptEngineManager m) {
ScriptEngine e = m.getEngineByName("js"); ScriptEngine e = m.getEngineByName("nashorn");
if (e == null && if (e == null &&
System.getProperty("java.runtime.name").startsWith("Java(TM)")) { System.getProperty("java.runtime.name").startsWith("Java(TM)")) {
// A js engine is requied for Sun's product JDK // A js engine is requied for Sun's product JDK
......
...@@ -33,9 +33,9 @@ import java.io.*; ...@@ -33,9 +33,9 @@ import java.io.*;
public class StringWriterPrintTest { public class StringWriterPrintTest {
public static void main(String[] args) throws ScriptException { public static void main(String[] args) throws ScriptException {
ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine engine = sem.getEngineByName("js"); ScriptEngine engine = sem.getEngineByName("nashorn");
if (engine == null) { 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; return;
} }
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
......
var ScriptContext = javax.script.ScriptContext;
if (key == undefined || key != 'engine value') { if (key == undefined || key != 'engine value') {
throw "unexpected engine scope value"; throw "unexpected engine scope value";
} }
// pre-defined context variable refers to current ScriptContext // 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"; throw "unexpected global scope value";
} }
// change the engine scope value // change the engine scope value
key = 'new engine 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"; throw "global scope should not change here";
} }
// delete engine scope value // delete engine scope value
delete key; delete key;
if (key == undefined && key != 'xglobal value') { if (key == undefined && key != 'global value') {
throw 'global scope should be visible after engine scope removal'; throw 'global scope should be visible after engine scope removal';
} }
...@@ -48,16 +48,24 @@ public class Test5 { ...@@ -48,16 +48,24 @@ public class Test5 {
System.out.println("engine scope only"); System.out.println("engine scope only");
e.put("count", new Integer(1)); e.put("count", new Integer(1));
Reader reader = new FileReader( try (Reader reader = new FileReader(
new File(System.getProperty("test.src", "."), "Test5.js")); new File(System.getProperty("test.src", "."), "Test5.js"))) {
engine.eval(reader,ctxt); engine.eval(reader,ctxt);
}
System.out.println("both scopes"); System.out.println("both scopes");
ctxt.setBindings(g, ScriptContext.GLOBAL_SCOPE); ctxt.setBindings(g, ScriptContext.GLOBAL_SCOPE);
e.put("count", new Integer(2)); 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"); System.out.println("only global");
e.put("count", new Integer(3)); e.put("count", new Integer(3));
ctxt.setAttribute("key", null, ScriptContext.ENGINE_SCOPE); ctxt.removeAttribute("key", ScriptContext.ENGINE_SCOPE);
engine.eval(reader,ctxt); try (Reader reader = new FileReader(
new File(System.getProperty("test.src", "."), "Test5.js"))) {
engine.eval(reader,ctxt);
}
} }
} }
var key;
var count;
var ScriptContext = javax.script.ScriptContext;
print(count); print(count);
switch (count) { switch (count) {
...@@ -9,7 +8,7 @@ switch (count) { ...@@ -9,7 +8,7 @@ switch (count) {
if (key != 'value in engine') { if (key != 'value in engine') {
throw "unexpected engine scope value"; 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"; throw "unexpected global scope value";
} }
break; break;
...@@ -19,7 +18,7 @@ switch (count) { ...@@ -19,7 +18,7 @@ switch (count) {
if (key != 'value in engine') { if (key != 'value in engine') {
throw "unexpected engine scope value"; throw "unexpected engine scope value";
} }
if (context.getAttribute("key", context.GLOBAL_SCOPE ) != if (context.getAttribute("key", ScriptContext.GLOBAL_SCOPE ) !=
"value in global") { "value in global") {
throw "unexpected global scope value"; throw "unexpected global scope value";
} }
...@@ -30,7 +29,7 @@ switch (count) { ...@@ -30,7 +29,7 @@ switch (count) {
if (key != 'value in global') { if (key != 'value in global') {
throw "unexpected global scope value"; throw "unexpected global scope value";
} }
if (context.getAttribute("key", context.GLOBAL_SCOPE ) != if (context.getAttribute("key", ScriptContext.GLOBAL_SCOPE ) !=
"value in global") { "value in global") {
throw "unexpected global scope value"; throw "unexpected global scope value";
} }
......
...@@ -40,11 +40,23 @@ public class Test6 { ...@@ -40,11 +40,23 @@ public class Test6 {
System.out.println("Warning: No js engine found; test vacuously passes."); System.out.println("Warning: No js engine found; test vacuously passes.");
return; return;
} }
Reader reader = new FileReader(
new File(System.getProperty("test.src", "."), "Test6.js")); try (Reader reader = new FileReader(
engine.eval(reader); new File(System.getProperty("test.src", "."), "Test6.js"))) {
engine.eval(reader);
}
Object res = engine.get("res"); 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(); scr.eval();
Object res1 = engine.get("res"); Object res1 = engine.get("res");
if (! res.equals(res1)) { if (! res.equals(res1)) {
......
//this is the first line of Test7.js //this is the first line of Test7.js
var filename; var filename;
try {
load("nashorn:mozilla_compat.js");
} catch (e) {
//ignored
}
importPackage(java.io); importPackage(java.io);
importPackage(java); importPackage(java);
var f = new File(filename); var f = new File(filename);
var r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); var r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
var firstLine = r.readLine() + ''; var firstLine = r.readLine();
print(firstLine); print(firstLine);
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
/* /*
* @test * @test
* @bug 7012701 * @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.*; import javax.script.*;
...@@ -33,9 +33,9 @@ import java.io.*; ...@@ -33,9 +33,9 @@ import java.io.*;
public class UnescapedBracketRegExTest { public class UnescapedBracketRegExTest {
public static void main(String[] args) throws ScriptException { public static void main(String[] args) throws ScriptException {
ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine engine = sem.getEngineByName("js"); ScriptEngine engine = sem.getEngineByName("nashorn");
if (engine == null) { 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; return;
} }
// the following throws exception // the following throws exception
......
...@@ -31,9 +31,7 @@ import javax.script.*; ...@@ -31,9 +31,7 @@ import javax.script.*;
import java.io.*; import java.io.*;
public class VersionTest { public class VersionTest {
private static final String JS_LANG_VERSION = "ECMA - 262 Edition 5.1";
private static final String JS_LANG_VERSION = "1.8";
private static final String JS_ENGINE_VERSION = "1.7 release 3 PRERELEASE";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngineManager manager = new ScriptEngineManager();
...@@ -48,9 +46,18 @@ public class VersionTest { ...@@ -48,9 +46,18 @@ public class VersionTest {
JS_LANG_VERSION); JS_LANG_VERSION);
} }
String engineVersion = jsengine.getFactory().getEngineVersion(); String engineVersion = jsengine.getFactory().getEngineVersion();
if (! engineVersion.equals(JS_ENGINE_VERSION)) { String expectedVersion = getNashornVersion();
throw new RuntimeException("Expected Rhino version is " + if (! engineVersion.equals(expectedVersion)) {
JS_ENGINE_VERSION); 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!";
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册