poking objects into context?

Michael Roberts mike at 7f.com
Thu Oct 24 19:49:08 PDT 2013


I had another couple of basic questions.

1) If my script is "pure" javascript provided by someone else, and I don't
want to interfere with the script by pre-pending some java objects into it,
what's the prescribed way for getting said objects into the execution
context.  I'm thinking about substitutes some commonly used browser objects
like console in the first case, but also potentially objects which enable
communication back into the wider environment I would be using the scripts
in.  Of course, I can declare references to said objects in the script, but
external insertion would I think be more elegant.

2) If I have a lot of instances of the same script running in different
places in my java environment, is there a way to (a) get the script from
one ScriptEngine and place the compiled form into another (thus avoiding
the overhead of a second compilation) or (b) create a secondary instance of
the same (I assume) ScriptObject which does not share state with the
original instance.

thanks in advance

M


More information about the nashorn-dev mailing list