Package delight.rhinosandox.internal
Class RhinoSandboxImpl
- java.lang.Object
-
- delight.rhinosandox.internal.RhinoSandboxImpl
-
- All Implemented Interfaces:
RhinoSandbox
public class RhinoSandboxImpl extends java.lang.Object implements RhinoSandbox
-
-
Constructor Summary
Constructors Constructor Description RhinoSandboxImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RhinoSandboxallow(java.lang.Class<?> clazz)Will allow access to this class in Rhino scripts.voidassertContextFactory()see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_ContextsvoidassertSafeScope(org.mozilla.javascript.Context context)java.lang.ObjectcallFunction(org.mozilla.javascript.NativeFunction function, java.lang.Object[] args)executes a javascript functionjava.lang.Objecteval(java.lang.String sourceName, java.io.Reader js)Evaluate a script with its own scope.java.lang.Objecteval(java.lang.String sourceName, java.io.Reader js, java.util.Map<java.lang.String,java.lang.Object> variables)Evaluate a script with its own scope.java.lang.Objecteval(java.lang.String sourceName, java.lang.String js)Evaluate a script with its own scope.java.lang.Objecteval(java.lang.String sourceName, java.lang.String js, java.util.Map<java.lang.String,java.lang.Object> variables)Evaluate a script with its own scope.java.lang.ObjectevalWithGlobalScope(java.lang.String sourceName, java.io.Reader js)Evaluate the given script with the global scope.java.lang.ObjectevalWithGlobalScope(java.lang.String sourceName, java.lang.String js)Evaluate the given script with the global scope.RhinoSandboxinject(java.lang.Class<org.mozilla.javascript.ScriptableObject> clazz)Will make this class available to instantiate in Rhino scripts.RhinoSandboxinject(java.lang.String variableName, java.lang.Object object)Will add a global variable available to all scripts executed with this sandbox.RhinoSandboxsetInstructionLimit(int limit)Sets the maximum instructions allowed for script execution.RhinoSandboxsetMaxDuration(int limitInMs)Sets the maximum allowed duration for scripts.RhinoSandboxsetUseSafeStandardObjects(boolean useSafeStandardObjects)If .initSafeStandardObjects should be used.RhinoSandboxsetUseSealedScope(boolean value)If the global scope should be sealed (default: true).
-
-
-
Method Detail
-
assertContextFactory
public void assertContextFactory()
see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_Contexts
-
assertSafeScope
public void assertSafeScope(org.mozilla.javascript.Context context)
-
evalWithGlobalScope
public java.lang.Object evalWithGlobalScope(java.lang.String sourceName, java.lang.String js)Description copied from interface:RhinoSandboxEvaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.- Specified by:
evalWithGlobalScopein interfaceRhinoSandbox
-
evalWithGlobalScope
public java.lang.Object evalWithGlobalScope(java.lang.String sourceName, java.io.Reader js) throws java.io.IOExceptionDescription copied from interface:RhinoSandboxEvaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.- Specified by:
evalWithGlobalScopein interfaceRhinoSandbox- Throws:
java.io.IOException
-
eval
public java.lang.Object eval(java.lang.String sourceName, java.lang.String js, java.util.Map<java.lang.String,java.lang.Object> variables)Description copied from interface:RhinoSandboxEvaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
variablesdefines variables with Java objects which will be available for the execution of this script.- Specified by:
evalin interfaceRhinoSandbox
-
eval
public java.lang.Object eval(java.lang.String sourceName, java.io.Reader js, java.util.Map<java.lang.String,java.lang.Object> variables) throws java.io.IOExceptionDescription copied from interface:RhinoSandboxEvaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
variablesdefines variables with Java objects which will be available for the execution of this script.- Specified by:
evalin interfaceRhinoSandbox- Throws:
java.io.IOException
-
eval
public java.lang.Object eval(java.lang.String sourceName, java.lang.String js)Description copied from interface:RhinoSandboxEvaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.- Specified by:
evalin interfaceRhinoSandbox
-
callFunction
public java.lang.Object callFunction(org.mozilla.javascript.NativeFunction function, java.lang.Object[] args)Description copied from interface:RhinoSandboxexecutes a javascript function- Specified by:
callFunctionin interfaceRhinoSandbox- Parameters:
function- a Native function you may got from jsargs- parameters you need to call the function- Returns:
- the result of the javascript function
-
eval
public java.lang.Object eval(java.lang.String sourceName, java.io.Reader js) throws java.io.IOExceptionDescription copied from interface:RhinoSandboxEvaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.- Specified by:
evalin interfaceRhinoSandbox- Throws:
java.io.IOException
-
setInstructionLimit
public RhinoSandbox setInstructionLimit(int limit)
Description copied from interface:RhinoSandboxSets the maximum instructions allowed for script execution.- Specified by:
setInstructionLimitin interfaceRhinoSandbox
-
setMaxDuration
public RhinoSandbox setMaxDuration(int limitInMs)
Sets the maximum allowed duration for scripts.- Specified by:
setMaxDurationin interfaceRhinoSandbox
-
setUseSafeStandardObjects
public RhinoSandbox setUseSafeStandardObjects(boolean useSafeStandardObjects)
Description copied from interface:RhinoSandboxIf .initSafeStandardObjects should be used.- Specified by:
setUseSafeStandardObjectsin interfaceRhinoSandbox
-
allow
public RhinoSandbox allow(java.lang.Class<?> clazz)
Description copied from interface:RhinoSandboxWill allow access to this class in Rhino scripts.
Note that for classes in packages which don't start with java., com., net. etc. the class name needs to be prefixed with Packages.
e.g. mypackage.Myclass will be Packages.mypackage.MyClass
- Specified by:
allowin interfaceRhinoSandbox
-
inject
public RhinoSandbox inject(java.lang.Class<org.mozilla.javascript.ScriptableObject> clazz)
Description copied from interface:RhinoSandboxWill make this class available to instantiate in Rhino scripts.- Specified by:
injectin interfaceRhinoSandbox
-
inject
public RhinoSandbox inject(java.lang.String variableName, java.lang.Object object)
Description copied from interface:RhinoSandboxWill add a global variable available to all scripts executed with this sandbox.- Specified by:
injectin interfaceRhinoSandbox
-
setUseSealedScope
public RhinoSandbox setUseSealedScope(boolean value)
Description copied from interface:RhinoSandboxIf the global scope should be sealed (default: true).- Specified by:
setUseSealedScopein interfaceRhinoSandbox
-
-