Any way to support expando props on Java objects?
Mike Hearn
mike at plan99.net
Tue Mar 20 14:25:10 UTC 2018
Hi Sundar,
Thanks for the pointer. Dynalink does indeed look like the right tool,
albeit quite a lot of work for a small project. Maybe I'll experiment if I
have time. I wonder if you've looked at a way to integrate Dynalink with
Graal/Truffle as it seems they have quite similar concepts of a high level
object model with get/set "messages" etc. It'd be nice if the two
mechanisms were compatible.
"Expando" is Internet Explorer terminology for a natively implemented
object that has extra properties set on it from JS. I think to implement
expandos with this scheme, I'd need to write a custom linker that maintains
an IdentityHashMap<Object, HashMap<String, Object>> and then catches the
right exception in handling property sets from the next linker in the
chain. If the bean linker can't handle the set because there's no such
property, I'd insert the property into the hashmaps. I'd also check those
first before delegating to the bean linker when handling gets. That could
be quite some fancy method handle logic!
On Mon, Mar 19, 2018 at 23:52:44, Sundararajan Athijegannathan<
sundararajan.athijegannathan at oracle.com>wrote:
> Hi,
>
> Haven't gone through the referred code. Do you want to add more properties
> to a Java object apart from "bean properties" inferred?
>
> If so, you can write your own dynalink linker with jdk9.
>
> See also:
>
> API doc:
>
> https://docs.oracle.com/javase/9/docs/api/jdk.dynalink-summary.html
>
> Sample:
>
> http://hg.openjdk.java.net/jdk9/dev/nashorn/file/17cc754c8936/samples/
> dynalink/DOMLinkerExporter.java http://hg.openjdk.java.net/jdk9/dev/
> nashorn/file/17cc754c8936/samples/dynalink/dom_linker_gutenberg.js http://
> hg.openjdk.java.net/jdk9/dev/nashorn/file/17cc754c8936/samples/dynalink/
> dom_linker.js
>
> Hope this helps,
> -Sundar
>
> On 19/03/18, 7:50 PM, Mike Hearn wrote:
>
> Hello,
>
> Thanks for writing Nashorn, it's useful!
>
> I'm trying to run https://github.com/domchristie/turndown in Nashorn,
> using JSoup to provide a simple DOM, but have hit an issue because Turndown
> expects to be able to add its own properties to DOM objects. This is
> something browsers support but Nashorn doesn't. I do realise that Nashorn's
> approach is allowed by the specs, but I'm wondering if there's any way to
> hack things up such that the library can do what it wants. I can also just
> change the code, but I'm curious if there's a quick fix here.
>
>
More information about the nashorn-dev
mailing list