Using === across different contexts

Vivin Suresh Paliath vivin.paliath at
Mon Dec 21 22:49:02 UTC 2015

I ran into an issue where === returns false even when both should be
pointing to the same object. I'm assuming this is because one of the
objects is wrapped by a ScriptObjectMirror, because it was defined in a
different context.

Here's some code that demonstrates this:

        ScriptEngine engine = new
            new String[] { "-strict" }

        try {
            engine.eval("function Foo(src) { this.src = src }; var e = { x:
new Foo(\"what\") };");

            ScriptContext c = new SimpleScriptContext();


            System.out.println(engine.eval("var z = e.x; z === e.x;", c));
        } catch(Exception e) {
            throw new RuntimeException(e);

This prints out "false". Is there a way around this? I am also explicitly
copying over all the bindings from the parent scope into the new scope so
that I have access to "e". Could this be the source of the problem, and if
so, is there a better way to achieve what I'm trying to do?

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