Package org.ringojs.engine
Class ReloadableScript
- java.lang.Object
-
- org.ringojs.engine.ReloadableScript
-
public class ReloadableScript extends java.lang.Object
This class represents a JavaScript Resource.
-
-
Constructor Summary
Constructors Constructor Description ReloadableScript(Resource source, RhinoEngine engine)
Construct a Script from the given script resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addDependency(ReloadableScript script)
Register a script that this script depends on.protected java.lang.Object
compileScript(org.mozilla.javascript.Context cx)
Get a script from a single script file.boolean
equals(java.lang.Object obj)
Equal check delegates to source.java.lang.Object
evaluate(org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Context cx, RingoWorker worker)
Evaluate the script on a module scope and return the resultprotected long
getChecksum()
Get the checksum of the script.protected long
getNestedChecksum(java.util.Set<ReloadableScript> set)
Get the recursive checksum of this script as a dependency.java.lang.Object
getScript(org.mozilla.javascript.Context cx, RingoWorker worker)
Get the actual compiled script.Resource
getSource()
Get the script's source resource.int
hashCode()
Hash code delegates to source.protected org.mozilla.javascript.Scriptable
load(org.mozilla.javascript.Scriptable prototype, org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable module, RingoWorker worker)
Get a module scope loaded with this script
-
-
-
Constructor Detail
-
ReloadableScript
public ReloadableScript(Resource source, RhinoEngine engine)
Construct a Script from the given script resource.- Parameters:
source
- the JavaScript resource or repository containing the script.engine
- the rhino engine
-
-
Method Detail
-
getSource
public Resource getSource()
Get the script's source resource.- Returns:
- the script's source resource.
-
getScript
public java.lang.Object getScript(org.mozilla.javascript.Context cx, RingoWorker worker) throws org.mozilla.javascript.JavaScriptException, java.io.IOException
Get the actual compiled script.- Parameters:
cx
- the current Context- Returns:
- the compiled and up-to-date script
- Throws:
org.mozilla.javascript.JavaScriptException
- if an error occurred compiling the script codejava.io.IOException
- if an error occurred reading the script file
-
compileScript
protected java.lang.Object compileScript(org.mozilla.javascript.Context cx) throws org.mozilla.javascript.JavaScriptException, java.io.IOException
Get a script from a single script file.- Parameters:
cx
- the current Context- Returns:
- the compiled and up-to-date script
- Throws:
org.mozilla.javascript.JavaScriptException
- if an error occurred compiling the script codejava.io.IOException
- if an error occurred reading the script file
-
evaluate
public java.lang.Object evaluate(org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Context cx, RingoWorker worker) throws org.mozilla.javascript.JavaScriptException, java.io.IOException
Evaluate the script on a module scope and return the result- Parameters:
scope
- the scope to evaluate the script oncx
- the rhino context- Returns:
- the result of the evaluation
- Throws:
org.mozilla.javascript.JavaScriptException
- if an error occurred evaluating the script filejava.io.IOException
- if an error occurred reading the script file
-
load
protected org.mozilla.javascript.Scriptable load(org.mozilla.javascript.Scriptable prototype, org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable module, RingoWorker worker) throws org.mozilla.javascript.JavaScriptException, java.io.IOException
Get a module scope loaded with this script- Parameters:
prototype
- the prototype for the module, usually the shared top level scopecx
- the rhino contextmodule
- the preexisting module for this resource if availableworker
- the worker instance loading this module- Returns:
- a new module scope
- Throws:
org.mozilla.javascript.JavaScriptException
- if an error occurred evaluating the script filejava.io.IOException
- if an error occurred reading the script file
-
getChecksum
protected long getChecksum() throws java.io.IOException
Get the checksum of the script. This includes the transitive sum of loaded module checksums, as modules need to be re-evaluated even if just a dependency has been updated.- Returns:
- the evaluation checksum for this script
- Throws:
java.io.IOException
- source could not be checked because of an I/O error
-
getNestedChecksum
protected long getNestedChecksum(java.util.Set<ReloadableScript> set) throws java.io.IOException
Get the recursive checksum of this script as a dependency. Since the checksum field may not be up-to-date we directly get the checksum from the underlying resource.- Parameters:
set
- visited script set to prevent cyclic invokation- Returns:
- the nested checksum
- Throws:
java.io.IOException
- source could not be checked because of an I/O error
-
addDependency
protected void addDependency(ReloadableScript script)
Register a script that this script depends on. This means that the script has been loaded directly or indirectly from the top scope of this module. The purpose of this is to keep track of modules loaded indirectly by shared modules, as we wouldn't normally notice they have been updated. Scripts loaded __after__ a module has been loaded do not count as dependencies, as they will be checked again at runtime.- Parameters:
script
- a script we depend on
-
hashCode
public int hashCode()
Hash code delegates to source.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
equals
public boolean equals(java.lang.Object obj)
Equal check delegates to source.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare ourself to- Returns:
- true if it is a script with the same resource
-
-