-
Bug
-
Resolution: Fixed
-
P4
-
7
-
b128
-
generic
-
generic
-
Verified
The following example throws stack trace:
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.StringWriter;
class ScriptTestJs
{
public static void main(String[] args)
{
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine jsengine = sem.getEngineByName("javascript");
StringWriter sw = new StringWriter();
try
{
jsengine.eval("print(\"hello world 1\\n\")");
jsengine.getContext().setWriter(sw);
jsengine.eval("print(\"hello world 2\\n\")");
}
catch(Throwable e)
{
e.printStackTrace();
}
}
};
java ScriptTestJs
hello world 1
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function print. (print#8) in print at line number 8
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at ScriptTestJs.main(ScriptTestJs.java:26)
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.StringWriter;
class ScriptTestJs
{
public static void main(String[] args)
{
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine jsengine = sem.getEngineByName("javascript");
StringWriter sw = new StringWriter();
try
{
jsengine.eval("print(\"hello world 1\\n\")");
jsengine.getContext().setWriter(sw);
jsengine.eval("print(\"hello world 2\\n\")");
}
catch(Throwable e)
{
e.printStackTrace();
}
}
};
java ScriptTestJs
hello world 1
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function print. (print#8) in print at line number 8
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at ScriptTestJs.main(ScriptTestJs.java:26)