## JavaScript: Rhino

Mozilla Rhino is a JavaScript interpreter implemented in Java. The script code is translated into byte code for the JVM which allows for the same optimizations as native Java code.

### JavaScript Compatibility

The Rhino runtime is provided as a separate plug-in and loaded by EASE. Depending on the installed version of the Rhino runtime, different levels of JavaScript support are available. By default we try to enable ECMAScript 6 support, which is not fully implemented in Rhino yet. Check out the compatibility table for details.
If not available EASE will gracefully fall back to JavaScript 1.8 support and finally drop to 1.7.

### Special language features

#### Built-in libraries

Rhino comes with some standard libraries:

- Array
- Number
- Math
- Date
- String
- RegExp
- JSON

#### String class ambiguity

JavaScript provides a String class that differs from the Java String class. As a script might have instances of both, this often leads to confusion. The variables drop-in in the Script Shell view shows the actual type by using different icons. `var javaScriptString = "I am a javaScript string"; var javaString = new java.lang.String("I am a Java string");`

To convert any string type to JavaScript use: `var javaScriptString = someString + "";`

To convert any string to Java use: `var javaString = new java.lang.String(someString);`

#### Java class interaction

Java classes on the classpath can directly be used when accessed with their full qualified name (eg. java.io.File). Typical top level package names will be detected automatically, eg com.*, org.*, java.*. In case your package is not detected as it may start with an unusual top level name, you may access it via the Packages.<full qualified name> syntax.

When accessing Java classes you always have to use full qualified class names. To simplify script code you may load classes or packages directly to the global namespace: `importClass(java.io.File); new File(...)` `importPackage(java.net); new ServerSocket(...)`