I am trying to invoke a javascript closure from Java using ScriptEngine. See below the code snippet. I removed the script engine eval code for brevity.I was able to invoke the function which has a closure but not the closure, any help is appreciated
//Java code snippet
ScriptObjectMirror execute = (ScriptObjectMirror) engine.get("transform");
ScriptObjectMirror closure = (ScriptObjectMirror) execute.callMember("execute", new TestObj());
for (String s: closure.getOwnKeys(true)) {
System.out.println(s);
}
//Javascript code
var transform = {
execute : function(execution) {
print("hello");execution.setVariable("test","testing");
function transform(execution) {
execution.setVariable("result", {result:"myjson object"});
print("Testing");
}
return transform;
}
}
hello
name:test,testing
prototype
length
name