Package delight.rhinosandox.internal
Class RhinoSandboxImpl
java.lang.Object
delight.rhinosandox.internal.RhinoSandboxImpl
- All Implemented Interfaces:
RhinoSandbox
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SafeClassShutter
private SafeContext
private static final Object
private org.mozilla.javascript.ScriptableObject
private int
private long
private org.mozilla.javascript.ScriptableObject
private boolean
private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionWill allow access to this class in Rhino scripts.void
see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_Contextsvoid
assertSafeScope
(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 void
setInstructionLimit
(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:RhinoSandbox
Evaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.- Specified by:
evalWithGlobalScope
in interfaceRhinoSandbox
-
evalWithGlobalScope
Description copied from interface:RhinoSandbox
Evaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.- Specified by:
evalWithGlobalScope
in interfaceRhinoSandbox
- Throws:
IOException
-
eval
Description copied from interface:RhinoSandbox
Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
variables
defines variables with Java objects which will be available for the execution of this script.- Specified by:
eval
in interfaceRhinoSandbox
-
eval
Description copied from interface:RhinoSandbox
Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
variables
defines variables with Java objects which will be available for the execution of this script.- Specified by:
eval
in interfaceRhinoSandbox
- Throws:
IOException
-
eval
Description copied from interface:RhinoSandbox
Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.- Specified by:
eval
in interfaceRhinoSandbox
-
callFunction
Description copied from interface:RhinoSandbox
executes a javascript function- Specified by:
callFunction
in 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:RhinoSandbox
Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.- Specified by:
eval
in interfaceRhinoSandbox
- Throws:
IOException
-
setInstructionLimit
Description copied from interface:RhinoSandbox
Sets the maximum instructions allowed for script execution.- Specified by:
setInstructionLimit
in interfaceRhinoSandbox
-
setMaxDuration
Sets the maximum allowed duration for scripts.- Specified by:
setMaxDuration
in interfaceRhinoSandbox
-
setUseSafeStandardObjects
Description copied from interface:RhinoSandbox
If .initSafeStandardObjects should be used.- Specified by:
setUseSafeStandardObjects
in interfaceRhinoSandbox
-
allow
Description copied from interface:RhinoSandbox
Will 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:
allow
in interfaceRhinoSandbox
-
inject
Description copied from interface:RhinoSandbox
Will make this class available to instantiate in Rhino scripts.- Specified by:
inject
in interfaceRhinoSandbox
-
inject
Description copied from interface:RhinoSandbox
Will add a global variable available to all scripts executed with this sandbox.- Specified by:
inject
in interfaceRhinoSandbox
-
injectInt
-
setUseSealedScope
Description copied from interface:RhinoSandbox
If the global scope should be sealed (default: true).- Specified by:
setUseSealedScope
in interfaceRhinoSandbox
-