| java.lang.Object com.google.gwt.dev.js.rhino.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 enter() method.
The behavior of the execution engine may be altered through methods
such as setErrorReporter.
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 |
Constructor Summary | |
public | Context() Create a new Context. |
Method Summary | |
static void | codeBug() | public static Context | enter() Get a context associated with the current thread, creating
one if need be.
The Context stores the execution state of the JavaScript
engine, so it is required that the context be entered
before execution may begin. | public static Context | enter(Context cx) Get a Context associated with the current thread, using
the given Context if need be. | public static void | exit() Exit a block of code requiring a Context. | void | firePropertyChange(String property, Object oldValue, Object newValue) | 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 ErrorReporter | getErrorReporter() Get the current error reporter. | public String | getImplementationVersion() Get the implementation version. | public int | getLanguageVersion() Get the current language version. | public Locale | getLocale() Get the current locale. | static String | getMessage(String messageId, Object[] arguments) | static String | getMessage0(String messageId) | static String | getMessage1(String messageId, Object arg1) | static String | getMessage2(String messageId, Object arg1, Object arg2) | static String | getMessage3(String messageId, Object arg1, Object arg2, Object arg3) | 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 retreived. | final public boolean | hasCompileFunctionsWithDynamicScope() Return whether functions are compiled by this context using
dynamic scope. | public boolean | hasFeature(int featureIndex) Controls certain aspects of script semantics. | final boolean | isVersionECMA1() | public void | putThreadLocal(Object key, Object value) Put a value that can later be retrieved using a given key. | 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 | reportWarning(String message, String sourceName, int lineno, String lineSource, int lineOffset) Report a warning using the error reporter for the current thread. | public void | setCompileFunctionsWithDynamicScope(boolean flag) Set whether functions compiled by this context should use
dynamic scope. | public ErrorReporter | setErrorReporter(ErrorReporter reporter) Change the current error reporter. | public void | setLanguageVersion(int version) Set the language version.
Setting the language version will affect functions and scripts compiled
subsequently. | public Locale | setLocale(Locale loc) Set the current locale. |
FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME | final public static int FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME(Code) | | if hasFeature(FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME) returns true,
allow 'function (...) { ... }' to be syntax sugar for
' = function(...) { ... }', when
is not simply identifier.
See Ecma-262, section 11.2 for definition of
|
FEATURE_NON_ECMA_GET_YEAR | final public static int FEATURE_NON_ECMA_GET_YEAR(Code) | | if hasFeature(FEATURE_NON_ECMA_GET_YEAR) returns true,
Date.prototype.getYear subtructs 1900 only if 1900 <= date < 2000
in deviation with Ecma B.2.4
|
FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER | final public static int FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER(Code) | | 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
|
FEATURE_TO_STRING_AS_SOURCE | final public static int FEATURE_TO_STRING_AS_SOURCE(Code) | | if hasFeature(FEATURE_TO_STRING_AS_SOURCE) returns true,
calling toString on JS objects gives JS source with code to create an
object with all enumeratable fields of the original object instead of
printing "[object ]".
By default
Context.hasFeature(int) returns true only if
the current JS version is set to
Context.VERSION_1_2 .
|
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_DEFAULT | final public static int VERSION_DEFAULT(Code) | | The default version.
|
VERSION_UNKNOWN | final public static int VERSION_UNKNOWN(Code) | | The unknown version.
|
check | final static boolean check(Code) | | |
errorCount | int errorCount(Code) | | |
errorReporterProperty | final public static String errorReporterProperty(Code) | | |
instructionCount | int instructionCount(Code) | | |
instructionThreshold | int instructionThreshold(Code) | | |
languageVersionProperty | final public static String languageVersionProperty(Code) | | |
printICode | final static boolean printICode(Code) | | |
printTrees | final static boolean printTrees(Code) | | |
Context | public Context()(Code) | | Create a new Context.
Note that the Context must be associated with a thread before
it can be used to execute a script.
See Also: org.mozilla.javascript.Context.enter |
codeBug | static void codeBug()(Code) | | |
enter | public static Context enter()(Code) | | Get a context associated with the current thread, creating
one if need be.
The Context stores the execution state of the JavaScript
engine, so it is required that the context be entered
before execution may begin. Once a thread has entered
a Context, then getCurrentContext() may be called to find
the context that is associated with the current thread.
Calling enter() will
return either the Context currently associated with the
thread, or will create a new context and associate it
with the current thread. Each call to enter()
must have a matching call to exit() . For example,
Context cx = Context.enter();
try {
...
cx.evaluateString(...);
}
finally { Context.exit(); }
a Context associated with the current thread See Also: org.mozilla.javascript.Context.getCurrentContext See Also: org.mozilla.javascript.Context.exit |
enter | public static Context enter(Context cx)(Code) | | Get a Context associated with the current thread, using
the given Context if need be.
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.
Parameters: cx - a Context to associate with the thread if possible a Context associated with the current thread |
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
enter() 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: org.mozilla.javascript.Context.enter |
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: org.mozilla.javascript.Context.enter See Also: org.mozilla.javascript.Context.exit |
getErrorReporter | public ErrorReporter getErrorReporter()(Code) | | Get the current error reporter.
See Also: org.mozilla.javascript.ErrorReporter |
getImplementationVersion | 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. |
getLanguageVersion | 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 | public Locale getLocale()(Code) | | Get the current locale. Returns the default locale if none has
been set.
See Also: java.util.Locale |
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 retreived. 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. |
hasCompileFunctionsWithDynamicScope | final public boolean hasCompileFunctionsWithDynamicScope()(Code) | | Return whether functions are compiled by this context using
dynamic scope.
If functions are compiled with dynamic scope, then they execute
in the scope of their caller, rather than in their parent scope.
This is useful for sharing functions across multiple scopes.
since: 1.5 Release 1 |
isVersionECMA1 | final boolean isVersionECMA1()(Code) | | |
putThreadLocal | 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 |
removeThreadLocal | 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 |
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 |
setCompileFunctionsWithDynamicScope | public void setCompileFunctionsWithDynamicScope(boolean flag)(Code) | | Set whether functions compiled by this context should use
dynamic scope.
Parameters: flag - if true, compile functions with dynamic scope since: 1.5 Release 1 |
setErrorReporter | public ErrorReporter setErrorReporter(ErrorReporter reporter)(Code) | | Change the current error reporter.
the previous error reporter See Also: org.mozilla.javascript.ErrorReporter |
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. |
|
|