Rhino (driving Javascript)

Rhino is an engine JavaScript Open source. It is developed entirely in Java by the Fondation Mozilla (which provides also SpiderMonkey, an engine JavaScript writes in C).

Netscape began the Rhino project in 1997 at the beginning of the development of Javagator, a navigator in Java intended to supplant their already existing navigator, Netscape Navigator. Javagator was given up, but Rhino survived, and was even laid off by multiple companies, which financed the development of it. The Mozilla Foundation inherited Rhino in 1998, and returned it open source thereafter.

Technical description

Rhino can be used only, as interpreter, but also integrated in an application. In the same way, it is able to function in interpreted mode, just like in compiled mode.

Objects exposed by Rhino

Rhino provides in theory only the native objects defined by the specification of the language (examples: String, Date, etc). One will thus not find there the objects usually exposed by the JavaScript engines of the various navigators (examples: window, document, etc).

However, its Java implementation makes it possible a user to use all the Java objects available, as shows it the following code (extracted the Mozilla assistance):

js> F = new java.io. Spin (" test.txt") test.txt

Moreover, its use in mode Shell exposes a certain number of additional functionalities, which one can find on the site of Mozilla

Then, each application embarking Rhino can expose its own functionalities. For example, as a navigator Internet, Javagator would have exposed a complete DOM HTML to Rhino, allowing the handling of environment HTML via Javascript.

Lastly, version 6 of the API Java offers from now on a generic interface making it possible to implement any engine of script, and includes Rhino by defect.

Compiled mode & interpreted mode

Rhino is able to function in mode compiled (script is then compiled in bytecode Java, Rhino which can even generate binary .class and associate them with packages), and in mode interpreted (script is then compiled into object JavaScript).

In mode compiled , Rhino can compete in performances with SpiderMonkey, its big brother implemented in Language C, but it would be however victim of escapes of memory. In interpreted mode, the compilation of script is faster, and no escape of memory takes place, but of course, script is then slower.

Anecdotes

  • the animal of the cover of the JavaScript book of O' Reilly Media inspired the name Rhino.

  • Rhino would be, like Javagator, with the trap door, if he had not been forgotten by the executives of Netscape.
  • the bond Java/JavaScript becomes obvious with Rhino: the name JavaScript had been selected for reasons of marketing, Netscape and Sun Microsystems having collaborated much at that time. Then, Rhino was to become the engine JavaScript in new Javagator, the Java navigator of Netscape. After the cancellation of Javagator, Sun Microsystems was one of the companies having laid off Rhino, and it is finally Rhino which was included like language of script per defect in Java 6.

References