Package ca.phon.script
Class PhonScriptContext
java.lang.Object
ca.phon.script.PhonScriptContext
- Direct Known Subclasses:
QueryScriptContext
Handles setting up script context, scope and
evaluation scripts.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncallFunction
(org.mozilla.javascript.Scriptable scope, String name, Object... args) Call the specified function with the given arguments.org.mozilla.javascript.Scriptable
Create a basic Scriptable objectorg.mozilla.javascript.Scriptable
Setup scope for script with default imports included and therequire
function installed.org.mozilla.javascript.Context
enter()
Enter and return a new script context.static Object
Evaulate the given text and return the result (if any)exec
(org.mozilla.javascript.Scriptable scope) Evaluate script using given scopevoid
exit()
org.mozilla.javascript.Script
Return the compiled version of the script.567\l *org.mozilla.javascript.ContextFactory
org.mozilla.javascript.Scriptable
org.mozilla.javascript.Scriptable
getEvaluatedScope
(org.mozilla.javascript.Scriptable parentScope) Get the evaluated scope for the script.Get the phon script object associated with this contextgetScriptParameters
(org.mozilla.javascript.Scriptable scope) Get the parameters for the script.org.mozilla.javascript.WrapFactory
boolean
hasFunction
(org.mozilla.javascript.Scriptable scope, String name, int arity) Does the script have a function with the given name and arity.void
installParams
(org.mozilla.javascript.Scriptable scope) Install these script params into the given scopevoid
redirectStdErr
(PrintStream stream) void
redirectStdOut
(PrintStream stream) void
-
Field Details
-
SCRIPT_EXPORTS
- See Also:
-
-
Constructor Details
-
PhonScriptContext
-
-
Method Details
-
redirectStdOut
-
getStdOut
-
redirectStdErr
-
getStdErr
-
getContextFactory
public org.mozilla.javascript.ContextFactory getContextFactory() -
enter
public org.mozilla.javascript.Context enter()Enter and return a new script context. Every call to this method should have a matching call to {#linkexit()
-
exit
public void exit() -
eval
Evaulate the given text and return the result (if any)- Parameters:
script
-- Returns:
- the return value of the script. May be
null
- Throws:
PhonScriptException
-
createBasicScope
public org.mozilla.javascript.Scriptable createBasicScope()Create a basic Scriptable object- Returns:
- basic Scriptable
-
createImporterScope
Setup scope for script with default imports included and therequire
function installed.- Returns:
- the top-level scope for the script
- Throws:
PhonScriptException
-
hasFunction
Does the script have a function with the given name and arity.- Parameters:
name
-arity
-- Returns:
true
if a function with the given name and arity is found,false
otherwise
-
getEvaluatedScope
- Throws:
PhonScriptException
-
resetEvaulatedScope
public void resetEvaulatedScope() -
getEvaluatedScope
public org.mozilla.javascript.Scriptable getEvaluatedScope(org.mozilla.javascript.Scriptable parentScope) throws PhonScriptException Get the evaluated scope for the script. The evaluated scope is the Scriptable object resulting from evaulating the script. The evaluated scope is useful for working with functions defined in the scropt.- Parameters:
parentScope
- may benull
- Returns:
- the evaluated scope
- Throws:
PhonScriptException
-
getCompiledScript
Return the compiled version of the script.567\l *- Returns:
- compiled script
- Throws:
PhonScriptException
-
getPhonScript
Get the phon script object associated with this context- Returns:
- the PhonScript
-
getScriptParameters
public ScriptParameters getScriptParameters(org.mozilla.javascript.Scriptable scope) throws PhonScriptException Get the parameters for the script.- Parameters:
scope
-- Returns:
- script parameters
- Throws:
PhonScriptException
-
exec
Evaluate script using given scope- Parameters:
scope
-- Returns:
- result of executing the script or
null
if not applicable - Throws:
PhonScriptException
-
callFunction
public Object callFunction(org.mozilla.javascript.Scriptable scope, String name, Object... args) throws PhonScriptException Call the specified function with the given arguments.- Parameters:
scope
-args
-method
-- Returns:
- Throws:
PhonScriptException
-
getWrapFactory
public org.mozilla.javascript.WrapFactory getWrapFactory() -
installParams
Install these script params into the given scope- Parameters:
scope
-context
-- Throws:
PhonScriptException
-