Ok, suppose that I have successfully inserted callback registering
Java object into Javascript scope and by using that I can register
callback functions using it's register( Object o )-method. When I call
something like following in Javascript....

callback.register( function(){ ... } );
// or
var f = function(){ ... };
callback.register( f );
// or
var tempObj = { f: function(){ ... } };
callback.register( tempObj.f );

...the register-function in Java gets runtime generated anonymous
object as a parameter, which happens to have call-method ( I confirmed
it using reflection ). I tried calling that using following
methods....

// Trying to cast it to FunctionObject and then call it...
FunctionObject fo = (FunctionObject)funcFromJS;
fo.call( ... );

// Trying to use it like object that implements Function-interface...
Function f = (Function)funcFromJS;
f.call( context, scope, thisObj, params );

// Trying to use it like object that implements Callable-interface...
Callable c = (Callable)funcFromJS;
c.call( ... );

// Using brute force reflection...
Object[] oa = new Object[0];// just do define empty argument list...
funcFromJS.getClass().getMethod
("call",Context.class,Scriptable.class,Scriptable.class,oa.getClass
()).invoke(funcFromJS, Context.enter(), (Scriptable)funcFromJS, null,
oa );

... and I can't believe that the last method ( reflection ) is the
only working solution for this. It is ugly as hell and you need
multiple catch-blocks to track errors it could produce...

Can anyone give me cleaner, faster and more secure way to do this?

- kunderez
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to