C# Class MsieJavaScriptEngine.JsRt.JavaScriptContext

A script context.

Each script context contains its own global object, distinct from the global object in other script contexts.

Many Chakra hosting APIs require an "active" script context, which can be set using Current. Chakra hosting APIs that require a current context to be set will note that explicitly in their documentation.

Show file Open project: klumsy/PowerShellJS Class Usage Examples

Public Methods

Method Description
AddRef ( ) : uint

Adds a reference to a script context.

Calling AddRef ensures that the context will not be freed until Release is called.

EnumerateHeap ( ) : Native.IActiveScriptProfilerHeapEnum

Enumerates the heap of the current context.

While the heap is being enumerated, the current context cannot be removed, and all calls to modify the state of the context will fail until the heap enumerator is released.

Requires an active script context.

GetAndClearException ( ) : JavaScriptValue

Returns the exception that caused the runtime of the current context to be in the exception state and resets the exception state for that runtime.

If the runtime of the current context is not in an exception state, this API will throw JsErrorInvalidArgument. If the runtime is disabled, this will return an exception indicating that the script was terminated, but it will not clear the exception (the exception will be cleared if the runtime is re-enabled using EnableRuntimeExecution).

Requires an active script context.

Idle ( ) : uint

Tells the runtime to do any idle processing it need to do.

If idle processing has been enabled for the current runtime, calling Idle will inform the current runtime that the host is idle and that the runtime can perform memory cleanup tasks.

Idle will also return the number of system ticks until there will be more idle work for the runtime to do. Calling Idle before this number of ticks has passed will do no work.

Requires an active script context.

ParseScript ( string script ) : JavaScriptValue

Parses a script and returns a Function representing the script.

Requires an active script context.

ParseScript ( string script, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue

Parses a script and returns a Function representing the script.

Requires an active script context.

ParseScript ( string script, byte buffer ) : JavaScriptValue

Parses a serialized script and returns a Function representing the script.

Requires an active script context.

ParseScript ( string script, byte buffer, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue

Parses a serialized script and returns a Function representing the script.

Requires an active script context.

Release ( ) : uint

Releases a reference to a script context.

Removes a reference to a context that was created by AddRef.

RunScript ( string script ) : JavaScriptValue

Executes a script.

Requires an active script context.

RunScript ( string script, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue

Executes a script.

Requires an active script context.

RunScript ( string script, byte buffer ) : JavaScriptValue

Runs a serialized script.

Requires an active script context.

RunScript ( string script, byte buffer, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue

Runs a serialized script.

Requires an active script context.

SerializeScript ( string script, byte buffer ) : ulong

Serializes a parsed script to a buffer than can be reused.

SerializeScript parses a script and then stores the parsed form of the script in a runtime-independent format. The serialized script then can be deserialized in any runtime without requiring the script to be re-parsed.

Requires an active script context.

SetException ( JavaScriptValue exception ) : void

Sets the runtime of the current context to an exception state.

If the runtime of the current context is already in an exception state, this API will throw JsErrorInExceptionState.

Requires an active script context.

StartDebugging ( Native debugApplication ) : void

Starts debugging in the context.

StartProfiling ( Native callback, Native eventMask, int context ) : void

Starts profiling in the current context.

Requires an active script context.

StopProfiling ( int reason ) : void

Stops profiling in the current context.

Will not return an error if profiling has not started.

Requires an active script context.

Private Methods

Method Description
JavaScriptContext ( IntPtr reference ) : System

Initializes a new instance of the JavaScriptContext struct.

Method Details

AddRef() public method

Adds a reference to a script context.
Calling AddRef ensures that the context will not be freed until Release is called.
public AddRef ( ) : uint
return uint

EnumerateHeap() public static method

Enumerates the heap of the current context.

While the heap is being enumerated, the current context cannot be removed, and all calls to modify the state of the context will fail until the heap enumerator is released.

Requires an active script context.

public static EnumerateHeap ( ) : Native.IActiveScriptProfilerHeapEnum
return Native.IActiveScriptProfilerHeapEnum

GetAndClearException() public static method

Returns the exception that caused the runtime of the current context to be in the exception state and resets the exception state for that runtime.

If the runtime of the current context is not in an exception state, this API will throw JsErrorInvalidArgument. If the runtime is disabled, this will return an exception indicating that the script was terminated, but it will not clear the exception (the exception will be cleared if the runtime is re-enabled using EnableRuntimeExecution).

Requires an active script context.

public static GetAndClearException ( ) : JavaScriptValue
return JavaScriptValue

Idle() public static method

Tells the runtime to do any idle processing it need to do.

If idle processing has been enabled for the current runtime, calling Idle will inform the current runtime that the host is idle and that the runtime can perform memory cleanup tasks.

Idle will also return the number of system ticks until there will be more idle work for the runtime to do. Calling Idle before this number of ticks has passed will do no work.

Requires an active script context.

public static Idle ( ) : uint
return uint

ParseScript() public static method

Parses a script and returns a Function representing the script.
Requires an active script context.
public static ParseScript ( string script ) : JavaScriptValue
script string The script to parse.
return JavaScriptValue

ParseScript() public static method

Parses a script and returns a Function representing the script.
Requires an active script context.
public static ParseScript ( string script, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue
script string The script to parse.
sourceContext JavaScriptSourceContext /// A cookie identifying the script that can be used by script contexts that have debugging enabled. ///
sourceName string The location the script came from.
return JavaScriptValue

ParseScript() public static method

Parses a serialized script and returns a Function representing the script.
Requires an active script context.
public static ParseScript ( string script, byte buffer ) : JavaScriptValue
script string The script to parse.
buffer byte The serialized script.
return JavaScriptValue

ParseScript() public static method

Parses a serialized script and returns a Function representing the script.
Requires an active script context.
public static ParseScript ( string script, byte buffer, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue
script string The script to parse.
buffer byte The serialized script.
sourceContext JavaScriptSourceContext /// A cookie identifying the script that can be used by script contexts that have debugging enabled. ///
sourceName string The location the script came from.
return JavaScriptValue

Release() public method

Releases a reference to a script context.
Removes a reference to a context that was created by AddRef.
public Release ( ) : uint
return uint

RunScript() public static method

Executes a script.
Requires an active script context.
public static RunScript ( string script ) : JavaScriptValue
script string The script to run.
return JavaScriptValue

RunScript() public static method

Executes a script.
Requires an active script context.
public static RunScript ( string script, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue
script string The script to run.
sourceContext JavaScriptSourceContext /// A cookie identifying the script that can be used by script contexts that have debugging enabled. ///
sourceName string The location the script came from.
return JavaScriptValue

RunScript() public static method

Runs a serialized script.
Requires an active script context.
public static RunScript ( string script, byte buffer ) : JavaScriptValue
script string The source code of the serialized script.
buffer byte The serialized script.
return JavaScriptValue

RunScript() public static method

Runs a serialized script.
Requires an active script context.
public static RunScript ( string script, byte buffer, JavaScriptSourceContext sourceContext, string sourceName ) : JavaScriptValue
script string The source code of the serialized script.
buffer byte The serialized script.
sourceContext JavaScriptSourceContext /// A cookie identifying the script that can be used by script contexts that have debugging enabled. ///
sourceName string The location the script came from.
return JavaScriptValue

SerializeScript() public static method

Serializes a parsed script to a buffer than can be reused.

SerializeScript parses a script and then stores the parsed form of the script in a runtime-independent format. The serialized script then can be deserialized in any runtime without requiring the script to be re-parsed.

Requires an active script context.

public static SerializeScript ( string script, byte buffer ) : ulong
script string The script to serialize.
buffer byte The buffer to put the serialized script into. Can be null.
return ulong

SetException() public static method

Sets the runtime of the current context to an exception state.

If the runtime of the current context is already in an exception state, this API will throw JsErrorInExceptionState.

Requires an active script context.

public static SetException ( JavaScriptValue exception ) : void
exception JavaScriptValue /// The JavaScript exception to set for the runtime of the current context. ///
return void

StartDebugging() public static method

Starts debugging in the context.
public static StartDebugging ( Native debugApplication ) : void
debugApplication Native The debug application to use for debugging.
return void

StartProfiling() public static method

Starts profiling in the current context.
Requires an active script context.
public static StartProfiling ( Native callback, Native eventMask, int context ) : void
callback Native The profiling callback to use.
eventMask Native The profiling events to callback with.
context int A context to pass to the profiling callback.
return void

StopProfiling() public static method

Stops profiling in the current context.

Will not return an error if profiling has not started.

Requires an active script context.

public static StopProfiling ( int reason ) : void
reason int /// The reason for stopping profiling to pass to the profiler callback. ///
return void