rhino vs spidermonkey

Tyler Gillies picture Tyler Gillies · Aug 25, 2010 · Viewed 11.9k times · Source

I noticed ubuntu 10.04 removed the spidermonkey package. Rhino looks like it's still there though. What are the differences between rhino and spidermonkey (besides what language they're written in). And why did they remove spidermonkey?

Answer

user257111 picture user257111 · Dec 12, 2010

I'm afraid the difference is the language they are written in, or what it means. People use C/C++ to write all manner of things (like Firefox) whereas Java is most prevalent in Application Servers. From http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29:

Rhino converts JavaScript scripts into Java classes. Rhino works in both compiled as well as interpreted mode. It is intended to be used in server-side applications, hence there is no built-in support for the browser objects that are commonly associated with JavaScript.

There are three important parts here. Firstly, there's no DOM (also true of SpiderMonkey). Secondly, server side is the intended usage. You're supposed to be able to use Rhino in your big enterprise-y application for automating stuff on a more ad-hoc basis. Finally, the Javascript becomes a class just like the rest of the Java class hierarchy and you can interact with Java classes (see the code sample on that page).

In short, you could quite easily manipulate your POJOs/JPA-based objects/Message Beans/whatever you want to call your "enterprise" Java class, all from within a javascript run through Rhino. Compare this to Jython, where you can use Python syntax and classes to interact with Java. Handy if you have some JavaScript/Python whizzes kicking around the office with nothing to do.

SpiderMonkey by contrast is more like LUA. It's a scripting language. What's the difference? Well, I doubt you get access to printf directly, for one. Rather than being able to access Java classes straight off, you don't get to access C/C++ classes straight off. Rather, you use C/C++ to program extra features of the language.

In short, Rhino allows JS to interact with your code. SpiderMonkey is more like a do-it-yourself compiler kit with the added advantage that a standard language a lot of people know has already been built and you just need to add your customisations to it.