-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b53
-
generic
-
generic
In the following test, a JavaScript function is called from Java program.
import javax.script.*;
public class Test {
public static void main(String[] argv) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
// function expects a java.io.File object.
engine.eval(
"function func(obj) { " +
" if (!(obj instanceof java.io.File)) { " +
" throw 'file expected'; " +
" } else { " +
" print('got : ' + obj); " +
" } " +
"} ");
Invocable in = (Invocable) engine;
// call the func by passing a java.io.File object
// we don't expect exception because we are passing right
// type of object as argument...
in.invoke("func", new Object[] { new java.io.File(".") });
}
}
We don't expect any exception in the above program. But, we get exception with the following trace:
Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: file expected (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:204)
at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:156)
at Test.main(Test.java:20)
It seems that the arguments passed to script function are not converted to correct script wrapper objects.
import javax.script.*;
public class Test {
public static void main(String[] argv) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
// function expects a java.io.File object.
engine.eval(
"function func(obj) { " +
" if (!(obj instanceof java.io.File)) { " +
" throw 'file expected'; " +
" } else { " +
" print('got : ' + obj); " +
" } " +
"} ");
Invocable in = (Invocable) engine;
// call the func by passing a java.io.File object
// we don't expect exception because we are passing right
// type of object as argument...
in.invoke("func", new Object[] { new java.io.File(".") });
}
}
We don't expect any exception in the above program. But, we get exception with the following trace:
Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: file expected (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:204)
at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:156)
at Test.main(Test.java:20)
It seems that the arguments passed to script function are not converted to correct script wrapper objects.