C# Класс JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext

The 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.

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AddRef ( ) : uint

Adds a reference to a script context

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

GetAndClearException ( ) : JsValue

Returns a 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 ) : JsValue

Parses a script and returns a Function representing the script

Requires an active script context.

ParseScript ( string script, JsSourceContext sourceContext, string sourceName ) : JsValue

Parses a 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 ) : JsValue

Executes a script

Requires an active script context

RunScript ( string script, JsSourceContext sourceContext, string sourceName ) : JsValue

Executes a 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 ( JsValue exception ) : void

Sets a 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.

Приватные методы

Метод Описание
JsContext ( IntPtr reference ) : System

Initializes a new instance of the JsContext struct

Описание методов

AddRef() публичный Метод

Adds a reference to a script context
Calling AddRef ensures that the context will not be freed until Release is called.
public AddRef ( ) : uint
Результат uint

GetAndClearException() публичный статический Метод

Returns a 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 ( ) : JsValue
Результат JsValue

Idle() публичный статический Метод

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
Результат uint

ParseScript() публичный статический Метод

Parses a script and returns a Function representing the script
Requires an active script context.
public static ParseScript ( string script ) : JsValue
script string The script to parse
Результат JsValue

ParseScript() публичный статический Метод

Parses a script and returns a Function representing the script
Requires an active script context.
public static ParseScript ( string script, JsSourceContext sourceContext, string sourceName ) : JsValue
script string The script to parse
sourceContext JsSourceContext The cookie identifying the script that can be used /// by script contexts that have debugging enabled
sourceName string The location the script came from
Результат JsValue

Release() публичный Метод

Releases a reference to a script context
Removes a reference to a context that was created by AddRef.
public Release ( ) : uint
Результат uint

RunScript() публичный статический Метод

Executes a script
Requires an active script context
public static RunScript ( string script ) : JsValue
script string The script to run
Результат JsValue

RunScript() публичный статический Метод

Executes a script
Requires an active script context.
public static RunScript ( string script, JsSourceContext sourceContext, string sourceName ) : JsValue
script string The script to run
sourceContext JsSourceContext The cookie identifying the script that can be used /// by script contexts that have debugging enabled
sourceName string The location the script came from
Результат JsValue

SerializeScript() публичный статический Метод

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
Результат ulong

SetException() публичный статический Метод

Sets a 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 ( JsValue exception ) : void
exception JsValue The JavaScript exception to set for the runtime of the current context
Результат void