test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
Print this page
*** 521,530 ****
--- 521,542 ----
}
assertEquals(sw.toString(), println("34 true hello"));
}
+ @Test
+ public void scriptObjectAutoConversionTest() throws ScriptException {
+ final ScriptEngineManager m = new ScriptEngineManager();
+ final ScriptEngine e = m.getEngineByName("nashorn");
+ e.eval("obj = { foo: 'hello' }");
+ e.put("Window", e.eval("Packages.jdk.nashorn.api.scripting.Window"));
+ assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
+ assertEquals(e.eval("Window.funcScriptObjectMirror(obj)"), "hello");
+ assertEquals(e.eval("Window.funcMap(obj)"), "hello");
+ assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
+ }
+
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
// Returns String that would be the result of calling PrintWriter.println
// of the given String. (This is to handle platform specific newline).
private static String println(final String str) {