C# Class MsieJavaScriptEngine.JsRt.JavaScriptRuntime

A Chakra runtime.

Each Chakra runtime has its own independent execution engine, JIT compiler, and garbage collected heap. As such, each runtime is completely isolated from other runtimes.

Runtimes can be used on any thread, but only one thread can call into a runtime at any time.

NOTE: A JavaScriptRuntime, unlike other objects in the Chakra hosting API, is not garbage collected since it contains the garbage collected heap itself. A runtime will continue to exist until Dispose is called.

Mostrar archivo Open project: klumsy/PowerShellJS Class Usage Examples

Public Methods

Method Description
CollectGarbage ( ) : void

Performs a full garbage collection.

Create ( ) : JavaScriptRuntime

Creates a new runtime.

Create ( JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version ) : JavaScriptRuntime

Creates a new runtime.

Create ( JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version, JavaScriptThreadServiceCallback threadServiceCallback ) : JavaScriptRuntime

Creates a new runtime.

CreateContext ( ) : JavaScriptContext

Creates a script context for running scripts.

Each script context has its own global object that is isolated from all other script contexts.

CreateContext ( Native debugApplication ) : JavaScriptContext

Creates a debug script context for running scripts.

Each script context has its own global object that is isolated from all other script contexts.

Dispose ( ) : void

Disposes a runtime.

Once a runtime has been disposed, all resources owned by it are invalid and cannot be used. If the runtime is active (i.e. it is set to be current on a particular thread), it cannot be disposed.

SetBeforeCollectCallback ( IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback ) : void

Sets a callback function that is called by the runtime before garbage collection.

The callback is invoked on the current runtime execution thread, therefore execution is blocked until the callback completes.

The callback can be used by hosts to prepare for garbage collection. For example, by releasing unnecessary references on Chakra objects.

SetMemoryAllocationCallback ( IntPtr callbackState, JavaScriptMemoryAllocationCallback allocationCallback ) : void

Sets a memory allocation callback for specified runtime

Registering a memory allocation callback will cause the runtime to call back to the host whenever it acquires memory from, or releases memory to, the OS. The callback routine is called before the runtime memory manager allocates a block of memory. The allocation will be rejected if the callback returns false. The runtime memory manager will also invoke the callback routine after freeing a block of memory, as well as after allocation failures.

The callback is invoked on the current runtime execution thread, therefore execution is blocked until the callback completes.

The return value of the callback is not stored; previously rejected allocations will not prevent the runtime from invoking the callback again later for new memory allocations.

Method Details

CollectGarbage() public method

Performs a full garbage collection.
public CollectGarbage ( ) : void
return void

Create() public static method

Creates a new runtime.
public static Create ( ) : JavaScriptRuntime
return JavaScriptRuntime

Create() public static method

Creates a new runtime.
public static Create ( JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version ) : JavaScriptRuntime
attributes JavaScriptRuntimeAttributes The attributes of the runtime to be created.
version JavaScriptRuntimeVersion The version of the runtime to be created.
return JavaScriptRuntime

Create() public static method

Creates a new runtime.
public static Create ( JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version, JavaScriptThreadServiceCallback threadServiceCallback ) : JavaScriptRuntime
attributes JavaScriptRuntimeAttributes The attributes of the runtime to be created.
version JavaScriptRuntimeVersion The version of the runtime to be created.
threadServiceCallback JavaScriptThreadServiceCallback The thread service for the runtime. Can be null.
return JavaScriptRuntime

CreateContext() public method

Creates a script context for running scripts.
Each script context has its own global object that is isolated from all other script contexts.
public CreateContext ( ) : JavaScriptContext
return JavaScriptContext

CreateContext() public method

Creates a debug script context for running scripts.
Each script context has its own global object that is isolated from all other script contexts.
public CreateContext ( Native debugApplication ) : JavaScriptContext
debugApplication Native The debug application to use.
return JavaScriptContext

Dispose() public method

Disposes a runtime.
Once a runtime has been disposed, all resources owned by it are invalid and cannot be used. If the runtime is active (i.e. it is set to be current on a particular thread), it cannot be disposed.
public Dispose ( ) : void
return void

SetBeforeCollectCallback() public method

Sets a callback function that is called by the runtime before garbage collection.

The callback is invoked on the current runtime execution thread, therefore execution is blocked until the callback completes.

The callback can be used by hosts to prepare for garbage collection. For example, by releasing unnecessary references on Chakra objects.

public SetBeforeCollectCallback ( IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback ) : void
callbackState System.IntPtr /// User provided state that will be passed back to the callback. ///
beforeCollectCallback JavaScriptBeforeCollectCallback The callback function being set.
return void

SetMemoryAllocationCallback() public method

Sets a memory allocation callback for specified runtime

Registering a memory allocation callback will cause the runtime to call back to the host whenever it acquires memory from, or releases memory to, the OS. The callback routine is called before the runtime memory manager allocates a block of memory. The allocation will be rejected if the callback returns false. The runtime memory manager will also invoke the callback routine after freeing a block of memory, as well as after allocation failures.

The callback is invoked on the current runtime execution thread, therefore execution is blocked until the callback completes.

The return value of the callback is not stored; previously rejected allocations will not prevent the runtime from invoking the callback again later for new memory allocations.

public SetMemoryAllocationCallback ( IntPtr callbackState, JavaScriptMemoryAllocationCallback allocationCallback ) : void
callbackState System.IntPtr /// User provided state that will be passed back to the callback. ///
allocationCallback JavaScriptMemoryAllocationCallback /// Memory allocation callback to be called for memory allocation events. ///
return void