RingoJS

Module ringo/engine

Provides access to the Rhino JavaScript engine.


addHostObject (javaClass)

Define a class as Rhino host object.

Parameters

JavaClass javaClass

the class to define as host object


addRepository (repo)

Add a repository to the module search path

Parameters

Repository repo

a repository


addShutdownHook (funcOrObject, sync)

Register a callback to be invoked when the current RingoJS instance is terminated.

Parameters

Function|Object funcOrObject

Either a JavaScript function or a JavaScript object containing properties called module and name specifying a function exported by a RingoJS module.

Boolean sync

(optional) whether to invoke the callback synchronously (on the main shutdown thread) or asynchronously (on the worker's event loop thread)


asJavaObject (object)

Get a wrapper for an object that exposes it as Java object to JavaScript.

Parameters

Object object

an object

Returns

Object

the object wrapped as native java object


asJavaString (object)

Get a wrapper for a string that exposes the java.lang.String methods to JavaScript This is useful for accessing strings as java.lang.String without the cost of creating a new instance.

Parameters

Object object

an object

Returns

Object

the object converted to a string and wrapped as native java object


createSandbox (modulePath, globals, options)

Create a sandboxed scripting engine with the same install directory as this and the given module paths, global properties, class shutter and sealing

Parameters

Array modulePath

the comma separated module search path

Object globals

a map of predefined global properties (may be undefined)

Object options

an options object (may be undefined). The following options are supported:

  • systemModules array of system module directories to add to the module search path (may be relative to the ringo install dir)
  • classShutter a Rhino class shutter, may be null
  • sealed if the global object should be sealed, defaults to false

Returns

RhinoEngine

a sandboxed RhinoEngine instance

Throws

{FileNotFoundException} if any part of the module paths does not exist

getCurrentWorker (obj)

Get the worker instance associated with the current thread or the given scope or function object.

Parameters

Object obj

optional scope or function to get the worker from.

Returns

org.ringojs.engine.RingoWorker

the current worker


getErrors ()

Get a list containing the syntax errors encountered in the current worker.

Returns

ScriptableList

a list containing the errors encountered in the current worker


getOptimizationLevel ()

Get the Rhino optimization level for the current thread and context. The optimization level is an integer between -1 (interpreter mode) and 9 (compiled mode, all optimizations enabled). The default level is 0.

Returns

Number

level an integer between -1 and 9


getRepositories ()

Get the app's module search path as list of repositories.

Returns

ScriptableList

a list containing the module search path repositories


getRhinoContext ()

Get the org.mozilla.javascript.Context associated with the current thread.


getRhinoEngine ()

Get the org.ringojs.engine.RhinoEngine associated with this application.

Returns

org.ringojs.engine.RhinoEngine

the current RhinoEngine instance


getRingoHome ()

Get the RingoJS installation directory.

Returns

Repository

a Repository representing the Ringo installation directory


getWorker ()

Get a new worker instance.

Returns

org.ringojs.engine.RingoWorker

a new RingoWorker instance


loadJars (location, recursive)

Loads the given location and adds all resources with a *.jar suffix to the class path. If location is a string, it will be treated as repository path like getRepository(location). Otherwise, location must be a valid Ringo repository. By default, JAR resources inside the repository will be looked up recursively and subjacent JARs will be loaded.

Parameters

Repository|string location

a path or repository to lookup JAR resources.

boolean recursive

load JARs recursively, defaults to true


properties

An object reflecting the Java system properties.


setOptimizationLevel (level)

Set the Rhino optimization level for the current thread and context. The optimization level is an integer between -1 (interpreter mode) and 9 (compiled mode, all optimizations enabled). The default level is 0.

Parameters

Number level

an integer between -1 and 9


version

The RingoJS version as an array-like object with the major and minor version number as first and second element.