Invoke a function

54 views
Skip to first unread message

Sylfaen AvA

unread,
Feb 11, 2015, 5:03:11 AM2/11/15
to mozill...@googlegroups.com
Hello ! 

I have to implement the JS function setTimeout (and setInterval) and I have a problem with the first parameter of the function : the function to be called.

Here the code without the implementation of the timer:

public int jsFunction_setTimeout(Object function, int time){
       
final Scriptable scopee = this.js.getScope();

       
Context context = Context.enter();
       
//Object result = context.evaluateString(scopee, function, "<cmd>", 1, null);
       
//String value = Context.toString(result);
       
//System.out.println(value);
       
Context.exit();
}


When I enter :
window.setTimeout(function f(){console.log("hey");}, 10000)

, I have some functions which bring me to this function. 
The type of the var function is : 'org.mozilla.javascript.gen.c1@6537cf78'. How can I execute this variable with rhino ?
I have to execute a JS function in order to execute an another one but how Rhino can execute the second function ?

I tried to change the type of the var (String function) but it's not work because function f(){[...]} isn't a String.

Thanks in advance ! 

Greg Brail

unread,
Feb 26, 2015, 1:00:14 PM2/26/15
to mozill...@googlegroups.com
Did anyone ever help you with this?

The object that you get in this instance should implement the org.mozilla.javascript.Function interface. You can then call it by calling the "call" method.
Reply all
Reply to author
Forward
0 new messages