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

Vivin Suresh Paliath vivin.paliath at
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
<>) 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 <>) as
well and it also seemed to fix the issue without causing any tests to fail.


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.

":13:02:11:01:02:11:01:12:02";map{print chr unpack"

More information about the nashorn-dev mailing list