Module ringo/engine
Provides access to the Rhino JavaScript engine.
Functions
- addHostObject (javaClass)
- addRepository (repo)
- addShutdownHook (funcOrObject, sync)
- asJavaObject (object)
- asJavaString (object)
- createSandbox (modulePath, globals, options)
- getCurrentWorker (obj)
- getErrors ()
- getOptimizationLevel ()
- getRepositories ()
- getRhinoContext ()
- getRhinoEngine ()
- getRingoHome ()
- getWorker ()
- loadJars (location, recursive)
- setOptimizationLevel (level)
Properties
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 |
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:
|
Returns
RhinoEngine | a sandboxed RhinoEngine instance |
Throws
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.