JavaScriptCore.Context
Description: Reference for JavaScriptCore.Context

### Class

# JavaScriptCoreContext

#### Description [src]

    class JavaScriptCore.Context : GObject.Object
    {
      JSCContextPrivate* priv
    }

JSCContext represents a JavaScript execution context, where all operations take place and where the values will be associated.

When a new context is created, a global object is allocated and the built-in JavaScript objects (Object, Function, String, Array) are populated. You can execute JavaScript in the context by using `jsc_context_evaluate()` or jsc_context_evaluate_with_source_uri(). It’s also possible to register custom objects in the context with jsc_context_register_class().

#### Ancestors

- GObject

#### Constructors

###### jsc_context_new

Create a new `JSCContext`. The context is created in a new `JSCVirtualMachine`. Use `jsc_context_new_with_virtual_machine()` to create a new `JSCContext` in an existing `JSCVirtualMachine`.

###### jsc_context_new_with_virtual_machine

Create a new `JSCContext` in `virtual_machine`.

#### Functions

###### jsc_context_get_current

Get the `JSCContext` that is currently executing a function. This should only be called within a function or method callback, otherwise `NULL` will be returned.

#### Instance methods

###### jsc_context_check_syntax

Check the given `code` in `context` for syntax errors. The `line_number` is the starting line number in `uri`; the value is one-based so the first line is 1. `uri` and `line_number` are only used to fill the `exception`. In case of errors `exception` will be set to a new `JSCException` with the details. You can pass `NULL` to `exception` to ignore the error details.

###### jsc_context_clear_exception

Clear the uncaught exception in `context` if any.

###### jsc_context_evaluate

Evaluate `code` in `context`.

###### jsc_context_evaluate_in_object

Evaluate `code` and create an new object where symbols defined in `code` will be added as properties, instead of being added to `context` global object. The new object is returned as `object` parameter. Similar to how `jsc_value_new_object()` works, if `object_instance` is not `NULL` `object_class` must be provided too. The `line_number` is the starting line number in `uri`; the value is one-based so the first line is 1. `uri` and `line_number` will be shown in exceptions and they don’t affect the behavior of the script.

###### jsc_context_evaluate_with_source_uri

Evaluate `code` in `context` using `uri` as the source URI. The `line_number` is the starting line number in `uri`; the value is one-based so the first line is 1. `uri` and `line_number` will be shown in exceptions and they don’t affect the behavior of the script.

###### jsc_context_get_exception

Get the last unhandled exception thrown in `context` by API functions calls.

###### jsc_context_get_global_object

Get a `JSCValue` referencing the `context` global object.

###### jsc_context_get_value

Get a property of `context` global object with `name`.

###### jsc_context_get_virtual_machine

Get the `JSCVirtualMachine` where `context` was created.

###### jsc_context_pop_exception_handler

Remove the last `JSCExceptionHandler` previously pushed to `context` with jsc_context_push_exception_handler().

###### jsc_context_push_exception_handler

Push an exception handler in `context`. Whenever a JavaScript exception happens in the `JSCContext`, the given `handler` will be called. The default `JSCExceptionHandler` simply calls `jsc_context_throw_exception()` to throw the exception to the `JSCContext`. If you don’t want to catch the exception, but only get notified about it, call `jsc_context_throw_exception()` in `handler` like the default one does. The last exception handler pushed is the only one used by the `JSCContext`, use `jsc_context_pop_exception_handler()` to remove it and set the previous one. When `handler` is removed from the context, `destroy_notify` is called with `user_data` as parameter.

###### jsc_context_register_class

Register a custom class in `context` using the given `name`. If the new class inherits from another `JSCClass`, the parent should be passed as `parent_class`, otherwise `NULL` should be used. The optional `vtable` parameter allows to provide a custom implementation for handling the class, for example, to handle external properties not added to the prototype. When an instance of the `JSCClass` is cleared in the context, `destroy_notify` is called with the instance as parameter.

###### jsc_context_set_value

Set a property of `context` global object with `name` and `value`.

###### jsc_context_throw

Throw an exception to `context` using the given error message. The created `JSCException` can be retrieved with jsc_context_get_exception().

###### jsc_context_throw_exception

Throw `exception` to `context`.

###### jsc_context_throw_printf

Throw an exception to `context` using the given formatted string as error message. The created `JSCException` can be retrieved with jsc_context_get_exception().

###### jsc_context_throw_with_name

Throw an exception to `context` using the given error name and message. The created `JSCException` can be retrieved with jsc_context_get_exception().

###### jsc_context_throw_with_name_printf

Throw an exception to `context` using the given error name and the formatted string as error message. The created `JSCException` can be retrieved with jsc_context_get_exception().

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### JavaScriptCore.Context:virtual-machine

The `JSCVirtualMachine` in which the context was created.

#### Signals

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct JavaScriptCoreContextClass {
      GObjectClass parent_class;
      void (* _jsc_reserved0) (
    void
      );
      void (* _jsc_reserved1) (
    void
      );
      void (* _jsc_reserved2) (
    void
      );
      void (* _jsc_reserved3) (
    void
      );

    }

No description available.

###### Class members

`parent_class: GObjectClass`

  No description available.

`_jsc_reserved0: void (* _jsc_reserved0) ( void )`

  No description available.

`_jsc_reserved1: void (* _jsc_reserved1) ( void )`

  No description available.

`_jsc_reserved2: void (* _jsc_reserved2) ( void )`

  No description available.

`_jsc_reserved3: void (* _jsc_reserved3) ( void )`

  No description available.