Value

constructor(context: Context, data: <Error class: unknown class>? = null, size: <Error class: unknown class>, destroyNotify: <Error class: unknown class>?)

Creates a new %ArrayBuffer from existing @data in memory.

The @data is not copied: while this allows sharing data with JavaScript efficiently, the caller must ensure that the memory region remains valid until the newly created object is released by JSC.

Optionally, a @destroy_notify callback can be provided, which will be invoked with @user_data as parameter when the %ArrayBuffer object is released. This is intended to be used for freeing resources related to the memory region which contains the data:

|!<-- language="C" --> GMappedFile *f = g_mapped_file_new (file_path, TRUE, NULL); JSCValue *value = jsc_value_new_array_buffer (context, g_mapped_file_get_contents (f), g_mapped_file_get_length (f), (GDestroyNotify) g_mapped_file_unref, f); |

Note that the @user_data can be the same value as @data:

|!<-- language="C" --> void *bytes = g_malloc0 (100); JSCValue *value = jsc_value_new_array_buffer (context, bytes, 100, g_free, bytes); |

Return

A #JSCValue, or null in case of exception.

Since

2.38

Parameters

context

A #JSCContext

data

Pointer to a region of memory.

size

Size in bytes of the memory region.

destroyNotify

destroy notifier for @user_data.


constructor(context: Context, strv: List<String>)

Create a new #JSCValue referencing an array of strings with the items from @strv. If @array is null or empty a new empty array will be created.

Return

a #JSCValue.

Parameters

context

a #JSCContext

strv

a null-terminated array of strings


constructor(context: Context, value: Boolean)

Create a new #JSCValue from @value

Return

a #JSCValue.

Parameters

context

a #JSCContext

value

a #gboolean


constructor(context: Context, json: String)

Create a new #JSCValue referencing a new value created by parsing @json.

Return

a #JSCValue.

Since

2.28

Parameters

context

a #JSCContext

json

the JSON string to be parsed


constructor(context: Context, name: String? = null, callback: <Error class: unknown class>, returnType: <Error class: unknown class>)

Create a function in @context. If @name is null an anonymous function will be created. When the function is called by JavaScript or jsc_value_function_call(), @callback is called receiving an #GPtrArray of #JSCValues with the arguments and then @user_data as last parameter. When the function is cleared in @context, @destroy_notify is called with @user_data as parameter.

Note that the value returned by @callback must be fully transferred. In case of boxed types, you could use %G_TYPE_POINTER instead of the actual boxed #GType to ensure that the instance owned by #JSCClass is used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a #JSCValue created with jsc_value_new_object() that receives the copy as instance parameter.

Return

a #JSCValue.

Parameters

context

a #JSCContext

name

the function name or null

callback

a #GCallback.

returnType

the #GType of the function return value, or %G_TYPE_NONE if the function is void.


constructor(context: Context)

Create a new #JSCValue referencing null in @context.

Return

a #JSCValue.

Parameters

context

a #JSCContext


constructor(context: Context, number: <Error class: unknown class>)

Create a new #JSCValue from @number.

Return

a #JSCValue.

Parameters

context

a #JSCContext

number

a number


constructor(context: Context, instance: <Error class: unknown class>? = null, jscClass: Class? = null)

Create a new #JSCValue from @instance. If @instance is null a new empty object is created. When @instance is provided, @jsc_class must be provided too. @jsc_class takes ownership of

Return

a #JSCValue.

Parameters

context

a #JSCContext

instance

an object instance or null

jscClass

the #JSCClass of @instance


constructor(context: Context, string: String? = null)

Create a new #JSCValue from @string. If you need to create a #JSCValue from a string containing null characters, use jsc_value_new_string_from_bytes() instead.

Return

a #JSCValue.

Parameters

context

a #JSCContext

string

a null-terminated string


constructor(context: Context, bytes: <Error class: unknown class>? = null)

Create a new #JSCValue from @bytes.

Return

a #JSCValue.

Parameters

context

a #JSCContext

bytes

a #GBytes


constructor(context: Context, type: TypedArrayType, length: <Error class: unknown class>)

Create a new typed array containing a given amount of elements.

Create a #JSCValue referencing a new typed array with space for @length elements of a given @type. As all typed arrays must have an associated ArrayBuffer, a new one of suitable size will be allocated to store the elements, which will be initialized to zero.

The @type must not be %JSC_TYPED_ARRAY_NONE.

Return

a #JSCValue

Since

2.38

Parameters

context

a #JSCContext

type

the type of array elements

length

number of elements in the array


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