mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-19 01:47:52 +00:00
8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
Reviewed-by: alanb
This commit is contained in:
parent
1caebc408d
commit
b7511e7609
@ -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);
|
||||
|
||||
@ -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 {
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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';
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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";
|
||||
}
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user