Context

class Context(pointer: <Error class: unknown class><<Error class: unknown class>>)

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().

Skipped during bindings generation

  • parameter exception: exception: Out parameter is not supported

  • parameter object: object: Out parameter is not supported

  • parameter destroy_notify: GLib.DestroyNotify

  • method throw_printf: Varargs parameter is not supported

  • method throw_with_name_printf: Varargs parameter is not supported

Constructors

Link copied to clipboard
constructor()

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.

constructor(vm: VirtualMachine)

Create a new #JSCContext in @virtual_machine.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val javascriptcoreContextPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard

The #JSCVirtualMachine in which the context was created.

Functions

Link copied to clipboard

Clear the uncaught exception in @context if any.

Link copied to clipboard
fun evaluate(code: String, length: Long): Value

Evaluate @code in @context.

Link copied to clipboard
fun evaluateWithSourceUri(code: String, length: Long, uri: String, lineNumber: <Error class: unknown class>): Value

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.

Link copied to clipboard

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

Link copied to clipboard

Get a #JSCValue referencing the @context global object

Link copied to clipboard
fun getValue(name: String): Value

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

Link copied to clipboard

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

Link copied to clipboard

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 i called with @user_data as parameter.

Link copied to clipboard
fun setValue(name: String, value: Value)

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

Link copied to clipboard
fun throw(errorMessage: String)

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

Link copied to clipboard
fun throwException(exception: Exception)

Throw @exception to @context.

Link copied to clipboard
fun throwWithName(errorName: String, errorMessage: String)

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