|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.dev.js.rhino.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 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.
Field Summary | |
---|---|
static int |
FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
if hasFeature(FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME) returns true, allow 'function |
static int |
FEATURE_NON_ECMA_GET_YEAR
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 |
static int |
FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
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 |
static int |
FEATURE_TO_STRING_AS_SOURCE
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 |
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_DEFAULT
The default version. |
static int |
VERSION_UNKNOWN
The unknown version. |
Constructor Summary | |
---|---|
Context()
Create a new Context. |
Method Summary | |
---|---|
static Context |
enter()
Get a context associated with the current thread, creating one if need be. |
static Context |
enter(Context cx)
Get a Context associated with the current thread, using the given Context if need be. |
static void |
exit()
Exit a block of code requiring a Context. |
static Context |
getCurrentContext()
Get the current Context. |
ErrorReporter |
getErrorReporter()
Get the current error reporter. |
int |
getLanguageVersion()
Get the current language version. |
java.util.Locale |
getLocale()
Get the current locale. |
boolean |
hasFeature(int featureIndex)
Controls certain aspects of script semantics. |
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 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. |
ErrorReporter |
setErrorReporter(ErrorReporter reporter)
Change the current error reporter. |
void |
setLanguageVersion(int version)
Set the language version. |
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 FEATURE_NON_ECMA_GET_YEAR
public static final int FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
public static final int FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
public static final int FEATURE_TO_STRING_AS_SOURCE
hasFeature(int)
returns true only if
the current JS version is set to VERSION_1_2
.
Constructor Detail |
---|
public Context()
Method Detail |
---|
public static Context enter()
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(); }
public static Context enter(Context cx)
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
public static void exit()
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.
public static Context getCurrentContext()
public 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 ErrorReporter getErrorReporter()
public ErrorReporter setErrorReporter(ErrorReporter reporter)
public java.util.Locale getLocale()
Locale
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 detectedpublic 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 detectedpublic boolean hasFeature(int featureIndex)
featureIndex
- feature index to check
featureIndex
feature is turned onFEATURE_NON_ECMA_GET_YEAR
,
FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
,
FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
,
FEATURE_TO_STRING_AS_SOURCE
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |