How to know if script is being run within Nashorn

Alex Soto asotobu at gmail.com
Tue Sep 16 14:36:23 UTC 2014


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.


-- 
+----------------------------------------------------------+
  Alex Soto Bueno
  www.lordofthejars.com
+----------------------------------------------------------+


More information about the nashorn-dev mailing list