Re: the ScriptingMojo

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: Kartik Ohri <kartikohri13(at)gmail(dot)com>
Cc: pljava-dev(at)lists(dot)postgresql(dot)org
Subject: Re: the ScriptingMojo
Date: 2020-08-22 21:55:09
Message-ID: 5F41943D.9080707@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

On 08/22/20 15:12, Kartik Ohri wrote:

> I really like this idea. But I am not sure how to work this out. The main
> point of contention is the class type of platforms["Linux"]. I tested with
> Nashorn and Graal and printed the class of the object in the constructor.
> For nashorn, it is jdk.nashorn.api.scripting.ScriptObjectMirror and for
> graal it is com.oracle.truffle.polyglot.PolyglotMap.

If I do the attached, it does what I was hoping for. The constructor prints

PGXS impl class is
jdk.nashorn.javaadapters.org_postgresql_pljava_pgxs_PGXSUtils$PGXS

in nashorn, or

PGXS impl class is org.postgresql.pljava.pgxs.PGXSUtils$PGXS$$JSJavaAdapter

in graal. (Wow, pretty sneaky, Graal fakes up a class that is even in
the superclass's package! I bet it's using MethodHandles.Lookup.defineClass,
which appeared in Java 9 so Nashorn probably doesn't.)

The new Foo(jsobject) syntax only has magic if Foo is an interface or an
abstract class. If Foo is an instantiable class, that will be parsed as
simply calling a one-argument constructor to instantiate it, and passing
the jsobject as the argument. Maybe that is what you were seeing?

You sort of have to believe with this stuff; ask too many questions and
you drive the magic away.

Regards,
-Chap

Attachment Content-Type Size
pgxs.pat image/x-coreldrawpattern 1021 bytes

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Kartik Ohri 2020-08-23 11:26:00 Re: the ScriptingMojo
Previous Message Chapman Flack 2020-08-22 20:45:13 Re: the ScriptingMojo