C# Class Rhino.Context

This class represents the runtime context of an executing script.
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.

显示文件 Open project: hazzik/Rhino.Net Class Usage Examples

Public Properties

Property Type Description
emptyArgs object[]
generateObserverCount bool

Public Methods

Method Description
AddActivationName ( string name ) : void

Add a name to the list of names forcing the creation of real activation objects for functions.

Add a name to the list of names forcing the creation of real activation objects for functions.

AddPropertyChangeListener ( PropertyChangeListener l ) : void

Register an object to receive notifications when a bound property has changed

Call ( ContextFactory factory, Callable callable, Scriptable scope, Scriptable thisObj, object args ) : object

Call Callable.Call(Context, Scriptable, Scriptable, object[]) 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.

CallFunctionWithContinuations ( Callable function, Scriptable scope, object args ) : object

Call function that may pause execution by capturing a continuation.

Call function that may pause execution by capturing a continuation. Caller must be prepared to catch a ContinuationPending exception and resume execution by calling ResumeContinuation(object, Scriptable, object) .

CaptureContinuation ( ) : ContinuationPending

Capture a continuation from the current execution.

Capture a continuation from the current execution. The execution must have been started via a call to ExecuteScriptWithContinuations(Script, Scriptable) or CallFunctionWithContinuations(Callable, Scriptable, object[]) . This implies that the code calling this method must have been called as a function from the JavaScript script. Also, there cannot be any non-JavaScript code between the JavaScript frames (e.g., a call to eval()). The ContinuationPending exception returned must be thrown.

CheckLanguageVersion ( int version ) : void
CheckOptimizationLevel ( int optimizationLevel ) : void
CompileFunction ( Scriptable scope, string source, string sourceName, int lineno, object securityDomain ) : System.Function

Compile a JavaScript function.

Compile a JavaScript function.

The function source must be a function definition as defined by ECMA (e.g., "function f(a) { return a; }").

CompileReader ( TextReader @in, string sourceName, int lineno, object securityDomain ) : System.Script

Compiles the source in the given reader.

Compiles the source in the given reader.

Returns a script that may later be executed. Will consume all the source in the reader.

CompileString ( string source, string sourceName, int lineno, object securityDomain ) : System.Script

Compiles the source in the given string.

Compiles the source in the given string.

Returns a script that may later be executed.

CreateClassLoader ( ClassLoader parent ) : GeneratedClassLoader

Create class loader for generated classes.

Create class loader for generated classes. The method calls ContextFactory.CreateClassLoader(Sharpen.ClassLoader) using the result of GetFactory() .

DecompileFunction ( System.Function fun, int indent ) : string

Decompile a JavaScript Function.

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.

DecompileFunctionBody ( System.Function fun, int indent ) : string

Decompile the body of a JavaScript Function.

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.

DecompileScript ( System.Script script, int indent ) : string

Decompile the script.

Decompile the script.

The canonical source of the script is returned.

Enter ( ) : Context

Same as calling ContextFactory.EnterContext() on the global ContextFactory instance.

EvaluateReader ( Scriptable scope, TextReader @in, string sourceName, int lineno, object securityDomain ) : object

Evaluate a reader as JavaScript source.

Evaluate a reader as JavaScript source. All characters of the reader are consumed.

EvaluateString ( Scriptable scope, string source, string sourceName, int lineno, object securityDomain ) : object

Evaluate a JavaScript source string.

Evaluate a JavaScript source string. The provided source name and line number are used for error messages and for producing debug information.

ExecuteScriptWithContinuations ( System.Script script, Scriptable scope ) : object

Execute script that may pause execution by capturing a continuation.

Execute script that may pause execution by capturing a continuation. Caller must be prepared to catch a ContinuationPending exception and resume execution by calling ResumeContinuation(object, Scriptable, object) .

Exit ( ) : void

Exit a block of code requiring a Context.

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.

GetApplicationClassLoader ( ) : ClassLoader
GetClassShutterSetter ( ) : Context.ClassShutterSetter
GetCurrentContext ( ) : Context

Get the current Context.

Get the current Context. The current Context is per-thread; this method looks up the Context associated with the current thread.

GetDebuggableView ( System.Script script ) : DebuggableScript

Return DebuggableScript instance if any associated with the script.

Return DebuggableScript instance if any associated with the script. If callable supports DebuggableScript implementation, the method returns it. Otherwise null is returned.

GetDebugger ( ) : Debugger

Return the current debugger.

Return the current debugger.

GetDebuggerContextData ( ) : object

Return the debugger context data associated with current context.

Return the debugger context data associated with current context.

GetE4xImplementationFactory ( ) : XMLLib.Factory

Returns an object which specifies an E4X implementation to use within this Context.

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 .

GetElements ( Scriptable @object ) : object[]

Get the elements of a JavaScript array.

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.

GetErrorReporter ( ) : ErrorReporter

Get the current error reporter.

Get the current error reporter.

GetFactory ( ) : ContextFactory

Return ContextFactory instance used to create this Context.

GetImplementationVersion ( ) : string

Get the implementation version.

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".
GetInstructionObserverThreshold ( ) : int

Get threshold of executed instructions counter that triggers call to observeInstructionCount().

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 ( ) : int

Get the current language version.

Get the current language version.

The language version number affects JavaScript semantics as detailed in the overview documentation.

GetLocale ( ) : CultureInfo

Get the current locale.

Get the current locale. Returns the default locale if none has been set.

GetMaximumInterpreterStackDepth ( ) : int

Returns the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter.

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.

GetOptimizationLevel ( ) : int

Get the current optimization level.

Get the current optimization level.

The optimization level is expressed as an integer between -1 and 9.

GetThreadLocal ( object key ) : object

Get a value corresponding to a 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. 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.

GetUndefinedValue ( ) : object

Get the singleton object that represents the JavaScript Undefined value.

Get the singleton object that represents the JavaScript Undefined value.

GetWrapFactory ( ) : WrapFactory

Return the current WrapFactory, or null if none is defined.

Return the current WrapFactory, or null if none is defined.

HasFeature ( int featureIndex ) : bool

Controls certain aspects of script semantics.

Controls certain aspects of script semantics. Should be overwritten to alter default behavior.

The default implementation calls ContextFactory.HasFeature(Context, int) that allows to customize Context behavior without introducing Context subclasses. ContextFactory documentation gives an example of hasFeature implementation.

InitStandardObjects ( ScriptableObject scope ) : Scriptable

Initialize the standard objects.

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.

InitStandardObjects ( ) : ScriptableObject

Initialize the standard objects.

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.

InitStandardObjects ( ScriptableObject scope, bool @sealed ) : ScriptableObject

Initialize the standard objects.

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.

IsActivationNeeded ( string name ) : bool

Check whether the name is in the list of names of objects forcing the creation of activation objects.

Check whether the name is in the list of names of objects forcing the creation of activation objects.

IsGeneratingDebug ( ) : bool

Tell whether debug information is being generated.

Tell whether debug information is being generated.

IsGeneratingDebugChanged ( ) : bool
IsGeneratingSource ( ) : bool

Tell whether source information is being generated.

Tell whether source information is being generated.

IsSealed ( ) : bool

Checks if this is a sealed Context.

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.

IsValidLanguageVersion ( int version ) : bool
IsValidOptimizationLevel ( int optimizationLevel ) : bool
JavaToJS ( object value, Scriptable scope ) : object

Convenient method to convert java value to its closest representation in JavaScript.

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, Scriptable, object, System.Type<T>) as in:

 Context cx = Context.getCurrentContext(); return cx.getWrapFactory().wrap(cx, scope, value, null); 
JsToJava ( object value, Type desiredType ) : object

Convert a JavaScript value into the desired type.

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.

NewArray ( Scriptable scope, int length ) : Scriptable

Create an array with a specified initial length.

Create an array with a specified initial length.

NewArray ( Scriptable scope, object elements ) : Scriptable

Create an array with a set of initial elements.

Create an array with a set of initial elements.

NewObject ( Scriptable scope ) : Scriptable

Create a new JavaScript object.

Create a new JavaScript object. Equivalent to evaluating "new Object()".

NewObject ( Scriptable scope, string constructorName ) : Scriptable

Create a new JavaScript object by executing the named constructor.

Create a new JavaScript object by executing the named constructor. The call newObject(scope, "Foo") is equivalent to evaluating "new Foo()".

NewObject ( Scriptable scope, string constructorName, object args ) : Scriptable

Creates a new JavaScript object by executing the named constructor.

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.
PutThreadLocal ( object key, object value ) : void

Put a value that can later be retrieved using a given key.

Put a value that can later be retrieved using a given key.

RemoveActivationName ( string name ) : void

Remove a name from the list of names forcing the creation of real activation objects for functions.

Remove a name from the list of names forcing the creation of real activation objects for functions.

RemovePropertyChangeListener ( PropertyChangeListener l ) : void

Remove an object from the list of objects registered to receive notification of changes to a bounded property

RemoveThreadLocal ( object key ) : void

Remove values from thread-local storage.

Remove values from thread-local storage.

ReportError ( string message ) : void

Report an error using the error reporter for the current thread.

Report an error using the error reporter for the current thread.

ReportError ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : void

Report an error using the error reporter for the current thread.

Report an error using the error reporter for the current thread.

ReportRuntimeError ( string message ) : EvaluatorException

Report a runtime error using the error reporter for the current thread.

Report a runtime error using the error reporter for the current thread.

ReportRuntimeError ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : EvaluatorException

Report a runtime error using the error reporter for the current thread.

Report a runtime error using the error reporter for the current thread.

ReportWarning ( string message ) : void

Report a warning using the error reporter for the current thread.

Report a warning using the error reporter for the current thread.

ReportWarning ( string message, Exception t ) : void
ReportWarning ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : void

Report a warning using the error reporter for the current thread.

Report a warning using the error reporter for the current thread.

ResumeContinuation ( object continuation, Scriptable scope, object functionResult ) : object

Restarts execution of the JavaScript suspended at the call to CaptureContinuation() . Execution of the code will resume with the functionResult as the result of the call that captured the continuation. Execution of the script will either conclude normally and the result returned, another continuation will be captured and thrown, or the script will terminate abnormally and throw an exception.

Seal ( object sealKey ) : void

Seal this Context object so any attempt to modify any of its properties including calling Enter() and Exit() methods will throw an exception.

If sealKey is not null, calling Unseal(object) with the same key unseals the object. If sealKey is null, unsealing is no longer possible.

SetApplicationClassLoader ( ClassLoader loader ) : void
SetClassShutter ( ClassShutter shutter ) : void

Set the LiveConnect access filter for this context.

Set the LiveConnect access filter for this context.

ClassShutter may only be set if it is currently null. Otherwise a SecurityException is thrown.

SetDebugger ( Debugger debugger, object contextData ) : void

Set the associated debugger.

Set the associated debugger.

SetErrorReporter ( ErrorReporter reporter ) : ErrorReporter

Change the current error reporter.

Change the current error reporter.

SetGenerateObserverCount ( bool generateObserverCount ) : void

Turn on or off generation of code with callbacks to track the count of executed instructions.

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.

SetGeneratingDebug ( bool generatingDebug ) : void

Specify whether or not debug information should be generated.

Specify whether or not debug information should be generated.

Setting the generation of debug information on will set the optimization level to zero.

SetGeneratingSource ( bool generatingSource ) : void

Specify whether or not source information should be generated.

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.

SetInstructionObserverThreshold ( int threshold ) : void

Set threshold of executed instructions counter that triggers call to observeInstructionCount().

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. SetGenerateObserverCount(bool) is called with true if threshold is greater than zero, false otherwise.

SetLanguageVersion ( int version ) : void

Set the language version.

Set the language version.

Setting the language version will affect functions and scripts compiled subsequently. See the overview documentation for version-specific behavior.

SetLocale ( CultureInfo loc ) : CultureInfo

Set the current locale.

Set the current locale.

SetMaximumInterpreterStackDepth ( int max ) : void

Sets the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter.

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.

SetOptimizationLevel ( int optimizationLevel ) : void

Set the current optimization level.

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.

SetSecurityController ( SecurityController controller ) : void

Set the security controller for this context.

Set the security controller for this context.

SecurityController may only be set if it is currently null and SecurityController.HasGlobal() is false. Otherwise a SecurityException is thrown.

SetWrapFactory ( WrapFactory wrapFactory ) : void

Set a WrapFactory for this Context.

Set a WrapFactory for this Context.

The WrapFactory allows custom object wrapping behavior for Java object manipulated with JavaScript.

StringIsCompilableUnit ( string source ) : bool

Check whether a string is ready to be compiled.

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.

ThrowAsScriptRuntimeEx ( Exception e ) : Exception

Rethrow the exception wrapping it as the script runtime exception.

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.
ToBoolean ( object value ) : bool

Convert the value to a JavaScript boolean value.

Convert the value to a JavaScript boolean value.

See ECMA 9.2.

ToNumber ( object value ) : double

Convert the value to a JavaScript Number value.

Convert the value to a JavaScript Number value.

Returns a Java double for the JavaScript Number.

See ECMA 9.3.

ToObject ( object value, Scriptable scope ) : Scriptable

Convert the value to an JavaScript object value.

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.

ToString ( object value ) : string

Convert the value to a JavaScript String value.

Convert the value to a JavaScript String value.

See ECMA 9.8.

Unseal ( object sealKey ) : void

Unseal previously sealed Context object.

Unseal previously sealed Context object. The sealKey argument should not be null and should match sealKey suplied with the last call to Seal(object) or an exception will be thrown.

Protected Methods

Method Description
Context ( ContextFactory factory ) : System

Creates a new context.

Creates a new context. Provided as a preferred super constructor for subclasses in place of the deprecated default public constructor.

ObserveInstructionCount ( int instructionCount ) : void

Allow application to monitor counter of executed script instructions in Context subclasses.

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 default implementation calls ContextFactory.ObserveInstructionCount(Context, int) that allows to customize Context behavior without introducing Context subclasses.

Private Methods

Method Description
AddContextListener ( ContextListener listener ) : void
Call ( ContextAction action ) : object
Call ( ContextFactory factory, ContextAction action ) : object

The method implements ContextFactory.Call(ContextAction) logic.

CompileFunction ( Scriptable scope, string source, Evaluator compiler, ErrorReporter compilationErrorReporter, string sourceName, int lineno, object securityDomain ) : System.Function
CompileImpl ( Scriptable scope, TextReader sourceReader, string sourceString, string sourceName, int lineno, object securityDomain, bool returnFunction, Evaluator compiler, ErrorReporter compilationErrorReporter ) : object
CompileReader ( Scriptable scope, TextReader @in, string sourceName, int lineno, object securityDomain ) : System.Script
CompileString ( string source, Evaluator compiler, ErrorReporter compilationErrorReporter, string sourceName, int lineno, object securityDomain ) : System.Script
Context ( ) : System
CreateCompiler ( ) : Evaluator
CreateInterpreter ( ) : Evaluator
Enter ( Rhino cx ) : Context
Enter ( Rhino cx, ContextFactory factory ) : Context
FirePropertyChange ( string property, object oldValue, object newValue ) : void

Notify any registered listeners that a bounded property has changed

FirePropertyChangeImpl ( object listeners, string property, object oldValue, object newValue ) : void
GetClassShutter ( ) : ClassShutter
GetContext ( ) : Context

Internal method that reports an error for missing calls to enter().

Internal method that reports an error for missing calls to enter().

GetRegExpProxy ( ) : RegExpProxy
GetSecurityController ( ) : SecurityController
GetSourcePositionFromStack ( int linep ) : string
IsVersionECMA1 ( ) : bool
NotifyDebugger_r ( Context cx, DebuggableScript dscript, string debugSource ) : void
OnSealedMutation ( ) : void
RemoveContextListener ( ContextListener listener ) : void
ReportRuntimeError0 ( string messageId ) : EvaluatorException
ReportRuntimeError1 ( string messageId, object arg1 ) : EvaluatorException
ReportRuntimeError2 ( string messageId, object arg1, object arg2 ) : EvaluatorException
ReportRuntimeError3 ( string messageId, object arg1, object arg2, object arg3 ) : EvaluatorException
ReportRuntimeError4 ( string messageId, object arg1, object arg2, object arg3, object arg4 ) : EvaluatorException
SetCachingEnabled ( bool cachingEnabled ) : void
ToObject ( object value, Scriptable scope, Type staticType ) : Scriptable
ToType ( object value, Type desiredType ) : object

Method Details

AddActivationName() public method

Add a name to the list of names forcing the creation of real activation objects for functions.
Add a name to the list of names forcing the creation of real activation objects for functions.
public AddActivationName ( string name ) : void
name string the name of the object to add to the list
return void

AddPropertyChangeListener() public method

Register an object to receive notifications when a bound property has changed
public AddPropertyChangeListener ( PropertyChangeListener l ) : void
l PropertyChangeListener the listener
return void

Call() public static method

Call Callable.Call(Context, Scriptable, Scriptable, object[]) 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.

public static Call ( ContextFactory factory, Callable callable, Scriptable scope, Scriptable thisObj, object args ) : object
factory ContextFactory
callable Callable
scope Scriptable
thisObj Scriptable
args object
return object

CallFunctionWithContinuations() public method

Call function that may pause execution by capturing a continuation.
Call function that may pause execution by capturing a continuation. Caller must be prepared to catch a ContinuationPending exception and resume execution by calling ResumeContinuation(object, Scriptable, object) .
/// if the script calls a function that results /// in a call to /// CaptureContinuation() ///
public CallFunctionWithContinuations ( Callable function, Scriptable scope, object args ) : object
function Callable /// The function to call. The function must have been /// compiled with interpreted mode (optimization level -1) ///
scope Scriptable The scope to execute the script against
args object The arguments for the function
return object

CaptureContinuation() public method

Capture a continuation from the current execution.
Capture a continuation from the current execution. The execution must have been started via a call to ExecuteScriptWithContinuations(Script, Scriptable) or CallFunctionWithContinuations(Callable, Scriptable, object[]) . This implies that the code calling this method must have been called as a function from the JavaScript script. Also, there cannot be any non-JavaScript code between the JavaScript frames (e.g., a call to eval()). The ContinuationPending exception returned must be thrown.
public CaptureContinuation ( ) : ContinuationPending
return ContinuationPending

CheckLanguageVersion() public static method

public static CheckLanguageVersion ( int version ) : void
version int
return void

CheckOptimizationLevel() public static method

public static CheckOptimizationLevel ( int optimizationLevel ) : void
optimizationLevel int
return void

CompileFunction() public method

Compile a JavaScript function.
Compile a JavaScript function.

The function source must be a function definition as defined by ECMA (e.g., "function f(a) { return a; }").

public CompileFunction ( Scriptable scope, string source, string sourceName, int lineno, object securityDomain ) : System.Function
scope Scriptable the scope to compile relative to
source string the function definition source
sourceName string a string describing the source, such as a filename
lineno int the starting line number
securityDomain object /// 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. ///
return System.Function

CompileReader() public method

Compiles the source in the given reader.
Compiles the source in the given reader.

Returns a script that may later be executed. Will consume all the source in the reader.

/// IOException /// if an IOException was generated by the Reader ///
public CompileReader ( TextReader @in, string sourceName, int lineno, object securityDomain ) : System.Script
@in System.IO.TextReader
sourceName string a string describing the source, such as a filename
lineno int the starting line number for reporting errors
securityDomain object /// 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. ///
return System.Script

CompileString() public method

Compiles the source in the given string.
Compiles the source in the given string.

Returns a script that may later be executed.

public CompileString ( string source, string sourceName, int lineno, object securityDomain ) : System.Script
source string the source string
sourceName string a string describing the source, such as a filename
lineno int /// the starting line number for reporting errors. Use /// 0 if the line number is unknown. ///
securityDomain object /// 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. ///
return System.Script

Context() protected method

Creates a new context.
Creates a new context. Provided as a preferred super constructor for subclasses in place of the deprecated default public constructor.
if factory parameter is null.
protected Context ( ContextFactory factory ) : System
factory ContextFactory /// the context factory associated with this context (most /// likely, the one that created the context). Can not be null. The context /// features are inherited from the factory, and the context will also /// otherwise use its factory's services. ///
return System

CreateClassLoader() public method

Create class loader for generated classes.
Create class loader for generated classes. The method calls ContextFactory.CreateClassLoader(Sharpen.ClassLoader) using the result of GetFactory() .
public CreateClassLoader ( ClassLoader parent ) : GeneratedClassLoader
parent ClassLoader
return GeneratedClassLoader

DecompileFunction() public method

Decompile a JavaScript Function.
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.

public DecompileFunction ( System.Function fun, int indent ) : string
fun System.Function the JavaScript function to decompile
indent int the number of spaces to indent the result
return string

DecompileFunctionBody() public method

Decompile the body of a JavaScript Function.
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.

public DecompileFunctionBody ( System.Function fun, int indent ) : string
fun System.Function the JavaScript function to decompile
indent int the number of spaces to indent the result
return string

DecompileScript() public method

Decompile the script.
Decompile the script.

The canonical source of the script is returned.

public DecompileScript ( System.Script script, int indent ) : string
script System.Script the script to decompile
indent int the number of spaces to indent the result
return string

Enter() public static method

Same as calling ContextFactory.EnterContext() on the global ContextFactory instance.
public static Enter ( ) : Context
return Context

EvaluateReader() public method

Evaluate a reader as JavaScript source.
Evaluate a reader as JavaScript source. All characters of the reader are consumed.
/// IOException /// if an IOException was generated by the Reader ///
public EvaluateReader ( Scriptable scope, TextReader @in, string sourceName, int lineno, object securityDomain ) : object
scope Scriptable the scope to execute in
@in System.IO.TextReader
sourceName string a string describing the source, such as a filename
lineno int the starting line number
securityDomain object /// 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. ///
return object

EvaluateString() public method

Evaluate a JavaScript source string.
Evaluate a JavaScript source string. The provided source name and line number are used for error messages and for producing debug information.
public EvaluateString ( Scriptable scope, string source, string sourceName, int lineno, object securityDomain ) : object
scope Scriptable the scope to execute in
source string the JavaScript source
sourceName string a string describing the source, such as a filename
lineno int the starting line number
securityDomain object /// 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. ///
return object

ExecuteScriptWithContinuations() public method

Execute script that may pause execution by capturing a continuation.
Execute script that may pause execution by capturing a continuation. Caller must be prepared to catch a ContinuationPending exception and resume execution by calling ResumeContinuation(object, Scriptable, object) .
/// if the script calls a function that results /// in a call to /// CaptureContinuation() ///
public ExecuteScriptWithContinuations ( System.Script script, Scriptable scope ) : object
script System.Script /// The script to execute. Script must have been compiled /// with interpreted mode (optimization level -1) ///
scope Scriptable The scope to execute the script against
return object

Exit() public static method

Exit a block of code requiring a Context.
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.
public static Exit ( ) : void
return void

GetApplicationClassLoader() public method

public GetApplicationClassLoader ( ) : ClassLoader
return ClassLoader

GetClassShutterSetter() public method

public GetClassShutterSetter ( ) : Context.ClassShutterSetter
return Context.ClassShutterSetter

GetCurrentContext() public static method

Get the current Context.
Get the current Context. The current Context is per-thread; this method looks up the Context associated with the current thread.

public static GetCurrentContext ( ) : Context
return Context

GetDebuggableView() public static method

Return DebuggableScript instance if any associated with the script.
Return DebuggableScript instance if any associated with the script. If callable supports DebuggableScript implementation, the method returns it. Otherwise null is returned.
public static GetDebuggableView ( System.Script script ) : DebuggableScript
script System.Script
return DebuggableScript

GetDebugger() public method

Return the current debugger.
Return the current debugger.
public GetDebugger ( ) : Debugger
return Debugger

GetDebuggerContextData() public method

Return the debugger context data associated with current context.
Return the debugger context data associated with current context.
public GetDebuggerContextData ( ) : object
return object

GetE4xImplementationFactory() public method

Returns an object which specifies an E4X implementation to use within this Context.
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 .
public GetE4xImplementationFactory ( ) : XMLLib.Factory
return Rhino.Xml.XMLLib.Factory

GetElements() public method

Get the elements of a JavaScript array.
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.

public GetElements ( Scriptable @object ) : object[]
@object Scriptable
return object[]

GetErrorReporter() public method

Get the current error reporter.
Get the current error reporter.
public GetErrorReporter ( ) : ErrorReporter
return ErrorReporter

GetFactory() public method

Return ContextFactory instance used to create this Context.
public GetFactory ( ) : ContextFactory
return ContextFactory

GetImplementationVersion() public method

Get the implementation version.
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".
public GetImplementationVersion ( ) : string
return string

GetInstructionObserverThreshold() public method

Get threshold of executed instructions counter that triggers call to observeInstructionCount().
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.
public GetInstructionObserverThreshold ( ) : int
return int

GetLanguageVersion() public method

Get the current language version.
Get the current language version.

The language version number affects JavaScript semantics as detailed in the overview documentation.

public GetLanguageVersion ( ) : int
return int

GetLocale() public method

Get the current locale.
Get the current locale. Returns the default locale if none has been set.
public GetLocale ( ) : CultureInfo
return System.Globalization.CultureInfo

GetMaximumInterpreterStackDepth() public method

Returns the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter.
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.
public GetMaximumInterpreterStackDepth ( ) : int
return int

GetOptimizationLevel() public method

Get the current optimization level.
Get the current optimization level.

The optimization level is expressed as an integer between -1 and 9.

public GetOptimizationLevel ( ) : int
return int

GetThreadLocal() public method

Get a value corresponding to a 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. 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.

public GetThreadLocal ( object key ) : object
key object the key used to lookup the value
return object

GetUndefinedValue() public static method

Get the singleton object that represents the JavaScript Undefined value.
Get the singleton object that represents the JavaScript Undefined value.
public static GetUndefinedValue ( ) : object
return object

GetWrapFactory() public method

Return the current WrapFactory, or null if none is defined.
Return the current WrapFactory, or null if none is defined.
public GetWrapFactory ( ) : WrapFactory
return WrapFactory

HasFeature() public method

Controls certain aspects of script semantics.
Controls certain aspects of script semantics. Should be overwritten to alter default behavior.

The default implementation calls ContextFactory.HasFeature(Context, int) that allows to customize Context behavior without introducing Context subclasses. ContextFactory documentation gives an example of hasFeature implementation.

public HasFeature ( int featureIndex ) : bool
featureIndex int feature index to check
return bool

InitStandardObjects() public method

Initialize the standard objects.
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.

public InitStandardObjects ( ScriptableObject scope ) : Scriptable
scope ScriptableObject /// the scope to initialize, or null, in which case a new /// object will be created to serve as the scope ///
return Scriptable

InitStandardObjects() public method

Initialize the standard objects.
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.

public InitStandardObjects ( ) : ScriptableObject
return ScriptableObject

InitStandardObjects() public method

Initialize the standard objects.
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.

public InitStandardObjects ( ScriptableObject scope, bool @sealed ) : ScriptableObject
scope ScriptableObject /// the scope to initialize, or null, in which case a new /// object will be created to serve as the scope ///
@sealed bool
return ScriptableObject

IsActivationNeeded() public method

Check whether the name is in the list of names of objects forcing the creation of activation objects.
Check whether the name is in the list of names of objects forcing the creation of activation objects.
public IsActivationNeeded ( string name ) : bool
name string the name of the object to test
return bool

IsGeneratingDebug() public method

Tell whether debug information is being generated.
Tell whether debug information is being generated.
public IsGeneratingDebug ( ) : bool
return bool

IsGeneratingDebugChanged() public method

public IsGeneratingDebugChanged ( ) : bool
return bool

IsGeneratingSource() public method

Tell whether source information is being generated.
Tell whether source information is being generated.
public IsGeneratingSource ( ) : bool
return bool

IsSealed() public method

Checks if this is a sealed Context.
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.
public IsSealed ( ) : bool
return bool

IsValidLanguageVersion() public static method

public static IsValidLanguageVersion ( int version ) : bool
version int
return bool

IsValidOptimizationLevel() public static method

public static IsValidOptimizationLevel ( int optimizationLevel ) : bool
optimizationLevel int
return bool

JavaToJS() public static method

Convenient method to convert java value to its closest representation in JavaScript.
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, Scriptable, object, System.Type<T>) as in:

 Context cx = Context.getCurrentContext(); return cx.getWrapFactory().wrap(cx, scope, value, null); 
public static JavaToJS ( object value, Scriptable scope ) : object
value object any Java object
scope Scriptable top scope object
return object

JsToJava() public static method

Convert a JavaScript value into the desired type.
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.
if the conversion cannot be performed
public static JsToJava ( object value, Type desiredType ) : object
value object the JavaScript value to convert
desiredType System.Type /// the Java type to convert to. Primitive Java /// types are represented using the TYPE fields in the corresponding /// wrapper class in java.lang. ///
return object

NewArray() public method

Create an array with a specified initial length.
Create an array with a specified initial length.

public NewArray ( Scriptable scope, int length ) : Scriptable
scope Scriptable the scope to create the object in
length int /// the initial length (JavaScript arrays may have /// additional properties added dynamically). ///
return Scriptable

NewArray() public method

Create an array with a set of initial elements.
Create an array with a set of initial elements.
public NewArray ( Scriptable scope, object elements ) : Scriptable
scope Scriptable the scope to create the object in.
elements object /// the initial elements. Each object in this array /// must be an acceptable JavaScript type and type /// of array should be exactly Object[], not /// SomeObjectSubclass[]. ///
return Scriptable

NewObject() public method

Create a new JavaScript object.
Create a new JavaScript object. Equivalent to evaluating "new Object()".
public NewObject ( Scriptable scope ) : Scriptable
scope Scriptable /// the scope to search for the constructor and to evaluate /// against ///
return Scriptable

NewObject() public method

Create a new JavaScript object by executing the named constructor.
Create a new JavaScript object by executing the named constructor. The call newObject(scope, "Foo") is equivalent to evaluating "new Foo()".
public NewObject ( Scriptable scope, string constructorName ) : Scriptable
scope Scriptable the scope to search for the constructor and to evaluate against
constructorName string the name of the constructor to call
return Scriptable

NewObject() public method

Creates a new JavaScript object by executing the named constructor.
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.
public NewObject ( Scriptable scope, string constructorName, object args ) : Scriptable
scope Scriptable /// The scope to search for the constructor and to evaluate /// against ///
constructorName string the name of the constructor to call
args object the array of arguments for the constructor
return Scriptable

ObserveInstructionCount() protected method

Allow application to monitor counter of executed script instructions in Context subclasses.
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 default implementation calls ContextFactory.ObserveInstructionCount(Context, int) that allows to customize Context behavior without introducing Context subclasses.

to terminate the script
protected ObserveInstructionCount ( int instructionCount ) : void
instructionCount int /// amount of script instruction executed since /// last call to observeInstructionCount ///
return void

PutThreadLocal() public method

Put a value that can later be retrieved using a given key.
Put a value that can later be retrieved using a given key.

public PutThreadLocal ( object key, object value ) : void
key object the key used to index the value
value object the value to save
return void

RemoveActivationName() public method

Remove a name from the list of names forcing the creation of real activation objects for functions.
Remove a name from the list of names forcing the creation of real activation objects for functions.
public RemoveActivationName ( string name ) : void
name string the name of the object to remove from the list
return void

RemovePropertyChangeListener() public method

Remove an object from the list of objects registered to receive notification of changes to a bounded property
public RemovePropertyChangeListener ( PropertyChangeListener l ) : void
l PropertyChangeListener the listener
return void

RemoveThreadLocal() public method

Remove values from thread-local storage.
Remove values from thread-local storage.
public RemoveThreadLocal ( object key ) : void
key object the key for the entry to remove.
return void

ReportError() public static method

Report an error using the error reporter for the current thread.
Report an error using the error reporter for the current thread.
public static ReportError ( string message ) : void
message string the error message to report
return void

ReportError() public static method

Report an error using the error reporter for the current thread.
Report an error using the error reporter for the current thread.
public static ReportError ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : void
message string the error message to report
sourceName string a string describing the source, such as a filename
lineno int the starting line number
lineSource string the text of the line (may be null)
lineOffset int the offset into lineSource where problem was detected
return void

ReportRuntimeError() public static method

Report a runtime error using the error reporter for the current thread.
Report a runtime error using the error reporter for the current thread.
public static ReportRuntimeError ( string message ) : EvaluatorException
message string the error message to report
return EvaluatorException

ReportRuntimeError() public static method

Report a runtime error using the error reporter for the current thread.
Report a runtime error using the error reporter for the current thread.
public static ReportRuntimeError ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : EvaluatorException
message string the error message to report
sourceName string a string describing the source, such as a filename
lineno int the starting line number
lineSource string the text of the line (may be null)
lineOffset int the offset into lineSource where problem was detected
return EvaluatorException

ReportWarning() public static method

Report a warning using the error reporter for the current thread.
Report a warning using the error reporter for the current thread.
public static ReportWarning ( string message ) : void
message string the warning message to report
return void

ReportWarning() public static method

public static ReportWarning ( string message, Exception t ) : void
message string
t System.Exception
return void

ReportWarning() public static method

Report a warning using the error reporter for the current thread.
Report a warning using the error reporter for the current thread.
public static ReportWarning ( string message, string sourceName, int lineno, string lineSource, int lineOffset ) : void
message string the warning message to report
sourceName string a string describing the source, such as a filename
lineno int the starting line number
lineSource string the text of the line (may be null)
lineOffset int the offset into lineSource where problem was detected
return void

ResumeContinuation() public method

Restarts execution of the JavaScript suspended at the call to CaptureContinuation() . Execution of the code will resume with the functionResult as the result of the call that captured the continuation. Execution of the script will either conclude normally and the result returned, another continuation will be captured and thrown, or the script will terminate abnormally and throw an exception.
/// if another continuation is captured before /// the code terminates ///
public ResumeContinuation ( object continuation, Scriptable scope, object functionResult ) : object
continuation object /// The value returned by /// ContinuationPending.GetContinuation() ///
scope Scriptable
functionResult object /// This value will appear to the code being resumed /// as the result of the function that captured the continuation ///
return object

Seal() public method

Seal this Context object so any attempt to modify any of its properties including calling Enter() and Exit() methods will throw an exception.

If sealKey is not null, calling Unseal(object) with the same key unseals the object. If sealKey is null, unsealing is no longer possible.

public Seal ( object sealKey ) : void
sealKey object
return void

SetApplicationClassLoader() public method

public SetApplicationClassLoader ( ClassLoader loader ) : void
loader ClassLoader
return void

SetClassShutter() public method

Set the LiveConnect access filter for this context.
Set the LiveConnect access filter for this context.

ClassShutter may only be set if it is currently null. Otherwise a SecurityException is thrown.

/// if there is already a ClassShutter /// object for this Context ///
public SetClassShutter ( ClassShutter shutter ) : void
shutter ClassShutter a ClassShutter object
return void

SetDebugger() public method

Set the associated debugger.
Set the associated debugger.
public SetDebugger ( Debugger debugger, object contextData ) : void
debugger Debugger /// the debugger to be used on callbacks from /// the engine. ///
contextData object /// arbitrary object that debugger can use to store /// per Context data. ///
return void

SetErrorReporter() public method

Change the current error reporter.
Change the current error reporter.
public SetErrorReporter ( ErrorReporter reporter ) : ErrorReporter
reporter ErrorReporter
return ErrorReporter

SetGenerateObserverCount() public method

Turn on or off generation of code with callbacks to track the count of executed instructions.
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.
public SetGenerateObserverCount ( bool generateObserverCount ) : void
generateObserverCount bool /// if true, generated code will contain /// calls to accumulate an estimate of the instructions executed. ///
return void

SetGeneratingDebug() public method

Specify whether or not debug information should be generated.
Specify whether or not debug information should be generated.

Setting the generation of debug information on will set the optimization level to zero.

public SetGeneratingDebug ( bool generatingDebug ) : void
generatingDebug bool
return void

SetGeneratingSource() public method

Specify whether or not source information should be generated.
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.

public SetGeneratingSource ( bool generatingSource ) : void
generatingSource bool
return void

SetInstructionObserverThreshold() public method

Set threshold of executed instructions counter that triggers call to observeInstructionCount().
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. SetGenerateObserverCount(bool) is called with true if threshold is greater than zero, false otherwise.

public SetInstructionObserverThreshold ( int threshold ) : void
threshold int The instruction threshold
return void

SetLanguageVersion() public method

Set the language version.
Set the language version.

Setting the language version will affect functions and scripts compiled subsequently. See the overview documentation for version-specific behavior.

public SetLanguageVersion ( int version ) : void
version int the version as specified by VERSION_1_0, VERSION_1_1, etc.
return void

SetLocale() public method

Set the current locale.
Set the current locale.
public SetLocale ( CultureInfo loc ) : CultureInfo
loc CultureInfo
return CultureInfo

SetMaximumInterpreterStackDepth() public method

Sets the maximum stack depth (in terms of number of call frames) allowed in a single invocation of interpreter.
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.
/// if this context's optimization level is not /// -1 /// if the new depth is not at least 1
public SetMaximumInterpreterStackDepth ( int max ) : void
max int the new maximum interpreter stack depth
return void

SetOptimizationLevel() public method

Set the current optimization level.
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.

public SetOptimizationLevel ( int optimizationLevel ) : void
optimizationLevel int /// an integer indicating the level of /// optimization to perform ///
return void

SetSecurityController() public method

Set the security controller for this context.
Set the security controller for this context.

SecurityController may only be set if it is currently null and SecurityController.HasGlobal() is false. Otherwise a SecurityException is thrown.

/// if there is already a SecurityController /// object for this Context or globally installed. ///
public SetSecurityController ( SecurityController controller ) : void
controller SecurityController a SecurityController object
return void

SetWrapFactory() public method

Set a WrapFactory for this Context.
Set a WrapFactory for this Context.

The WrapFactory allows custom object wrapping behavior for Java object manipulated with JavaScript.

public SetWrapFactory ( WrapFactory wrapFactory ) : void
wrapFactory WrapFactory
return void

StringIsCompilableUnit() public method

Check whether a string is ready to be compiled.
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.

public StringIsCompilableUnit ( string source ) : bool
source string the source buffer to check
return bool

ThrowAsScriptRuntimeEx() public static method

Rethrow the exception wrapping it as the script runtime exception.
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.
EvaluatorException EcmaError
public static ThrowAsScriptRuntimeEx ( Exception e ) : Exception
e Exception
return Exception

ToBoolean() public static method

Convert the value to a JavaScript boolean value.
Convert the value to a JavaScript boolean value.

See ECMA 9.2.

public static ToBoolean ( object value ) : bool
value object a JavaScript value
return bool

ToNumber() public static method

Convert the value to a JavaScript Number value.
Convert the value to a JavaScript Number value.

Returns a Java double for the JavaScript Number.

See ECMA 9.3.

public static ToNumber ( object value ) : double
value object a JavaScript value
return double

ToObject() public static method

Convert the value to an JavaScript object value.
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.

public static ToObject ( object value, Scriptable scope ) : Scriptable
value object any Java object
scope Scriptable /// global scope containing constructors for Number, /// Boolean, and String ///
return Scriptable

ToString() public static method

Convert the value to a JavaScript String value.
Convert the value to a JavaScript String value.

See ECMA 9.8.

public static ToString ( object value ) : string
value object a JavaScript value
return string

Unseal() public method

Unseal previously sealed Context object.
Unseal previously sealed Context object. The sealKey argument should not be null and should match sealKey suplied with the last call to Seal(object) or an exception will be thrown.
public Unseal ( object sealKey ) : void
sealKey object
return void

Property Details

emptyArgs public_oe static_oe property

Convenient value to use as zero-length array of objects.
Convenient value to use as zero-length array of objects.
public static object[] emptyArgs
return object[]

generateObserverCount public_oe property

public bool generateObserverCount
return bool