| java.lang.Object org.mozilla.javascript.Context
Context | public class Context (Code) | | 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
Context.call(ContextAction) or
Context.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.
See Also: Scriptable author: Norris Boyd author: Brendan Eich |
Method Summary | |
public void | addActivationName(String name) Add a name to the list of names forcing the creation of real
activation objects for functions. | public static void | addContextListener(ContextListener listener) | final public void | addPropertyChangeListener(PropertyChangeListener l) | public static Object | call(ContextAction action) Call
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. | public static Object | call(ContextFactory factory, Callable callable, Scriptable scope, Scriptable thisObj, Object[] args) Call
Callable.call(Context cxScriptable scopeScriptable thisObjObject[] 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. | static Object | call(ContextFactory factory, ContextAction action) The method implements
logic. | public static void | checkLanguageVersion(int version) | public static void | checkOptimizationLevel(int optimizationLevel) | final public Function | compileFunction(Scriptable scope, String source, String sourceName, int lineno, Object securityDomain) Compile a JavaScript function.
The function source must be a function definition as defined by
ECMA (e.g., "function f(a) { return a; }").
Parameters: scope - the scope to compile relative to Parameters: source - the function definition source Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. | final Function | compileFunction(Scriptable scope, String source, Evaluator compiler, ErrorReporter compilationErrorReporter, String sourceName, int lineno, Object securityDomain) | final public Script | compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) | final public Script | compileReader(Reader in, String sourceName, int lineno, Object securityDomain) Compiles the source in the given reader.
Returns a script that may later be executed.
Will consume all the source in the reader.
Parameters: in - the input reader Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number for reporting errors Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. | final public Script | compileString(String source, String sourceName, int lineno, Object securityDomain) Compiles the source in the given string.
Returns a script that may later be executed.
Parameters: source - the source string Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number for reporting errors Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. | final Script | compileString(String source, Evaluator compiler, ErrorReporter compilationErrorReporter, String sourceName, int lineno, Object securityDomain) | public GeneratedClassLoader | createClassLoader(ClassLoader parent) Create class loader for generated classes. | static Evaluator | createInterpreter() | final public String | decompileFunction(Function fun, int indent) Decompile a JavaScript Function. | final public String | decompileFunctionBody(Function fun, int indent) Decompile the body of a JavaScript Function. | final public String | decompileScript(Script script, int indent) Decompile the script. | public static Context | enter() Same as calling
ContextFactory.enterContext on the global
ContextFactory instance. | public static Context | enter(Context cx) Get a Context associated with the current thread, using
the given Context if need be. | final static Context | enter(Context cx, ContextFactory factory) | final public Object | evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) Evaluate a reader as JavaScript source.
All characters of the reader are consumed.
Parameters: scope - the scope to execute in Parameters: in - the Reader to get JavaScript source from Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. | final public Object | evaluateString(Scriptable scope, String source, String sourceName, int lineno, Object securityDomain) Evaluate a JavaScript source string.
The provided source name and line number are used for error messages
and for producing debug information.
Parameters: scope - the scope to execute in Parameters: source - the JavaScript source Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. | public static void | exit() Exit a block of code requiring a Context.
Calling 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. | final void | firePropertyChange(String property, Object oldValue, Object newValue) | final public ClassLoader | getApplicationClassLoader() | final ClassShutter | getClassShutter() | static Context | getContext() Internal method that reports an error for missing calls to
enter(). | public static Context | getCurrentContext() Get the current Context.
The current Context is per-thread; this method looks up
the Context associated with the current thread. | public static DebuggableScript | getDebuggableView(Script script) Return DebuggableScript instance if any associated with the script.
If callable supports DebuggableScript implementation, the method
returns it. | final public Debugger | getDebugger() Return the current debugger. | final public Object | getDebuggerContextData() Return the debugger context data associated with current context. | public XMLLib.Factory | getE4xImplementationFactory() Returns an object which specifies an E4X implementation to use within
this Context . | final public Object[] | getElements(Scriptable object) Get the elements of a JavaScript array.
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]. | final public ErrorReporter | getErrorReporter() Get the current error reporter. | final public ContextFactory | getFactory() Return
ContextFactory instance used to create this Context. | final public String | getImplementationVersion() Get the implementation version. | final public int | getInstructionObserverThreshold() Get threshold of executed instructions counter that triggers call to
observeInstructionCount() . | final public int | getLanguageVersion() Get the current language version. | final public Locale | getLocale() Get the current locale. | final public int | getMaximumInterpreterStackDepth() Returns the maximum stack depth (in terms of number of call frames)
allowed in a single invocation of interpreter. | final public int | getOptimizationLevel() Get the current optimization level. | RegExpProxy | getRegExpProxy() | SecurityController | getSecurityController() | static String | getSourcePositionFromStack(int[] linep) | final public Object | getThreadLocal(Object key) Get a value corresponding to a key.
Since the Context is associated with a thread it can be
used to maintain values that can be later retrieved using
the current thread.
Note that the values are maintained with the Context, so
if the Context is disassociated from the thread the values
cannot be retrieved. | public static Object | getUndefinedValue() Get the singleton object that represents the JavaScript Undefined value. | final public WrapFactory | getWrapFactory() Return the current WrapFactory, or null if none is defined. | final public boolean | hasCompileFunctionsWithDynamicScope() | public boolean | hasFeature(int featureIndex) Controls certain aspects of script semantics.
Should be overwritten to alter default behavior.
The default implementation calls
ContextFactory.hasFeature(Context cxint featureIndex) that allows to customize Context behavior without introducing
Context subclasses. | final public ScriptableObject | initStandardObjects() Initialize the standard objects. | final public Scriptable | initStandardObjects(ScriptableObject scope) Initialize the standard objects.
Creates instances of the standard objects and their constructors
(Object, String, Number, Date, etc.), setting up 'scope' to act
as a global object as in ECMA 15.1.
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.
Parameters: scope - the scope to initialize, or null, in which case a newobject will be created to serve as the scope the initialized scope. | public ScriptableObject | initStandardObjects(ScriptableObject scope, boolean sealed) Initialize the standard objects.
Creates instances of the standard objects and their constructors
(Object, String, Number, Date, etc.), setting up 'scope' to act
as a global object as in ECMA 15.1.
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. | final public boolean | isActivationNeeded(String name) Check whether the name is in the list of names of objects
forcing the creation of activation objects. | final public boolean | isGeneratingDebug() Tell whether debug information is being generated. | final public boolean | isGeneratingDebugChanged() | final public boolean | isGeneratingSource() Tell whether source information is being generated. | final public boolean | isSealed() Checks if this is a sealed Context. | public static boolean | isValidLanguageVersion(int version) | public static boolean | isValidOptimizationLevel(int optimizationLevel) | final boolean | isVersionECMA1() | public static Object | javaToJS(Object value, Scriptable scope) Convenient method to convert java value to its closest representation
in JavaScript. | public static Object | jsToJava(Object value, Class desiredType) Convert a JavaScript value into the desired type.
Uses the semantics defined with LiveConnect3 and throws an
Illegal argument exception if the conversion cannot be performed.
Parameters: value - the JavaScript value to convert Parameters: desiredType - the Java type to convert to. | final public Scriptable | newArray(Scriptable scope, int length) Create an array with a specified initial length.
Parameters: scope - the scope to create the object in Parameters: length - the initial length (JavaScript arrays may haveadditional properties added dynamically). | final public Scriptable | newArray(Scriptable scope, Object[] elements) Create an array with a set of initial elements.
Parameters: scope - the scope to create the object in. Parameters: elements - the initial elements. | final public Scriptable | newObject(Scriptable scope) Create a new JavaScript object. | final public Scriptable | newObject(Scriptable scope, String constructorName) Create a new JavaScript object by executing the named constructor. | final public Scriptable | newObject(Scriptable scope, String constructorName, 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. | static void | onSealedMutation() | final public void | putThreadLocal(Object key, Object value) Put a value that can later be retrieved using a given key. | public void | removeActivationName(String name) Remove a name from the list of names forcing the creation of real
activation objects for functions. | public static void | removeContextListener(ContextListener listener) | final public void | removePropertyChangeListener(PropertyChangeListener l) | final public void | removeThreadLocal(Object key) Remove values from thread-local storage. | public static void | reportError(String message, String sourceName, int lineno, String lineSource, int lineOffset) Report an error using the error reporter for the current thread. | public static void | reportError(String message) Report an error using the error reporter for the current thread. | public static EvaluatorException | reportRuntimeError(String message, String sourceName, int lineno, String lineSource, int lineOffset) Report a runtime error using the error reporter for the current thread. | public static EvaluatorException | reportRuntimeError(String message) Report a runtime error using the error reporter for the current thread. | static EvaluatorException | reportRuntimeError0(String messageId) | static EvaluatorException | reportRuntimeError1(String messageId, Object arg1) | static EvaluatorException | reportRuntimeError2(String messageId, Object arg1, Object arg2) | static EvaluatorException | reportRuntimeError3(String messageId, Object arg1, Object arg2, Object arg3) | static EvaluatorException | reportRuntimeError4(String messageId, Object arg1, Object arg2, Object arg3, Object arg4) | public static void | reportWarning(String message, String sourceName, int lineno, String lineSource, int lineOffset) Report a warning using the error reporter for the current thread. | public static void | reportWarning(String message) Report a warning using the error reporter for the current thread. | public static void | reportWarning(String message, Throwable t) | final public void | seal(Object sealKey) Seal this Context object so any attempt to modify any of its properties
including calling
Context.enter() and
Context.exit() methods will
throw an exception.
If sealKey is not null, calling
Context.unseal(Object sealKey) with the same key unseals
the object. | final public void | setApplicationClassLoader(ClassLoader loader) | public static void | setCachingEnabled(boolean cachingEnabled) | final public void | setClassShutter(ClassShutter shutter) Set the LiveConnect access filter for this context. | final public void | setCompileFunctionsWithDynamicScope(boolean flag) | final public void | setDebugger(Debugger debugger, Object contextData) Set the associated debugger. | final public ErrorReporter | setErrorReporter(ErrorReporter reporter) Change the current error reporter. | public void | setGenerateObserverCount(boolean generateObserverCount) Turn on or off generation of code with callbacks to
track the count of executed instructions.
Currently only affects JVM byte code generation: this slows down the
generated code, but code generated without the callbacks will not
be counted toward instruction thresholds. | final public void | setGeneratingDebug(boolean generatingDebug) Specify whether or not debug information should be generated. | final public void | setGeneratingSource(boolean generatingSource) Specify whether or not source information should be generated. | final public void | setInstructionObserverThreshold(int threshold) Set threshold of executed instructions counter that triggers call to
observeInstructionCount() . | public void | setLanguageVersion(int version) Set the language version.
Setting the language version will affect functions and scripts compiled
subsequently. | final public Locale | setLocale(Locale loc) Set the current locale. | final public void | setMaximumInterpreterStackDepth(int max) Sets the maximum stack depth (in terms of number of call frames)
allowed in a single invocation of interpreter. | final public void | setOptimizationLevel(int optimizationLevel) Set the current optimization level.
The optimization level is expected to be an integer between -1 and
9. | final public void | setSecurityController(SecurityController controller) Set the security controller for this context. | final public void | setWrapFactory(WrapFactory wrapFactory) Set a WrapFactory for this Context. | final public boolean | stringIsCompilableUnit(String source) Check whether a string is ready to be compiled.
stringIsCompilableUnit is intended to support interactive compilation of
javascript. | public static RuntimeException | throwAsScriptRuntimeEx(Throwable e) Rethrow the exception wrapping it as the script runtime exception. | public static boolean | toBoolean(Object value) Convert the value to a JavaScript boolean value. | public static double | toNumber(Object value) Convert the value to a JavaScript Number value. | public static Scriptable | toObject(Object value, Scriptable scope) Convert the value to an JavaScript object value. | public static Scriptable | toObject(Object value, Scriptable scope, Class staticType) | public static String | toString(Object value) Convert the value to a JavaScript String value. | public static Object | toType(Object value, Class desiredType) | final public void | unseal(Object sealKey) Unseal previously sealed Context object. |
FEATURE_DYNAMIC_SCOPE | final public static int FEATURE_DYNAMIC_SCOPE(Code) | | Control if dynamic scope should be used for name access.
If hasFeature(FEATURE_DYNAMIC_SCOPE) returns true, then the name lookup
during name resolution will use the top scope of the script or function
which is at the top of JS execution stack instead of the top scope of the
script or function from the current stack frame if the top scope of
the top stack frame contains the top scope of the current stack frame
on its prototype chain.
This is useful to define shared scope containing functions that can
be called from scripts and functions using private scopes.
By default
Context.hasFeature(int) returns false.
since: 1.6 Release 1 |
FEATURE_E4X | final public static int FEATURE_E4X(Code) | | Control if support for E4X(ECMAScript for XML) extension is available.
If hasFeature(FEATURE_E4X) returns true, the XML syntax is available.
By default
Context.hasFeature(int) returns true if
the current JS version is set to
Context.VERSION_DEFAULT or is at least
Context.VERSION_1_6 .
since: 1.6 Release 1 |
FEATURE_ENHANCED_JAVA_ACCESS | final public static int FEATURE_ENHANCED_JAVA_ACCESS(Code) | | Enables enhanced access to Java.
Specifically, controls whether private and protected members can be
accessed, and whether scripts can catch all Java exceptions.
Note that this feature should only be enabled for trusted scripts.
By default
Context.hasFeature(int) returns false.
since: 1.7 Release 1 |
FEATURE_LOCATION_INFORMATION_IN_ERROR | final public static int FEATURE_LOCATION_INFORMATION_IN_ERROR(Code) | | When the feature is on Rhino will add a "fileName" and "lineNumber"
properties to Error objects automatically. When the feature is off, you
have to explicitly pass them as the second and third argument to the
Error constructor. Note that neither behaviour is fully ECMA 262
compliant (as 262 doesn't specify a three-arg constructor), but keeping
the feature off results in Error objects that don't have
additional non-ECMA properties when constructed using the ECMA-defined
single-arg constructor and is thus desirable if a stricter ECMA
compliance is desired, specifically adherence to the point 15.11.5. of
the standard.
By default
Context.hasFeature(int) returns false.
since: 1.6 Release 6 |
FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME | final public static int FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME(Code) | | Control if member expression as function name extension is available.
If hasFeature(FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME) returns
true, allow function memberExpression(args) { body } to be
syntax sugar for memberExpression = function(args) { body },
when memberExpression is not a simple identifier.
See ECMAScript-262, section 11.2 for definition of memberExpression.
By default
Context.hasFeature(int) returns false.
|
FEATURE_NON_ECMA_GET_YEAR | final public static int FEATURE_NON_ECMA_GET_YEAR(Code) | | Controls behaviour of Date.prototype.getYear().
If hasFeature(FEATURE_NON_ECMA_GET_YEAR) returns true,
Date.prototype.getYear subtructs 1900 only if 1900 <= date < 2000.
The default behavior of
Context.hasFeature(int) is always to subtruct
1900 as rquired by ECMAScript B.2.4.
|
FEATURE_PARENT_PROTO_PROPERTIES | final public static int FEATURE_PARENT_PROTO_PROPERTIES(Code) | | Control if properties __proto__ and __parent__
are treated specially.
If hasFeature(FEATURE_PARENT_PROTO_PROPERTIES) returns true,
treat __parent__ and __proto__ as special 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
Context.hasFeature(int) returns true.
|
FEATURE_PARENT_PROTO_PROPRTIES | final public static int FEATURE_PARENT_PROTO_PROPRTIES(Code) | | |
FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER | final public static int FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER(Code) | | Control if reserved keywords are treated as identifiers.
If hasFeature(RESERVED_KEYWORD_AS_IDENTIFIER) returns true,
treat future reserved keyword (see Ecma-262, section 7.5.3) as ordinary
identifiers but warn about this usage.
By default
Context.hasFeature(int) returns false.
|
FEATURE_STRICT_EVAL | final public static int FEATURE_STRICT_EVAL(Code) | | Control if strict eval mode is enabled.
When the feature is on Rhino reports runtime errors if non-string
argument is passed to the eval function. When the feature is off
eval simply return non-string argument as is without performing any
evaluation as required by ECMA 262.
By default
Context.hasFeature(int) returns false.
since: 1.6 Release 1 |
FEATURE_STRICT_MODE | final public static int FEATURE_STRICT_MODE(Code) | | Controls whether JS 1.5 'strict mode' is enabled.
When the feature is on, Rhino reports more than a dozen different
warnings. When the feature is off, these warnings are not generated.
FEATURE_STRICT_MODE implies FEATURE_STRICT_VARS and FEATURE_STRICT_EVAL.
By default
Context.hasFeature(int) returns false.
since: 1.6 Release 6 |
FEATURE_STRICT_VARS | final public static int FEATURE_STRICT_VARS(Code) | | Control if strict variable mode is enabled.
When the feature is on Rhino reports runtime errors if assignment
to a global variable that does not exist is executed. When the feature
is off such assignments creates new variable in the global scope as
required by ECMA 262.
By default
Context.hasFeature(int) returns false.
since: 1.6 Release 1 |
FEATURE_TO_STRING_AS_SOURCE | final public static int FEATURE_TO_STRING_AS_SOURCE(Code) | | Control if toString() should returns the same result
as toSource() when applied to objects and arrays.
If hasFeature(FEATURE_TO_STRING_AS_SOURCE) returns true,
calling toString() on JS objects gives the same result as
calling toSource(). That is it returns JS source with code
to create an object with all enumeratable fields of the original object
instead of printing [object result of
Scriptable.getClassName ].
By default
Context.hasFeature(int) returns true only if
the current JS version is set to
Context.VERSION_1_2 .
|
FEATURE_WARNING_AS_ERROR | final public static int FEATURE_WARNING_AS_ERROR(Code) | | Controls whether a warning should be treated as an error.
since: 1.6 Release 6 |
VERSION_1_0 | final public static int VERSION_1_0(Code) | | JavaScript 1.0
|
VERSION_1_1 | final public static int VERSION_1_1(Code) | | JavaScript 1.1
|
VERSION_1_2 | final public static int VERSION_1_2(Code) | | JavaScript 1.2
|
VERSION_1_3 | final public static int VERSION_1_3(Code) | | JavaScript 1.3
|
VERSION_1_4 | final public static int VERSION_1_4(Code) | | JavaScript 1.4
|
VERSION_1_5 | final public static int VERSION_1_5(Code) | | JavaScript 1.5
|
VERSION_1_6 | final public static int VERSION_1_6(Code) | | JavaScript 1.6
|
VERSION_1_7 | final public static int VERSION_1_7(Code) | | JavaScript 1.7
|
VERSION_DEFAULT | final public static int VERSION_DEFAULT(Code) | | The default version.
|
VERSION_UNKNOWN | final public static int VERSION_UNKNOWN(Code) | | The unknown version.
|
activationNames | Hashtable activationNames(Code) | | This is the list of names of objects forcing the creation of
function activation records.
|
compileFunctionsWithDynamicScopeFlag | boolean compileFunctionsWithDynamicScopeFlag(Code) | | |
emptyArgs | final public static Object[] emptyArgs(Code) | | Convenient value to use as zero-length array of objects.
|
errorReporterProperty | final public static String errorReporterProperty(Code) | | |
generateObserverCount | public boolean generateObserverCount(Code) | | |
instructionCount | int instructionCount(Code) | | |
instructionThreshold | int instructionThreshold(Code) | | |
interpreterSecurityDomain | Object interpreterSecurityDomain(Code) | | |
languageVersionProperty | final public static String languageVersionProperty(Code) | | |
previousInterpreterInvocations | ObjArray previousInterpreterInvocations(Code) | | |
scratchIndex | int scratchIndex(Code) | | |
scratchUint32 | long scratchUint32(Code) | | |
useDynamicScope | boolean useDynamicScope(Code) | | |
addActivationName | public void addActivationName(String name)(Code) | | Add a name to the list of names forcing the creation of real
activation objects for functions.
Parameters: name - the name of the object to add to the list |
checkLanguageVersion | public static void checkLanguageVersion(int version)(Code) | | |
checkOptimizationLevel | public static void checkOptimizationLevel(int optimizationLevel)(Code) | | |
compileFunction | final public Function compileFunction(Scriptable scope, String source, String sourceName, int lineno, Object securityDomain)(Code) | | Compile a JavaScript function.
The function source must be a function definition as defined by
ECMA (e.g., "function f(a) { return a; }").
Parameters: scope - the scope to compile relative to Parameters: source - the function definition source Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. Forimplementations that don't care about security, this valuemay be null. a Function that may later be called See Also: org.mozilla.javascript.Function |
compileReader | final public Script compileReader(Reader in, String sourceName, int lineno, Object securityDomain) throws IOException(Code) | | Compiles the source in the given reader.
Returns a script that may later be executed.
Will consume all the source in the reader.
Parameters: in - the input reader Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number for reporting errors Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. Forimplementations that don't care about security, this valuemay be null. a script that may later be executed exception: IOException - if an IOException was generated by the Reader See Also: org.mozilla.javascript.Script |
compileString | final public Script compileString(String source, String sourceName, int lineno, Object securityDomain)(Code) | | Compiles the source in the given string.
Returns a script that may later be executed.
Parameters: source - the source string Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number for reporting errors Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. Forimplementations that don't care about security, this valuemay be null. a script that may later be executed See Also: org.mozilla.javascript.Script |
decompileFunction | final public String decompileFunction(Function fun, int indent)(Code) | | Decompile a JavaScript Function.
Decompiles a previously compiled JavaScript function object to
canonical source.
Returns function body of '[native code]' if no decompilation
information is available.
Parameters: fun - the JavaScript function to decompile Parameters: indent - the number of spaces to indent the result a string representing the function source |
decompileFunctionBody | final public String decompileFunctionBody(Function fun, int indent)(Code) | | Decompile the body of a JavaScript Function.
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.
Parameters: fun - the JavaScript function to decompile Parameters: indent - the number of spaces to indent the result a string representing the function body source. |
decompileScript | final public String decompileScript(Script script, int indent)(Code) | | Decompile the script.
The canonical source of the script is returned.
Parameters: script - the script to decompile Parameters: indent - the number of spaces to indent the result a string representing the script source |
evaluateReader | final public Object evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException(Code) | | Evaluate a reader as JavaScript source.
All characters of the reader are consumed.
Parameters: scope - the scope to execute in Parameters: in - the Reader to get JavaScript source from Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. Forimplementations that don't care about security, this valuemay be null. the result of evaluating the source exception: IOException - if an IOException was generated by the Reader |
evaluateString | final public Object evaluateString(Scriptable scope, String source, String sourceName, int lineno, Object securityDomain)(Code) | | Evaluate a JavaScript source string.
The provided source name and line number are used for error messages
and for producing debug information.
Parameters: scope - the scope to execute in Parameters: source - the JavaScript source Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: securityDomain - an arbitrary object that specifies securityinformation about the origin or owner of the script. Forimplementations that don't care about security, this valuemay be null. the result of evaluating the string See Also: org.mozilla.javascript.SecurityController |
exit | public static void exit()(Code) | | Exit a block of code requiring a Context.
Calling 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.
See Also: ContextFactory.enterContext |
getContext | static Context getContext()(Code) | | Internal method that reports an error for missing calls to
enter().
|
getCurrentContext | public static Context getCurrentContext()(Code) | | Get the current Context.
The current Context is per-thread; this method looks up
the Context associated with the current thread.
the Context associated with the current thread, ornull if no context is associated with the currentthread. See Also: ContextFactory.enterContext See Also: ContextFactory.call(ContextAction) |
getDebuggableView | public static DebuggableScript getDebuggableView(Script script)(Code) | | Return DebuggableScript instance if any associated with the script.
If callable supports DebuggableScript implementation, the method
returns it. Otherwise null is returned.
|
getDebugger | final public Debugger getDebugger()(Code) | | Return the current debugger.
the debugger, or null if none is attached. |
getDebuggerContextData | final public Object getDebuggerContextData()(Code) | | Return the debugger context data associated with current context.
the debugger data, or null if debugger is not attached |
getE4xImplementationFactory | public XMLLib.Factory getE4xImplementationFactory()(Code) | | Returns an object which specifies an E4X implementation to use within
this Context . Note
that the XMLLib.Factory interface should be considered experimental.
The default implementation uses the implementation provided by this
Context 's
ContextFactory .
An XMLLib.Factory. Should not return null ifContext.FEATURE_E4X is enabled. See Context.hasFeature. |
getElements | final public Object[] getElements(Scriptable object)(Code) | | Get the elements of a JavaScript array.
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.
Parameters: object - the JavaScript array or array-like object a Java array of objects since: 1.4 release 2 |
getImplementationVersion | final public String getImplementationVersion()(Code) | | Get the implementation version.
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".
a string that encodes the product, language version, releasenumber, and date. |
getInstructionObserverThreshold | final public int getInstructionObserverThreshold()(Code) | | Get threshold of executed instructions counter that triggers call to
observeInstructionCount() .
When the threshold is zero, instruction counting is disabled,
otherwise each time the run-time executes at least the threshold value
of script instructions, observeInstructionCount() will
be called.
|
getLanguageVersion | final public int getLanguageVersion()(Code) | | Get the current language version.
The language version number affects JavaScript semantics as detailed
in the overview documentation.
an integer that is one of VERSION_1_0, VERSION_1_1, etc. |
getLocale | final public Locale getLocale()(Code) | | Get the current locale. Returns the default locale if none has
been set.
See Also: java.util.Locale |
getMaximumInterpreterStackDepth | final public int getMaximumInterpreterStackDepth()(Code) | | Returns the maximum stack depth (in terms of number of call frames)
allowed in a single invocation of interpreter. If the set depth would be
exceeded, the interpreter will throw an EvaluatorException in the script.
Defaults to Integer.MAX_VALUE. The setting only has effect for
interpreted functions (those compiled with optimization level set to -1).
As the interpreter doesn't use the Java stack but rather manages its own
stack in the heap memory, a runaway recursion in interpreted code would
eventually consume all available memory and cause OutOfMemoryError
instead of a StackOverflowError limited to only a single thread. This
setting helps prevent such situations.
The current maximum interpreter stack depth. |
getOptimizationLevel | final public int getOptimizationLevel()(Code) | | Get the current optimization level.
The optimization level is expressed as an integer between -1 and
9.
since: 1.3 |
getSourcePositionFromStack | static String getSourcePositionFromStack(int[] linep)(Code) | | |
getThreadLocal | final public Object getThreadLocal(Object key)(Code) | | Get a value corresponding to a key.
Since the Context is associated with a thread it can be
used to maintain values that can be later retrieved using
the current thread.
Note that the values are maintained with the Context, so
if the Context is disassociated from the thread the values
cannot be retrieved. Also, if private data is to be maintained
in this manner the key should be a java.lang.Object
whose reference is not divulged to untrusted code.
Parameters: key - the key used to lookup the value a value previously stored using putThreadLocal. |
getUndefinedValue | public static Object getUndefinedValue()(Code) | | Get the singleton object that represents the JavaScript Undefined value.
|
getWrapFactory | final public WrapFactory getWrapFactory()(Code) | | Return the current WrapFactory, or null if none is defined.
See Also: WrapFactory since: 1.5 Release 4 |
initStandardObjects | final public ScriptableObject initStandardObjects()(Code) | | Initialize the standard objects.
Creates instances of the standard objects and their constructors
(Object, String, Number, Date, etc.), setting up 'scope' to act
as a global object as in ECMA 15.1.
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.
the initialized scope |
initStandardObjects | final public Scriptable initStandardObjects(ScriptableObject scope)(Code) | | Initialize the standard objects.
Creates instances of the standard objects and their constructors
(Object, String, Number, Date, etc.), setting up 'scope' to act
as a global object as in ECMA 15.1.
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.
Parameters: scope - the scope to initialize, or null, in which case a newobject will be created to serve as the scope the initialized scope. The method returns the value of the scopeargument if it is not null or newly allocated scope object whichis an instance ScriptableObject. |
initStandardObjects | public ScriptableObject initStandardObjects(ScriptableObject scope, boolean sealed)(Code) | | Initialize the standard objects.
Creates instances of the standard objects and their constructors
(Object, String, Number, Date, etc.), setting up 'scope' to act
as a global object as in ECMA 15.1.
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.
Parameters: scope - the scope to initialize, or null, in which case a newobject will be created to serve as the scope Parameters: sealed - whether or not to create sealed standard objects thatcannot be modified. the initialized scope. The method returns the value of the scopeargument if it is not null or newly allocated scope object. since: 1.4R3 |
isActivationNeeded | final public boolean isActivationNeeded(String name)(Code) | | Check whether the name is in the list of names of objects
forcing the creation of activation objects.
Parameters: name - the name of the object to test true if an function activation object is needed. |
isGeneratingDebug | final public boolean isGeneratingDebug()(Code) | | Tell whether debug information is being generated.
since: 1.3 |
isGeneratingDebugChanged | final public boolean isGeneratingDebugChanged()(Code) | | |
isGeneratingSource | final public boolean isGeneratingSource()(Code) | | Tell whether source information is being generated.
since: 1.3 |
isSealed | final public boolean isSealed()(Code) | | Checks if this is a sealed Context. A sealed Context instance does not
allow to modify any of its properties and will throw an exception
on any such attempt.
See Also: Context.seal(Object sealKey) |
isValidLanguageVersion | public static boolean isValidLanguageVersion(int version)(Code) | | |
isValidOptimizationLevel | public static boolean isValidOptimizationLevel(int optimizationLevel)(Code) | | |
isVersionECMA1 | final boolean isVersionECMA1()(Code) | | |
javaToJS | public static Object javaToJS(Object value, Scriptable scope)(Code) | | Convenient method to convert java value to its closest representation
in JavaScript.
If value is an instance of String, Number, Boolean, Function or
Scriptable, it is returned as it and will be treated as the corresponding
JavaScript type of string, number, boolean, function and object.
Note that for Number instances during any arithmetic operation in
JavaScript the engine will always use the result of
Number.doubleValue() resulting in a precision loss if
the number can not fit into double.
If value is an instance of Character, it will be converted to string of
length 1 and its JavaScript type will be string.
The rest of values will be wrapped as LiveConnect objects
by calling
WrapFactory.wrap(Context cxScriptable scopeObject objClass staticType) as in:
Context cx = Context.getCurrentContext();
return cx.getWrapFactory().wrap(cx, scope, value, null);
Parameters: value - any Java object Parameters: scope - top scope object value suitable to pass to any API that takes JavaScript values. |
jsToJava | public static Object jsToJava(Object value, Class desiredType) throws EvaluatorException(Code) | | Convert a JavaScript value into the desired type.
Uses the semantics defined with LiveConnect3 and throws an
Illegal argument exception if the conversion cannot be performed.
Parameters: value - the JavaScript value to convert Parameters: desiredType - the Java type to convert to. Primitive Javatypes are represented using the TYPE fields in the correspondingwrapper class in java.lang. the converted value throws: EvaluatorException - if the conversion cannot be performed |
newArray | final public Scriptable newArray(Scriptable scope, int length)(Code) | | Create an array with a specified initial length.
Parameters: scope - the scope to create the object in Parameters: length - the initial length (JavaScript arrays may haveadditional properties added dynamically). the new array object |
newArray | final public Scriptable newArray(Scriptable scope, Object[] elements)(Code) | | Create an array with a set of initial elements.
Parameters: scope - the scope to create the object in. Parameters: elements - the initial elements. Each object in this arraymust be an acceptable JavaScript type and typeof array should be exactly Object[], notSomeObjectSubclass[]. the new array object. |
newObject | final public Scriptable newObject(Scriptable scope)(Code) | | Create a new JavaScript object.
Equivalent to evaluating "new Object()".
Parameters: scope - the scope to search for the constructor and to evaluateagainst the new object |
newObject | final public Scriptable newObject(Scriptable scope, String constructorName)(Code) | | Create a new JavaScript object by executing the named constructor.
The call newObject(scope, "Foo") is equivalent to
evaluating "new Foo()".
Parameters: scope - the scope to search for the constructor and to evaluate against Parameters: constructorName - the name of the constructor to call the new object |
newObject | final public Scriptable newObject(Scriptable scope, String constructorName, Object[] args)(Code) | | Creates a new JavaScript object by executing the named constructor.
Searches 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 .
Parameters: scope - The scope to search for the constructor and to evaluateagainst Parameters: constructorName - the name of the constructor to call Parameters: args - the array of arguments for the constructor the new object |
observeInstructionCount | protected void observeInstructionCount(int instructionCount)(Code) | | Allow application to monitor counter of executed script instructions
in Context subclasses.
Run-time calls this when instruction counting is enabled and the counter
reaches limit set by setInstructionObserverThreshold() .
The method is useful to observe long running scripts and if necessary
to terminate them.
The instruction counting support is available only for interpreted
scripts generated when the optimization level is set to -1.
The default implementation calls
ContextFactory.observeInstructionCount(Context cxint instructionCount) that allows to customize Context behavior without introducing
Context subclasses.
Parameters: instructionCount - amount of script instruction executed sincelast call to observeInstructionCount throws: Error - to terminate the script See Also: Context.setOptimizationLevel(int) |
onSealedMutation | static void onSealedMutation()(Code) | | |
putThreadLocal | final public void putThreadLocal(Object key, Object value)(Code) | | Put a value that can later be retrieved using a given key.
Parameters: key - the key used to index the value Parameters: value - the value to save |
removeActivationName | public void removeActivationName(String name)(Code) | | Remove a name from the list of names forcing the creation of real
activation objects for functions.
Parameters: name - the name of the object to remove from the list |
removeThreadLocal | final public void removeThreadLocal(Object key)(Code) | | Remove values from thread-local storage.
Parameters: key - the key for the entry to remove. since: 1.5 release 2 |
reportError | public static void reportError(String message, String sourceName, int lineno, String lineSource, int lineOffset)(Code) | | Report an error using the error reporter for the current thread.
Parameters: message - the error message to report Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: lineSource - the text of the line (may be null) Parameters: lineOffset - the offset into lineSource where problem was detected See Also: org.mozilla.javascript.ErrorReporter |
reportRuntimeError | public static EvaluatorException reportRuntimeError(String message, String sourceName, int lineno, String lineSource, int lineOffset)(Code) | | Report a runtime error using the error reporter for the current thread.
Parameters: message - the error message to report Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: lineSource - the text of the line (may be null) Parameters: lineOffset - the offset into lineSource where problem was detected a runtime exception that will be thrown to terminate theexecution of the script See Also: org.mozilla.javascript.ErrorReporter |
reportWarning | public static void reportWarning(String message, String sourceName, int lineno, String lineSource, int lineOffset)(Code) | | Report a warning using the error reporter for the current thread.
Parameters: message - the warning message to report Parameters: sourceName - a string describing the source, such as a filename Parameters: lineno - the starting line number Parameters: lineSource - the text of the line (may be null) Parameters: lineOffset - the offset into lineSource where problem was detected See Also: org.mozilla.javascript.ErrorReporter |
setApplicationClassLoader | final public void setApplicationClassLoader(ClassLoader loader)(Code) | | |
setClassShutter | final public void setClassShutter(ClassShutter shutter)(Code) | | Set the LiveConnect access filter for this context.
ClassShutter may only be set if it is currently null.
Otherwise a SecurityException is thrown.
Parameters: shutter - a ClassShutter object throws: SecurityException - if there is already a ClassShutterobject for this Context |
setDebugger | final public void setDebugger(Debugger debugger, Object contextData)(Code) | | Set the associated debugger.
Parameters: debugger - the debugger to be used on callbacks fromthe engine. Parameters: contextData - arbitrary object that debugger can use to storeper Context data. |
setGenerateObserverCount | public void setGenerateObserverCount(boolean generateObserverCount)(Code) | | Turn on or off generation of code with callbacks to
track the count of executed instructions.
Currently only affects JVM byte code generation: this slows down the
generated code, but code generated without the callbacks will not
be counted toward instruction thresholds. Rhino's interpretive
mode does instruction counting without inserting callbacks, so
there is no requirement to compile code differently.
Parameters: generateObserverCount - if true, generated code will containcalls to accumulate an estimate of the instructions executed. |
setGeneratingDebug | final public void setGeneratingDebug(boolean generatingDebug)(Code) | | Specify whether or not debug information should be generated.
Setting the generation of debug information on will set the
optimization level to zero.
since: 1.3 |
setGeneratingSource | final public void setGeneratingSource(boolean generatingSource)(Code) | | Specify whether or not source information should be generated.
Without source information, evaluating the "toString" method
on JavaScript functions produces only "[native code]" for
the body of the function.
Note that code generated without source is not fully ECMA
conformant.
since: 1.3 |
setInstructionObserverThreshold | final public void setInstructionObserverThreshold(int threshold)(Code) | | Set threshold of executed instructions counter that triggers call to
observeInstructionCount() .
When the threshold is zero, instruction counting is disabled,
otherwise each time the run-time executes at least the threshold value
of script instructions, observeInstructionCount() will
be called.
Note that the meaning of "instruction" is not guaranteed to be
consistent between compiled and interpretive modes: executing a given
script or function in the different modes will result in different
instruction counts against the threshold.
Context.setGenerateObserverCount is called with true if
threshold is greater than zero, false otherwise.
Parameters: threshold - The instruction threshold |
setLanguageVersion | public void setLanguageVersion(int version)(Code) | | Set the language version.
Setting the language version will affect functions and scripts compiled
subsequently. See the overview documentation for version-specific
behavior.
Parameters: version - the version as specified by VERSION_1_0, VERSION_1_1, etc. |
setMaximumInterpreterStackDepth | final public void setMaximumInterpreterStackDepth(int max)(Code) | | Sets the maximum stack depth (in terms of number of call frames)
allowed in a single invocation of interpreter. If the set depth would be
exceeded, the interpreter will throw an EvaluatorException in the script.
Defaults to Integer.MAX_VALUE. The setting only has effect for
interpreted functions (those compiled with optimization level set to -1).
As the interpreter doesn't use the Java stack but rather manages its own
stack in the heap memory, a runaway recursion in interpreted code would
eventually consume all available memory and cause OutOfMemoryError
instead of a StackOverflowError limited to only a single thread. This
setting helps prevent such situations.
Parameters: max - the new maximum interpreter stack depth throws: IllegalStateException - if this context's optimization level is not-1 throws: IllegalArgumentException - if the new depth is not at least 1 |
setOptimizationLevel | final public void setOptimizationLevel(int optimizationLevel)(Code) | | Set the current optimization level.
The optimization level is expected to be an integer between -1 and
9. Any negative values will be interpreted as -1, and any values
greater than 9 will be interpreted as 9.
An optimization level of -1 indicates that interpretive mode will
always be used. Levels 0 through 9 indicate that class files may
be generated. Higher optimization levels trade off compile time
performance for runtime performance.
The optimizer level can't be set greater than -1 if the optimizer
package doesn't exist at run time.
Parameters: optimizationLevel - an integer indicating the level ofoptimization to perform since: 1.3 |
setWrapFactory | final public void setWrapFactory(WrapFactory wrapFactory)(Code) | | Set a WrapFactory for this Context.
The WrapFactory allows custom object wrapping behavior for
Java object manipulated with JavaScript.
See Also: WrapFactory since: 1.5 Release 4 |
stringIsCompilableUnit | final public boolean stringIsCompilableUnit(String source)(Code) | | Check whether a string is ready to be compiled.
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.
Parameters: source - the source buffer to check whether the source is ready for compilation since: 1.4 Release 2 |
throwAsScriptRuntimeEx | public static RuntimeException throwAsScriptRuntimeEx(Throwable e)(Code) | | Rethrow the exception wrapping it as the script runtime exception.
Unless the exception is instance of
EcmaError or
EvaluatorException it will be wrapped as
WrappedException , a subclass of
EvaluatorException .
The resulting exception object always contains
source name and line number of script that triggered exception.
This method always throws an exception, its return value is provided
only for convenience to allow a usage like:
throw Context.throwAsScriptRuntimeEx(ex);
to indicate that code after the method is unreachable.
throws: EvaluatorException - throws: EcmaError - |
toBoolean | public static boolean toBoolean(Object value)(Code) | | Convert the value to a JavaScript boolean value.
See ECMA 9.2.
Parameters: value - a JavaScript value the corresponding boolean value converted usingthe ECMA rules |
toNumber | public static double toNumber(Object value)(Code) | | Convert the value to a JavaScript Number value.
Returns a Java double for the JavaScript Number.
See ECMA 9.3.
Parameters: value - a JavaScript value the corresponding double value converted usingthe ECMA rules |
toObject | public static Scriptable toObject(Object value, Scriptable scope)(Code) | | Convert the value to an JavaScript object value.
Note that a scope must be provided to look up the constructors
for Number, Boolean, and String.
See ECMA 9.9.
Additionally, arbitrary Java objects and classes will be
wrapped in a Scriptable object with its Java fields and methods
reflected as JavaScript properties of the object.
Parameters: value - any Java object Parameters: scope - global scope containing constructors for Number,Boolean, and String new JavaScript object |
toString | public static String toString(Object value)(Code) | | Convert the value to a JavaScript String value.
See ECMA 9.8.
Parameters: value - a JavaScript value the corresponding String value converted usingthe ECMA rules |
|
|