dyn:callMethod and varargs
Peter Zhelezniakov
Peter.Zhelezniakov at oracle.com
Thu Mar 14 07:39:08 PDT 2013
On 03/14/13 00:32, Attila Szegedi wrote:
> Dynalink doesn't support that for arbitrary Java methods, only if the Java method on the receiving end is itself variable arity. Basically, the static signature at the call site should be "similar" to the invoked method. This is actually a property of a linker - NashornLinker tipically allows any JS function to be invoked as vararg, and Dynalink's BeansLinker does not. A request for a vararg invoker has been articulated by others too - notably, Groovy would need it for their "splat" invocation. I'm thinking of introducing a separate operation "dyn:callVarArg" for this purpose. I don't want to rush a half-baked solution though so I'm gathering requirements for now.
>
> What'd be your use case? Out of curiosity, how are you using Dynalink?
I'm implementing browser-specific objects to be installed in Nashorn,
such as [window], [document] etc. My implementation classes all extend
JSObject, so I was basically implementing
JSObject.call(String methodName, Object... args)
to look something like (in pseudocode)
MethodHandle mh = lookup(this, methodName);
mh.invoke(this, args);
If I stop extending JSObject things apparently just work. The reason
seems that NashornLinker is used instead of JSObjectLinker. So much
depends on the linker indeed.
Thanks!
--
Peter | x33066 | St Petersburg, Russia | timezone: GMT+04
More information about the nashorn-dev
mailing list