dyn:callMethod and varargs
Attila Szegedi
attila.szegedi at oracle.com
Mon Mar 18 00:29:03 PDT 2013
On Mar 14, 2013, at 3:39 PM, Peter Zhelezniakov <Peter.Zhelezniakov at oracle.com> wrote:
> 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.
Yeah, this is a known issue; Nashorn also internally uses JSObject for certain purposes, so Nashorn actually has an internal linker for JSObject objects. Myself, Per Bothner, and Sundar have been having discussions on how to reconcile the problems around this issue, with no definite solution yet (as far as I can remember - need to look up the e-mail threads… maybe Per or Sundar's immediate memory serves better)
Attila.
>
> Thanks!
> --
> Peter | x33066 | St Petersburg, Russia | timezone: GMT+04
More information about the nashorn-dev
mailing list