3 ms·
This is very cool. You can basically even call all Java classes (and the other way around) from that JavaScript! (And reliably limit the classes that can be use
by Capt-RogerOver 9y ago
This is very cool. You can basically even call all Java classes (and the other way around) from that JavaScript! (And reliably limit the classes that can be used if you want to execute JS in a safe environment.) Why isn't this used more often? (Or is it used more often?)
- james-mcelwain 9y agoHere's a great testing library that leans heavily on Nashorn. https://github.com/intuit/karate https://github.com/intuit/karate. I find this a beautiful use of JavaScript in Java.
- cderwin 9y agoI can't speak to whether it is used more often, but I would bet the java-based Nashorn vm is significantly slower than the c++-based nodejs. In fact, a cursory google search shows this is the case, and it's not even close. See: http://blog.jonasbandi.net/2014/03/performance-nashorn-vs-node.html http://blog.jonasbandi.net/2014/03/performance-nashorn-vs-no... http://pieroxy.net/blog/2015/06/29/node_js_vs_java_nashorn.html http://pieroxy.net/blog/2015/06/29/node_js_vs_java_nashorn.h... (I can't speak to the quality of either of these tests, but the results seem decisive)
- Capt-RogerOver 9y agoWhile it is of course going to be slower, "it's not even close" is a judgement claim. The tests you have link talk about 1.6-2-3 times the difference. In a lot of applications the performance hit is going to be worth gaining access to the whole Java ecosystem of libraries. Also the performance is very likely to increase with newer versions.
- peoplewindow 9y agoNashorn isn't that slow, but there's another JS-on-the-JVM project called Graal.js which is about as fast as NodeJS/V8. One reason Nashorn isn't used that much is that it doesn't expose a node.js compatible API. JS people often want Node specifically, not just the ability to run JS. It has some cool features though. The shell mode is neat.