|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mozilla.javascript.Context
public class Context
This class represents the runtime context of an executing script.
Before executing a script, an instance of Context must be created
and associated with the thread that will be executing the script.
The Context will be used to store information about the executing
of the script such as the call stack. Contexts are associated with
the current thread using the call(ContextAction)
or enter() methods.
Different forms of script execution are supported. Scripts may be evaluated from the source directly, or first compiled and then later executed. Interactive execution is also supported.
Some aspects of script execution, such as type conversions and object creation, may be accessed directly through methods of Context.
Scriptable| Field Summary | |
|---|---|
static java.lang.Object[] |
emptyArgs
Convenient value to use as zero-length array of objects. |
static java.lang.String |
errorReporterProperty
|
static int |
FEATURE_DYNAMIC_SCOPE
Control if dynamic scope should be used for name access. |
static int |
FEATURE_E4X
Control if support for E4X(ECMAScript for XML) extension is available. |
static int |
FEATURE_ENHANCED_JAVA_ACCESS
Enables enhanced access to Java. |
static int |
FEATURE_LOCATION_INFORMATION_IN_ERROR
When the feature is on Rhino will add a "fileName" and "lineNumber" properties to Error objects automatically. |
static int |
FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
Control if member expression as function name extension is available. |
static int |
FEATURE_NON_ECMA_GET_YEAR
Controls behaviour of Date.prototype.getYear(). |
static int |
FEATURE_PARENT_PROTO_PROPERTIES
Control if properties __proto__ and __parent__ are treated specially. |
static int |
FEATURE_PARENT_PROTO_PROPRTIES
Deprecated. In previous releases, this name was given to FEATURE_PARENT_PROTO_PROPERTIES. |
static int |
FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
Control if reserved keywords are treated as identifiers. |
static int |
FEATURE_STRICT_EVAL
Control if strict eval mode is enabled. |
static int |
FEATURE_STRICT_MODE
Controls whether JS 1.5 'strict mode' is enabled. |
static int |
FEATURE_STRICT_VARS
Control if strict variable mode is enabled. |
static int |
FEATURE_TO_STRING_AS_SOURCE
Control if toString() should returns the same result as toSource() when applied to objects and arrays. |
static int |
FEATURE_WARNING_AS_ERROR
Controls whether a warning should be treated as an error. |
boolean |
generateObserverCount
|
static java.lang.String |
languageVersionProperty
|
static int |
VERSION_1_0
JavaScript 1.0 |
static int |
VERSION_1_1
JavaScript 1.1 |
static int |
VERSION_1_2
JavaScript 1.2 |
static int |
VERSION_1_3
JavaScript 1.3 |
static int |
VERSION_1_4
JavaScript 1.4 |
static int |
VERSION_1_5
JavaScript 1.5 |
static int |
VERSION_1_6
JavaScript 1.6 |
static int |
VERSION_1_7
JavaScript 1.7 |
static int |
VERSION_DEFAULT
The default version. |
static int |
VERSION_UNKNOWN
The unknown version. |
| Constructor Summary | |
|---|---|
Context()
Deprecated. use ContextFactory.enter() or
ContextFactory.call(ContextAction) instead. |
|
| Method Summary | |
|---|---|
void |
addActivationName(java.lang.String name)
Add a name to the list of names forcing the creation of real activation objects for functions. |
static void |
addContextListener(org.mozilla.javascript.ContextListener listener)
Deprecated. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Register an object to receive notifications when a bound property has changed |
static java.lang.Object |
call(ContextAction action)
Deprecated. use ContextFactory.call(ContextAction) instead as
this method relies on usage of a static singleton "global"
ContextFactory. |
static java.lang.Object |
call(ContextFactory factory,
Callable callable,
Scriptable scope,
Scriptable thisObj,
java.lang.Object[] args)
Call Callable.call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
using the Context instance associated with the current thread. |
static void |
checkLanguageVersion(int version)
|
static void |
checkOptimizationLevel(int optimizationLevel)
|
Function |
compileFunction(Scriptable scope,
java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Compile a JavaScript function. |
Script |
compileReader(java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Compiles the source in the given reader. |
Script |
compileReader(Scriptable scope,
java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Deprecated. |
Script |
compileString(java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Compiles the source in the given string. |
GeneratedClassLoader |
createClassLoader(java.lang.ClassLoader parent)
Create class loader for generated classes. |
java.lang.String |
decompileFunction(Function fun,
int indent)
Decompile a JavaScript Function. |
java.lang.String |
decompileFunctionBody(Function fun,
int indent)
Decompile the body of a JavaScript Function. |
java.lang.String |
decompileScript(Script script,
int indent)
Decompile the script. |
static Context |
enter()
Deprecated. use ContextFactory.enter() or
ContextFactory.call(ContextAction) instead as this method relies
on usage of a static singleton "global" ContextFactory. |
static Context |
enter(Context cx)
Deprecated. use ContextFactory.enterContext(Context) instead as
this method relies on usage of a static singleton "global" ContextFactory. |
java.lang.Object |
evaluateReader(Scriptable scope,
java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Evaluate a reader as JavaScript source. |
java.lang.Object |
evaluateString(Scriptable scope,
java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Evaluate a JavaScript source string. |
static void |
exit()
Exit a block of code requiring a Context. |
java.lang.ClassLoader |
getApplicationClassLoader()
|
static Context |
getCurrentContext()
Get the current Context. |
static DebuggableScript |
getDebuggableView(Script script)
Return DebuggableScript instance if any associated with the script. |
org.mozilla.javascript.debug.Debugger |
getDebugger()
Return the current debugger. |
java.lang.Object |
getDebuggerContextData()
Return the debugger context data associated with current context. |
org.mozilla.javascript.xml.XMLLib.Factory |
getE4xImplementationFactory()
Returns an object which specifies an E4X implementation to use within this Context. |
java.lang.Object[] |
getElements(Scriptable object)
Get the elements of a JavaScript array. |
ErrorReporter |
getErrorReporter()
Get the current error reporter. |
ContextFactory |
getFactory()
Return ContextFactory instance used to create this Context. |
java.lang.String |
getImplementationVersion()
Get the implementation version. |
int |
getInstructionObserverThreshold()
Get threshold of executed instructions counter that triggers call to observeInstructionCount(). |
int |
getLanguageVersion()
Get the current language version. |
java.util.Locale |
getLocale()
Get the current locale. |
int |
getMaximumInterpreterStackDepth()
Returns the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter. |
int |
getOptimizationLevel()
Get the current optimization level. |
java.lang.Object |
getThreadLocal(java.lang.Object key)
Get a value corresponding to a key. |
static java.lang.Object |
getUndefinedValue()
Get the singleton object that represents the JavaScript Undefined value. |
WrapFactory |
getWrapFactory()
Return the current WrapFactory, or null if none is defined. |
boolean |
hasCompileFunctionsWithDynamicScope()
Deprecated. |
boolean |
hasFeature(int featureIndex)
Controls certain aspects of script semantics. |
ScriptableObject |
initStandardObjects()
Initialize the standard objects. |
Scriptable |
initStandardObjects(ScriptableObject scope)
Initialize the standard objects. |
ScriptableObject |
initStandardObjects(ScriptableObject scope,
boolean sealed)
Initialize the standard objects. |
boolean |
isActivationNeeded(java.lang.String name)
Check whether the name is in the list of names of objects forcing the creation of activation objects. |
boolean |
isGeneratingDebug()
Tell whether debug information is being generated. |
boolean |
isGeneratingDebugChanged()
|
boolean |
isGeneratingSource()
Tell whether source information is being generated. |
boolean |
isSealed()
Checks if this is a sealed Context. |
static boolean |
isValidLanguageVersion(int version)
|
static boolean |
isValidOptimizationLevel(int optimizationLevel)
|
static java.lang.Object |
javaToJS(java.lang.Object value,
Scriptable scope)
Convenient method to convert java value to its closest representation in JavaScript. |
static java.lang.Object |
jsToJava(java.lang.Object value,
java.lang.Class desiredType)
Convert a JavaScript value into the desired type. |
Scriptable |
newArray(Scriptable scope,
int length)
Create an array with a specified initial length. |
Scriptable |
newArray(Scriptable scope,
java.lang.Object[] elements)
Create an array with a set of initial elements. |
Scriptable |
newObject(Scriptable scope)
Create a new JavaScript object. |
Scriptable |
newObject(Scriptable scope,
java.lang.String constructorName)
Create a new JavaScript object by executing the named constructor. |
Scriptable |
newObject(Scriptable scope,
java.lang.String constructorName,
java.lang.Object[] args)
Creates a new JavaScript object by executing the named constructor. |
protected void |
observeInstructionCount(int instructionCount)
Allow application to monitor counter of executed script instructions in Context subclasses. |
void |
putThreadLocal(java.lang.Object key,
java.lang.Object value)
Put a value that can later be retrieved using a given key. |
void |
removeActivationName(java.lang.String name)
Remove a name from the list of names forcing the creation of real activation objects for functions. |
static void |
removeContextListener(org.mozilla.javascript.ContextListener listener)
Deprecated. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove an object from the list of objects registered to receive notification of changes to a bounded property |
void |
removeThreadLocal(java.lang.Object key)
Remove values from thread-local storage. |
static void |
reportError(java.lang.String message)
Report an error using the error reporter for the current thread. |
static void |
reportError(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
Report an error using the error reporter for the current thread. |
static EvaluatorException |
reportRuntimeError(java.lang.String message)
Report a runtime error using the error reporter for the current thread. |
static EvaluatorException |
reportRuntimeError(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
Report a runtime error using the error reporter for the current thread. |
static void |
reportWarning(java.lang.String message)
Report a warning using the error reporter for the current thread. |
static void |
reportWarning(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
Report a warning using the error reporter for the current thread. |
static void |
reportWarning(java.lang.String message,
java.lang.Throwable t)
|
void |
seal(java.lang.Object sealKey)
Seal this Context object so any attempt to modify any of its properties including calling enter() and exit() methods will
throw an exception. |
void |
setApplicationClassLoader(java.lang.ClassLoader loader)
|
static void |
setCachingEnabled(boolean cachingEnabled)
Deprecated. |
void |
setClassShutter(ClassShutter shutter)
Set the LiveConnect access filter for this context. |
void |
setCompileFunctionsWithDynamicScope(boolean flag)
Deprecated. |
void |
setDebugger(org.mozilla.javascript.debug.Debugger debugger,
java.lang.Object contextData)
Set the associated debugger. |
ErrorReporter |
setErrorReporter(ErrorReporter reporter)
Change the current error reporter. |
void |
setGenerateObserverCount(boolean generateObserverCount)
Turn on or off generation of code with callbacks to track the count of executed instructions. |
void |
setGeneratingDebug(boolean generatingDebug)
Specify whether or not debug information should be generated. |
void |
setGeneratingSource(boolean generatingSource)
Specify whether or not source information should be generated. |
void |
setInstructionObserverThreshold(int threshold)
Set threshold of executed instructions counter that triggers call to observeInstructionCount(). |
void |
setLanguageVersion(int version)
Set the language version. |
java.util.Locale |
setLocale(java.util.Locale loc)
Set the current locale. |
void |
setMaximumInterpreterStackDepth(int max)
Sets the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter. |
void |
setOptimizationLevel(int optimizationLevel)
Set the current optimization level. |
void |
setSecurityController(SecurityController controller)
Set the security controller for this context. |
void |
setWrapFactory(WrapFactory wrapFactory)
Set a WrapFactory for this Context. |
boolean |
stringIsCompilableUnit(java.lang.String source)
Check whether a string is ready to be compiled. |
static java.lang.RuntimeException |
throwAsScriptRuntimeEx(java.lang.Throwable e)
Rethrow the exception wrapping it as the script runtime exception. |
static boolean |
toBoolean(java.lang.Object value)
Convert the value to a JavaScript boolean value. |
static double |
toNumber(java.lang.Object value)
Convert the value to a JavaScript Number value. |
static Scriptable |
toObject(java.lang.Object value,
Scriptable scope)
Convert the value to an JavaScript object value. |
static Scriptable |
toObject(java.lang.Object value,
Scriptable scope,
java.lang.Class staticType)
Deprecated. |
static java.lang.String |
toString(java.lang.Object value)
Convert the value to a JavaScript String value. |
static java.lang.Object |
toType(java.lang.Object value,
java.lang.Class desiredType)
Deprecated. |
void |
unseal(java.lang.Object sealKey)
Unseal previously sealed Context object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int VERSION_UNKNOWN
public static final int VERSION_DEFAULT
public static final int VERSION_1_0
public static final int VERSION_1_1
public static final int VERSION_1_2
public static final int VERSION_1_3
public static final int VERSION_1_4
public static final int VERSION_1_5
public static final int VERSION_1_6
public static final int VERSION_1_7
public static final int FEATURE_NON_ECMA_GET_YEAR
hasFeature(int) is always to subtruct
1900 as rquired by ECMAScript B.2.4.
public static final int FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
hasFeature(int) returns false.
public static final int FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
hasFeature(int) returns false.
public static final int FEATURE_TO_STRING_AS_SOURCE
Scriptable.getClassName()].
By default hasFeature(int) returns true only if
the current JS version is set to VERSION_1_2.
public static final int FEATURE_PARENT_PROTO_PROPERTIES
The properties allow to query and set scope and prototype chains for the
objects. The special meaning of the properties is available
only when they are used as the right hand side of the dot operator.
For example, while x.__proto__ = y changes the prototype
chain of the object x to point to y,
x["__proto__"] = y simply assigns a new value to the property
__proto__ in x even when the feature is on.
By default hasFeature(int) returns true.
public static final int FEATURE_PARENT_PROTO_PROPRTIES
public static final int FEATURE_E4X
By default hasFeature(int) returns true if
the current JS version is set to VERSION_DEFAULT
or is at least VERSION_1_6.
public static final int FEATURE_DYNAMIC_SCOPE
This is useful to define shared scope containing functions that can be called from scripts and functions using private scopes.
By default hasFeature(int) returns false.
public static final int FEATURE_STRICT_VARS
By default hasFeature(int) returns false.
public static final int FEATURE_STRICT_EVAL
By default hasFeature(int) returns false.
public static final int FEATURE_LOCATION_INFORMATION_IN_ERROR
By default hasFeature(int) returns false.
public static final int FEATURE_STRICT_MODE
By default hasFeature(int) returns false.
public static final int FEATURE_WARNING_AS_ERROR
public static final int FEATURE_ENHANCED_JAVA_ACCESS
Note that this feature should only be enabled for trusted scripts.
By default hasFeature(int) returns false.
public static final java.lang.String languageVersionProperty
public static final java.lang.String errorReporterProperty
public static final java.lang.Object[] emptyArgs
public boolean generateObserverCount
| Constructor Detail |
|---|
public Context()
ContextFactory.enter() or
ContextFactory.call(ContextAction) instead.
| Method Detail |
|---|
public static Context getCurrentContext()
ContextFactory.enterContext(),
ContextFactory.call(ContextAction)public static Context enter()
ContextFactory.enter() or
ContextFactory.call(ContextAction) instead as this method relies
on usage of a static singleton "global" ContextFactory.
ContextFactory.enterContext() on the global
ContextFactory instance.
getCurrentContext(),
exit(),
call(ContextAction)public static Context enter(Context cx)
ContextFactory.enterContext(Context) instead as
this method relies on usage of a static singleton "global" ContextFactory.
The same as enter() except that cx
is associated with the current thread and returned if
the current thread has no associated context and cx
is not associated with any other thread.
cx - a Context to associate with the thread if possible
ContextFactory.enterContext(Context),
ContextFactory.call(ContextAction)public static void exit()
exit() will remove the association between
the current thread and a Context if the prior call to
ContextFactory.enterContext() on this thread newly associated a
Context with this thread. Once the current thread no longer has an
associated Context, it cannot be used to execute JavaScript until it is
again associated with a Context.
ContextFactory.enterContext()public static java.lang.Object call(ContextAction action)
ContextFactory.call(ContextAction) instead as
this method relies on usage of a static singleton "global"
ContextFactory.
ContextAction.run(Context cx)
using the Context instance associated with the current thread.
If no Context is associated with the thread, then
ContextFactory.getGlobal().makeContext() will be called to
construct new Context instance. The instance will be temporary
associated with the thread during call to
ContextAction.run(Context).
ContextAction.run(Context).
public static java.lang.Object call(ContextFactory factory,
Callable callable,
Scriptable scope,
Scriptable thisObj,
java.lang.Object[] args)
Callable.call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
using the Context instance associated with the current thread.
If no Context is associated with the thread, then
ContextFactory.makeContext() will be called to construct
new Context instance. The instance will be temporary associated
with the thread during call to ContextAction.run(Context).
It is allowed but not advisable to use null for factory argument in which case the global static singleton ContextFactory instance will be used to create new context instances.
ContextFactory.call(ContextAction)public static void addContextListener(org.mozilla.javascript.ContextListener listener)
ContextFactory.addListener(ContextFactory.Listener),
ContextFactory.getGlobal()public static void removeContextListener(org.mozilla.javascript.ContextListener listener)
ContextFactory.removeListener(ContextFactory.Listener),
ContextFactory.getGlobal()public final ContextFactory getFactory()
ContextFactory instance used to create this Context.
public final boolean isSealed()
seal(Object sealKey)public final void seal(java.lang.Object sealKey)
enter() and exit() methods will
throw an exception.
If sealKey is not null, calling
unseal(Object sealKey) with the same key unseals
the object. If sealKey is null, unsealing is no longer possible.
isSealed(),
unseal(Object)public final void unseal(java.lang.Object sealKey)
seal(Object) or an exception will be thrown.
isSealed(),
seal(Object sealKey)public final int getLanguageVersion()
The language version number affects JavaScript semantics as detailed in the overview documentation.
public void setLanguageVersion(int version)
Setting the language version will affect functions and scripts compiled subsequently. See the overview documentation for version-specific behavior.
version - the version as specified by VERSION_1_0, VERSION_1_1, etc.public static boolean isValidLanguageVersion(int version)
public static void checkLanguageVersion(int version)
public final java.lang.String getImplementationVersion()
The implementation version is of the form
"name langVer release relNum date"
where name is the name of the product, langVer is
the language version, relNum is the release number, and
date is the release date for that specific
release in the form "yyyy mm dd".
public final ErrorReporter getErrorReporter()
ErrorReporterpublic final ErrorReporter setErrorReporter(ErrorReporter reporter)
ErrorReporterpublic final java.util.Locale getLocale()
Localepublic final java.util.Locale setLocale(java.util.Locale loc)
Localepublic final void addPropertyChangeListener(java.beans.PropertyChangeListener l)
l - the listenerPropertyChangeEvent,
removePropertyChangeListener(java.beans.PropertyChangeListener)public final void removePropertyChangeListener(java.beans.PropertyChangeListener l)
l - the listenerPropertyChangeEvent,
addPropertyChangeListener(java.beans.PropertyChangeListener)
public static void reportWarning(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
message - the warning message to reportsourceName - a string describing the source, such as a filenamelineno - the starting line numberlineSource - the text of the line (may be null)lineOffset - the offset into lineSource where problem was detectedErrorReporterpublic static void reportWarning(java.lang.String message)
message - the warning message to reportErrorReporter
public static void reportWarning(java.lang.String message,
java.lang.Throwable t)
public static void reportError(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
message - the error message to reportsourceName - a string describing the source, such as a filenamelineno - the starting line numberlineSource - the text of the line (may be null)lineOffset - the offset into lineSource where problem was detectedErrorReporterpublic static void reportError(java.lang.String message)
message - the error message to reportErrorReporter
public static EvaluatorException reportRuntimeError(java.lang.String message,
java.lang.String sourceName,
int lineno,
java.lang.String lineSource,
int lineOffset)
message - the error message to reportsourceName - a string describing the source, such as a filenamelineno - the starting line numberlineSource - the text of the line (may be null)lineOffset - the offset into lineSource where problem was detected
ErrorReporterpublic static EvaluatorException reportRuntimeError(java.lang.String message)
message - the error message to reportErrorReporterpublic final ScriptableObject initStandardObjects()
This method must be called to initialize a scope before scripts can be evaluated in that scope.
This method does not affect the Context it is called upon.
public final Scriptable initStandardObjects(ScriptableObject scope)
This method must be called to initialize a scope before scripts can be evaluated in that scope.
This method does not affect the Context it is called upon.
scope - the scope to initialize, or null, in which case a new
object will be created to serve as the scope
ScriptableObject.
public ScriptableObject initStandardObjects(ScriptableObject scope,
boolean sealed)
This method must be called to initialize a scope before scripts can be evaluated in that scope.
This method does not affect the Context it is called upon.
This form of the method also allows for creating "sealed" standard objects. An object that is sealed cannot have properties added, changed, or removed. This is useful to create a "superglobal" that can be shared among several top-level objects. Note that sealing is not allowed in the current ECMA/ISO language specification, but is likely for the next version.
scope - the scope to initialize, or null, in which case a new
object will be created to serve as the scopesealed - whether or not to create sealed standard objects that
cannot be modified.
public static java.lang.Object getUndefinedValue()
public final java.lang.Object evaluateString(Scriptable scope,
java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
scope - the scope to execute insource - the JavaScript sourcesourceName - a string describing the source, such as a filenamelineno - the starting line numbersecurityDomain - an arbitrary object that specifies security
information about the origin or owner of the script. For
implementations that don't care about security, this value
may be null.
SecurityController
public final java.lang.Object evaluateReader(Scriptable scope,
java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
throws java.io.IOException
scope - the scope to execute inin - the Reader to get JavaScript source fromsourceName - a string describing the source, such as a filenamelineno - the starting line numbersecurityDomain - an arbitrary object that specifies security
information about the origin or owner of the script. For
implementations that don't care about security, this value
may be null.
java.io.IOException - if an IOException was generated by the Readerpublic final boolean stringIsCompilableUnit(java.lang.String source)
stringIsCompilableUnit is intended to support interactive compilation of javascript. If compiling the string would result in an error that might be fixed by appending more source, this method returns false. In every other case, it returns true.
Interactive shells may accumulate source lines, using this method after each new line is appended to check whether the statement being entered is complete.
source - the source buffer to check
public final Script compileReader(Scriptable scope,
java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
throws java.io.IOException
java.io.IOExceptioncompileReader(Reader in, String sourceName, int lineno,
Object securityDomain)
public final Script compileReader(java.io.Reader in,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
throws java.io.IOException
Returns a script that may later be executed. Will consume all the source in the reader.
in - the input readersourceName - a string describing the source, such as a filenamelineno - the starting line number for reporting errorssecurityDomain - an arbitrary object that specifies security
information about the origin or owner of the script. For
implementations that don't care about security, this value
may be null.
java.io.IOException - if an IOException was generated by the ReaderScript
public final Script compileString(java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
Returns a script that may later be executed.
source - the source stringsourceName - a string describing the source, such as a filenamelineno - the starting line number for reporting errorssecurityDomain - an arbitrary object that specifies security
information about the origin or owner of the script. For
implementations that don't care about security, this value
may be null.
Script
public final Function compileFunction(Scriptable scope,
java.lang.String source,
java.lang.String sourceName,
int lineno,
java.lang.Object securityDomain)
The function source must be a function definition as defined by ECMA (e.g., "function f(a) { return a; }").
scope - the scope to compile relative tosource - the function definition sourcesourceName - a string describing the source, such as a filenamelineno - the starting line numbersecurityDomain - an arbitrary object that specifies security
information about the origin or owner of the script. For
implementations that don't care about security, this value
may be null.
Function
public final java.lang.String decompileScript(Script script,
int indent)
The canonical source of the script is returned.
script - the script to decompileindent - the number of spaces to indent the result
public final java.lang.String decompileFunction(Function fun,
int indent)
Decompiles a previously compiled JavaScript function object to canonical source.
Returns function body of '[native code]' if no decompilation information is available.
fun - the JavaScript function to decompileindent - the number of spaces to indent the result
public final java.lang.String decompileFunctionBody(Function fun,
int indent)
Decompiles the body a previously compiled JavaScript Function object to canonical source, omitting the function header and trailing brace. Returns '[native code]' if no decompilation information is available.
fun - the JavaScript function to decompileindent - the number of spaces to indent the result
public final Scriptable newObject(Scriptable scope)
scope - the scope to search for the constructor and to evaluate
against
public final Scriptable newObject(Scriptable scope,
java.lang.String constructorName)
newObject(scope, "Foo") is equivalent to
evaluating "new Foo()".
scope - the scope to search for the constructor and to evaluate againstconstructorName - the name of the constructor to call
public final Scriptable newObject(Scriptable scope,
java.lang.String constructorName,
java.lang.Object[] args)
scope for the named constructor, calls it with
the given arguments, and returns the result.The code
Object[] args = { "a", "b" };
newObject(scope, "Foo", args)
is equivalent to evaluating "new Foo('a', 'b')", assuming that the Foo
constructor has been defined in scope.
scope - The scope to search for the constructor and to evaluate
againstconstructorName - the name of the constructor to callargs - the array of arguments for the constructor
public final Scriptable newArray(Scriptable scope,
int length)
scope - the scope to create the object inlength - the initial length (JavaScript arrays may have
additional properties added dynamically).
public final Scriptable newArray(Scriptable scope,
java.lang.Object[] elements)
scope - the scope to create the object in.elements - the initial elements. Each object in this array
must be an acceptable JavaScript type and type
of array should be exactly Object[], not
SomeObjectSubclass[].
public final java.lang.Object[] getElements(Scriptable object)
If the object defines a length property convertible to double number, then the number is converted Uint32 value as defined in Ecma 9.6 and Java array of that size is allocated. The array is initialized with the values obtained by calling get() on object for each value of i in [0,length-1]. If there is not a defined value for a property the Undefined value is used to initialize the corresponding element in the array. The Java array is then returned. If the object doesn't define a length property or it is not a number, empty array is returned.
object - the JavaScript array or array-like object
public static boolean toBoolean(java.lang.Object value)
See ECMA 9.2.
value