How to know if script is being run within Nashorn
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Tue Sep 16 14:47:12 UTC 2014
If you are using javax.script API to run your scripts with nashorn, you
can for "engine" variable. This is of type javax.script.ScriptEngine.
Something like...
if (typeof engine != 'undefined' ) {
// perhaps further check for engine instanceof javax.script.ScriptEngine
....
}
-Sundar
On Tuesday 16 September 2014 08:06 PM, Alex Soto wrote:
> Hi,
> I hava a Javascript file and I want to detect who is running it. Let me
> explain:
>
> The problem is that I want that if this script is run in browser use the IO
> streaming API to load content from url, if it is running within node.js it
> uses the node.js libraries to read content, and if it is in Nashorn, use
> the Java Input stream classes. I have a way to know if the script is run
> within a browser or inside Node.js. But I have not found any way to know if
> script is running inside Nashorn.
>
> Is there a function that I can call that will return for example some
> information about Nashorn that obviously if the script is run outside will
> return undefined?
>
> I have thought about using a directly a Java class and if it returns
> correctly then I know that is Nashorn, but I would like to know if there is
> something more specific of Nashorn.
>
> Thank you so much for your time and help.
>
> Alex.
>
>
More information about the nashorn-dev
mailing list