Package delight.rhinosandox.internal
Class RhinoSandboxImpl
java.lang.Object
delight.rhinosandox.internal.RhinoSandboxImpl
- All Implemented Interfaces:
RhinoSandbox
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SafeClassShutterprivate SafeContextprivate static final Objectprivate org.mozilla.javascript.ScriptableObjectprivate intprivate longprivate org.mozilla.javascript.ScriptableObjectprivate booleanprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionWill allow access to this class in Rhino scripts.voidsee https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_ContextsvoidassertSafeScope(org.mozilla.javascript.Context context) callFunction(org.mozilla.javascript.NativeFunction function, Object[] args) executes a javascript functionEvaluate a script with its own scope.Evaluate a script with its own scope.Evaluate a script with its own scope.Evaluate a script with its own scope.evalWithGlobalScope(String sourceName, Reader js) Evaluate the given script with the global scope.evalWithGlobalScope(String sourceName, String js) Evaluate the given script with the global scope.Will make this class available to instantiate in Rhino scripts.Will add a global variable available to all scripts executed with this sandbox.private voidsetInstructionLimit(int limit) Sets the maximum instructions allowed for script execution.setMaxDuration(int limitInMs) Sets the maximum allowed duration for scripts.setUseSafeStandardObjects(boolean useSafeStandardObjects) If .initSafeStandardObjects should be used.setUseSealedScope(boolean value) If the global scope should be sealed (default: true).
-
Field Details
-
contextFactory
-
globalScope
private org.mozilla.javascript.ScriptableObject globalScope -
safeScope
private org.mozilla.javascript.ScriptableObject safeScope -
instructionLimit
private int instructionLimit -
maxDuration
private long maxDuration -
useSafeStandardObjects
private boolean useSafeStandardObjects -
sealScope
private boolean sealScope -
inScope
-
classShutter
-
ctxFactoryLock
-
-
Constructor Details
-
RhinoSandboxImpl
public RhinoSandboxImpl()
-
-
Method Details
-
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
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
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- Throws:
IOException
-
eval
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
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- Throws:
IOException
-
eval
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
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
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- Throws:
IOException
-
setInstructionLimit
Description copied from interface:RhinoSandboxSets the maximum instructions allowed for script execution.- Specified by:
setInstructionLimitin interfaceRhinoSandbox
-
setMaxDuration
Sets the maximum allowed duration for scripts.- Specified by:
setMaxDurationin interfaceRhinoSandbox
-
setUseSafeStandardObjects
Description copied from interface:RhinoSandboxIf .initSafeStandardObjects should be used.- Specified by:
setUseSafeStandardObjectsin interfaceRhinoSandbox
-
allow
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
Description copied from interface:RhinoSandboxWill make this class available to instantiate in Rhino scripts.- Specified by:
injectin interfaceRhinoSandbox
-
inject
Description copied from interface:RhinoSandboxWill add a global variable available to all scripts executed with this sandbox.- Specified by:
injectin interfaceRhinoSandbox
-
injectInt
-
setUseSealedScope
Description copied from interface:RhinoSandboxIf the global scope should be sealed (default: true).- Specified by:
setUseSealedScopein interfaceRhinoSandbox
-