Value
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
A #JSCContext
Pointer to a region of memory.
Size in bytes of the memory region.
destroy notifier for @user_data.
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
a #JSCContext
a null-terminated array of strings
Create a new #JSCValue from @value
Return
a #JSCValue.
Parameters
a #JSCContext
a #gboolean
Create a new #JSCValue referencing a new value created by parsing @json.
Return
a #JSCValue.
Since
2.28
Parameters
a #JSCContext
the JSON string to be parsed
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
a #JSCContext
the function name or null
a #GCallback.
the #GType of the function return value, or %G_TYPE_NONE if the function is void.
Create a new #JSCValue referencing
Return
a #JSCValue.
Parameters
a #JSCContext
Create a new #JSCValue from @number.
Return
a #JSCValue.
Parameters
a #JSCContext
a number
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
a #JSCContext
an object instance or null
the #JSCClass of @instance
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
a #JSCContext
a null-terminated string
Create a new #JSCValue from @bytes.
Return
a #JSCValue.
Parameters
a #JSCContext
a #GBytes
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
a #JSCContext
the type of array elements
number of elements in the array