Dereferencing properties on foreign script objects creates a new ScriptObjectMirror instance each time, making direct comparisons difficult

Vivin Suresh Paliath vivin.paliath at gmail.com
Fri Dec 25 21:35:52 UTC 2015


I thought I would start a separate thread for this dedicated to discussing
possible fixes. The issue is the following "surprising" behavior when
dealing with foreign script-objects:

foreignObj === foreignObj; //true
foreignObj.prop === foreignObj.prop; //false

I took a quick stab at fixing this. My first approach is quite naive; I
just have a cyclic reference (see here
<https://gist.github.com/vivin/58f4e62f3926222f63cf>) from ScriptObject
back to its mirror. It does seem to fix the issue and none of the tests
seem to fail either. I initially used a weakref, but I'm not sure if that
would have bought me anything extra. The weakref would be GC'd when no
strong references are held on the mirror, but I think even without the
weakref, that would be the case. I admit I don't like the cyclic reference,
but are there any other drawbacks with the approach?

Another approach I tried was to use a WeakHashMap in Context. I tried that
approach (see here <https://gist.github.com/vivin/cfbb18f21935925555db>) as
well and it also seemed to fix the issue without causing any tests to fail.

Thanks!

Vivin
-- 
Ruin untold;
And thine own sadness,
Sing in the grass,
When eve has forgot, that no more hear common things that gleam and pass;
But seek alone to lip, sad Rose of love and ruin untold;
And thine own mother
Can know it as I know
More than another
What makes your own sadness,
Set in her eyes.

map{@n=split//;$j.=$n[0]x$n[1]}split/:/,"01:11:02".
":11:01:11:02:13:01:11:01:11:01:13:02:12:01:13:01".
":11:04:11:06:12:04:11:01:12:01:13:02:12:01:14:01".
":13:01:11:03:12:01:11:04:12:02:11:01:11:01:13:02".
":11:03:11:06:11:01:11:05:12:02:11:01:11:01:13:02".
":11:02:12:01:12:04:11:06:12:01:11:04:12:04:11:01".
":12:03:12:01:12:01:11:01:12:01:12:02:11:01:11:01".
":13:02:11:01:02:11:01:12:02";map{print chr unpack"
i",pack"B32",$_}$j=~m/.{8}/g


More information about the nashorn-dev mailing list