Pessoal, estou testando o Rhino baseado nos exemplos lá do mozilla. Mas estou emperrado a partir do segundo exemplo, que trata da execução de funções. O códido é o seguinte:
public static void main(String args[])
{
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
// Collect the arguments into a single string.
String s = "";
for (int i=0; i < args.length; i++) {
s += args[i];
}
// Now evaluate the string we've colected. We'll ignore the result.
cx.evaluateString(scope, s, "<cmd>", 1, null);
// Print the value of variable "x"
Object x = scope.get("x", scope);
if (x == Scriptable.NOT_FOUND) {
System.out.println("x is not defined.");
} else {
System.out.println("x = " + Context.toString(x));
}
// Call function "f('my arg')" and print its result.
Object fObj = scope.get("f", scope);
if (!(fObj instanceof Function)) {
System.out.println("f is undefined or not a function.");
} else {
Object functionArgs[] = { "my arg" };
Function f = (Function)fObj;
Object result = f.call(cx, scope, scope, functionArgs);
String report = "f('my args') = " + Context.toString(result);
System.out.println(report);
}
} finally {
Context.exit();
}
}
E recebo a exception:
[code]
Exception in thread "main" org.mozilla.javascript.EvaluatorException: missing ; before statement (<cmd>#1)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)
at org.mozilla.javascript.Parser.addError(Parser.java:146)
at org.mozilla.javascript.Parser.reportError(Parser.java:160)
at org.mozilla.javascript.Parser.statementHelper(Parser.java:1265)
at org.mozilla.javascript.Parser.statement(Parser.java:708)
at org.mozilla.javascript.Parser.parse(Parser.java:401)
at org.mozilla.javascript.Parser.parse(Parser.java:338)
at org.mozilla.javascript.Context.compileImpl(Context.java:2252)
at org.mozilla.javascript.Context.compileString(Context.java:1240)
at org.mozilla.javascript.Context.compileString(Context.java:1229)
at org.mozilla.javascript.Context.evaluateString(Context.java:1085)
at RunScript3.main(RunScript3.java:62)
[/code]
Alguem sabe o que pode ser? Vou dar uma olhada na documentação do metodo para saber o que é esse <cmd>
Valeu!
Alberto