It derives from <GObject>.
JSCValue represents a reference to a value in a
<JSCContext>. The JSCValue protects the
referenced value from being garbage collected.
The <JSCContext> in which the value was created.
Its value is a <JSCContext>, or #f.
It can only be set when the object is made, with #:context.
Gets a pointer to memory that contains the array buffer data.
Obtains a pointer to the memory region that holds the contents of the
ArrayBuffer; modifications done to the data will be visible to
JavaScript code. If size is not #f, the size in bytes of
the memory region will also be stored in the pointed location.
Note that the pointer returned by this function is not guaranteed to
remain the same after calls to other JSC API functions. If you plan to
access the data of the ArrayBuffer later, you can keep a
reference to the self and obtain the data pointer at a later
point. Keep in mind that if JavaScript code has a chance to run, for
example due to main loop events that result in JSC being called, the
contents of the memory region might be modified in the meantime.
Consider taking a copy of the data and using the copy instead in
asynchronous code.
Passed: a <JSCValue>.
Returned: a bytevector.
pointer to memory.
Not returned: it is the length of %return.
location where to store the size of the memory region.
Gets the size in bytes of the array buffer.
Obtains the size in bytes of the memory region that holds the contents
of an ArrayBuffer.
Passed: a <JSCValue>.
Returned: an unsigned 64-bit integer.
size, in bytes.
Invoke new() with constructor referenced by self. If
first-parameter-type is G_TYPE_NONE no parameters will be
passed to the constructor.
Passed: a <JSCValue>.
Passed, or left out: a list or vector, each a
<JSCValue>, or #f.
Returned: a <JSCValue>.
a <JSCValue> referencing the newly created object
instance.
Not passed: guile-gi gives the length of parameters.
GType of first parameter, or G_TYPE_NONE
value of the first parameter, followed optionally by more type/value
pairs, followed by G_TYPE_NONE
Call function referenced by self, passing the given parameters. If
first-parameter-type is G_TYPE_NONE no parameters will be
passed to the function.
This function always returns a <JSCValue>, in case
of void functions a <JSCValue> referencing
undefined() is returned
Passed: a <JSCValue>.
Passed, or left out: a list or vector, each a
<JSCValue>, or #f.
Returned: a <JSCValue>.
a <JSCValue> with the return value of the function.
Not passed: guile-gi gives the length of parameters.
GType of first parameter, or G_TYPE_NONE
value of the first parameter, followed optionally by more type/value
pairs, followed by G_TYPE_NONE
Get the <JSCContext> in which self was
created.
Passed: a <JSCValue>.
Returned: a <JSCContext>.
the <JSCValue> context.
Check whether the self is an ArrayBuffer.
Passed: a <JSCValue>.
A <JSCValue>.
Returned: a boolean.
whether the value is an ArrayBuffer
Get whether the value referenced by self is an array.
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is an array.
Get whether the value referenced by self is a boolean.
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is a boolean.
Get whether the value referenced by self is a constructor.
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is a constructor.
Get whether the value referenced by self is a function
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is a function.
Get whether the value referenced by self is null().
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is null.
Get whether the value referenced by self is a number.
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is a number.
Get whether the value referenced by self is an object.
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is an object.
Get whether the value referenced by self is a string
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is a string
Determines whether a value is a typed array.
Passed: a <JSCValue>.
Returned: a boolean.
Whether self is a typed array.
Get whether the value referenced by self is undefined().
Passed: a <JSCValue>.
Returned: a boolean.
whether the value is undefined.
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);
Passed: a <JSCContext>.
Passed: a foreign pointer, or a bytevector, or #f.
Pointer to a region of memory.
Passed: an unsigned 64-bit integer.
Size in bytes of the memory region.
Passed, or left out: a procedure, or #f.
destroy notifier for user-data.
See GDestroyNotify for how it is
called.
Returned: a <JSCValue>, or #f.
A <JSCValue>, or #f in case of exception.
Not passed: guile-gi supplies it.
user data.
Create a new <JSCValue> referencing an array with
the items from array. If array is #f or empty a new
empty array will be created. Elements of array should be pointers
to a <JSCValue>.
Passed: a <JSCContext>.
Passed, or left out: a list or vector, each a
<JSCValue>, or #f.
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> referencing an array of
strings with the items from strv. If array is #f or
empty a new empty array will be created.
Passed: a <JSCContext>.
Passed: a list or vector, each a string.
a #f-terminated array of strings
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> from value
Passed: a <JSCContext>.
Passed: a boolean.
a gboolean
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> referencing a new value
created by parsing json.
Passed: a <JSCContext>.
Passed: a string.
the JSON string to be parsed
Returned: a <JSCValue>.
a <JSCValue>.
Create a function in context. If name is #f an
anonymous function will be created. When the function is called by
JavaScript or value:function-call,
callback is called receiving the function parameters 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 value:new-object that
receives the copy as instance parameter.
Passed: a <JSCContext>.
a #JSCContext:
Passed: a string, or #f.
the function name or #f
Passed: a procedure.
a GCallback.
See GCallback for how it is called.
Passed: a class, or a GType number.
the GType of the function return value, or G_TYPE_NONE if
the function is void.
Passed, or left out: a list or vector, each a class, or a GType number,
or #f.
Returned: a <JSCValue>.
a <JSCValue>.
Not passed: guile-gi gives the length of parameter-types.
Not passed: guile-gi supplies it.
user data to pass to callback.
Not passed: guile-gi supplies it.
destroy notifier for user-data
See GDestroyNotify for how it is
called.
the number of parameter types to follow or 0 if the function doesn’t receive parameters.
a list of GType<!– –>s, one for each parameter.
Create a function in context. If name is #f an
anonymous function will be created. When the function is called by
JavaScript or value:function-call,
callback is called receiving an
<GPtrArray> of
<JSCValue><!– –>s 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 value:new-object that
receives the copy as instance parameter.
Passed: a <JSCContext>.
Passed: a string, or #f.
the function name or #f
Passed: a procedure.
a GCallback.
See GCallback for how it is called.
Passed: a class, or a GType number.
the GType of the function return value, or G_TYPE_NONE if
the function is void.
Returned: a <JSCValue>.
a <JSCValue>.
Not passed: guile-gi supplies it.
user data to pass to callback.
Not passed: guile-gi supplies it.
destroy notifier for user-data
See GDestroyNotify for how it is
called.
Create a new <JSCValue> referencing null() in
context.
Passed: a <JSCContext>.
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> from number.
Passed: a <JSCContext>.
Passed: a real number.
a number
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> from instance. If
instance is #f a new empty object is created. When
instance is provided, jsc-class must be provided too.
jsc-class takes ownership of instance that will be freed by
the GDestroyNotify passed to
jsc_context_register_class().
Passed: a <JSCContext>.
Passed, or left out: a foreign pointer, or a bytevector, or #f.
an object instance or #f
Passed, or left out: a <JSCClass>, or #f.
the <JSCClass> of instance
Returned: a <JSCValue>.
a <JSCValue>.
Creates a new Promise. executor will be invoked during promise initialization and it receives the resolve and reject objects than can be called to resolve or reject the promise. It is called like a JavaScript function, so exceptions raised during the executor invocation will not be propagated to the context, but handled by the promise causing a rejection.
Passed: a <JSCContext>.
Passed: a procedure.
an initialization callback
See JSCExecutor for how it is called.
Returned: a <JSCValue>.
a deferred promise object
Not passed: guile-gi supplies it.
user data passed in executor
Create a new <JSCValue> from string. If you
need to create a <JSCValue> from a string containing
null characters, use value:new-string-from-bytes instead.
Passed: a <JSCContext>.
Passed, or left out: a string, or #f.
a null-terminated string
Returned: a <JSCValue>.
a <JSCValue>.
Create a new <JSCValue> from bytes.
Passed: a <JSCContext>.
Passed, or left out: a <GBytes>, or #f.
a <GBytes>
Returned: a <JSCValue>.
a <JSCValue>.
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 none.
Passed: a <JSCContext>.
Passed: a <%JSCTypedArrayType>, or one of
its symbols.
the type of array elements
Passed: an unsigned 64-bit integer.
number of elements in the array
Returned: a <JSCValue>.
Create a new typed array value with elements from an array buffer.
Create a <JSCValue> referencing a new typed array
value containing elements of the given type, where the elements
are stored at the memory region represented by the self.
The type must not be none.
The offset and length parameters can be used to indicate
which part of the array buffer can be accessed through the typed array.
If both are omitted (passing zero as offset, and -1 as
length), the whole self is exposed through the typed array.
Omitting the length with a non-zero offset will expose the
remainder of the self starting at the indicated offset.
Passed: a <JSCValue>.
a <JSCValue>.
Passed: a <%JSCTypedArrayType>, or one of
its symbols.
type of array elements.
Passed: an unsigned 64-bit integer.
offset, in bytes.
Passed: a 64-bit integer.
number of array elements, or -1.
Returned: a <JSCValue>.
Create a new <JSCValue> referencing
undefined() in context.
Passed: a <JSCContext>.
Returned: a <JSCValue>.
a <JSCValue>.
Define or modify a property with property-name in object
referenced by self. When the property value is read or set,
getter and setter callbacks will be called. When the
property is cleared in the <JSCClass> context,
destroy-notify is called with user-data as parameter. This
is equivalent to JavaScript Object.defineProperty() when used
with an accessor descriptor.
Note that the value returned by getter 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 value:new-object that receives the copy as instance
parameter.
Note that getter and setter are called as functions and not
methods, so they don’t receive an instance as first parameter. Use
class:add-property if you want to add
property accessor invoked as a method.
Passed: a <JSCValue>.
Passed: a string.
the name of the property to define
Passed: a <%JSCValuePropertyFlags>, or
a list of its symbols, or one of them.
Passed: a class, or a GType number.
the GType of the property
Passed, or left out: a procedure, or #f.
a GCallback to be called to get the
property value
See GCallback for how it is called.
Passed, or left out: a procedure, or #f.
a GCallback to be called to set the
property value
See GCallback for how it is called.
Not passed: guile-gi supplies it.
user data to pass to getter and setter
Not passed: guile-gi supplies it.
destroy notifier for user-data
See GDestroyNotify for how it is
called.
Define or modify a property with property-name in object
referenced by self. This is equivalent to JavaScript
Object.defineProperty() when used with a data descriptor.
Passed: a <JSCValue>.
Passed: a string.
the name of the property to define
Passed: a <%JSCValuePropertyFlags>, or
a list of its symbols, or one of them.
Passed, or left out: a <JSCValue>, or #f.
the default property value
Try to delete property with name from self. This function
will return #f if the property was defined without
configurable flag.
Passed: a <JSCValue>.
Passed: a string.
the property name
Returned: a boolean.
#t if the property was deleted, or #f otherwise.
Get the list of property names of self. Only properties defined
with enumerable flag will be collected.
Passed: a <JSCValue>.
Returned: a vector, each a string, or #f.
a #f-terminated array of strings containing the property names,
or #f if self doesn’t have enumerable properties. Use
strfreev to free.
Get property with name from self.
Passed: a <JSCValue>.
Passed: a string.
the property name
Returned: a <JSCValue>.
the property <JSCValue>.
Get property at index from self.
Passed: a <JSCValue>.
Passed: an unsigned 32-bit integer.
the property index
Returned: a <JSCValue>.
the property <JSCValue>.
Get whether self has property with name.
Passed: a <JSCValue>.
Passed: a string.
the property name
Returned: a boolean.
#t if self has a property with name, or #f
otherwise
Invoke method with name on object referenced by self,
passing the given parameters. If first-parameter-type is
G_TYPE_NONE no parameters will be passed to the method. The
object instance will be handled automatically even when the method is a
custom one registered with class:add-method, so it should never be passed explicitly
as parameter of this function.
This function always returns a <JSCValue>, in case
of void methods a <JSCValue> referencing
undefined() is returned.
Passed: a <JSCValue>.
Passed: a string.
the method name
Passed, or left out: a list or vector, each a
<JSCValue>, or #f.
Returned: a <JSCValue>.
a <JSCValue> with the return value of the method.
Not passed: guile-gi gives the length of parameters.
GType of first parameter, or G_TYPE_NONE
value of the first parameter, followed optionally by more type/value
pairs, followed by G_TYPE_NONE
Get whether the value referenced by self is an instance of class name.
Passed: a <JSCValue>.
Passed: a string.
a class name
Returned: a boolean.
whether the value is an object instance of class name.
Set property with name on self.
Passed: a <JSCValue>.
Passed: a string.
the property name
Passed: a <JSCValue>.
the <JSCValue> to set
Set property at index on self.
Passed: a <JSCValue>.
Passed: an unsigned 32-bit integer.
the property index
Passed: a <JSCValue>.
the <JSCValue> to set
Convert self to a boolean.
Passed: a <JSCValue>.
Returned: a boolean.
a gboolean result of the conversion.
Convert self to a double.
Passed: a <JSCValue>.
Returned: a real number.
a gdouble result of the conversion.
Convert self to a gint32.
Passed: a <JSCValue>.
Returned: a 32-bit integer.
a gint32 result of the conversion.
Create a JSON string of self serialization. If indent is 0, the resulting JSON will not contain newlines. The size of the indent is clamped to 10 spaces.
Passed: a <JSCValue>.
Passed: an unsigned 32-bit integer.
The number of spaces to indent when nesting.
Returned: a string.
a null-terminated JSON string with serialization of self
Convert self to a string. Use value:to-string-as-bytes instead, if you need to
handle strings containing null characters.
Passed: a <JSCValue>.
Returned: a string.
a null-terminated string result of the conversion.
Convert self to a string and return the results as
<GBytes>. This is needed to handle strings
with null characters.
Passed: a <JSCValue>.
Returned: a <GBytes>.
a <GBytes> with the result of the conversion.
Obtain the ArrayBuffer for the memory region of the typed array
elements.
Passed: a <JSCValue>.
Returned: a <JSCValue>.
Obtains a pointer to the memory region that holds the elements of the
typed array; modifications done to them will be visible to JavaScript
code. If length is not #f, the number of elements
contained in the typed array are also stored in the pointed location.
The returned pointer needs to be casted to the appropriate type (see
<%JSCTypedArrayType>), and has the
offset over the underlying array buffer data applied—that is,
points to the first element of the typed array:
if (jsc_value_typed_array_get_type(value) != JSC_TYPED_ARRAY_UINT32)
g_error ("Only arrays of uint32_t are supported");
gsize count = 0;
uint32_t *elements = jsc_value_typed_array_get_contents (value, &count);
for (gsize i = 0; i < count; i++)
g_print ("index %zu, value %" PRIu32 "\n", i, elements[i]);
Note that the pointer returned by this function is not guaranteed to
remain the same after calls to other JSC API functions. See
value:array-buffer-get-data
for details.
Passed: a <JSCValue>.
Returned: a foreign pointer, or #f.
pointer to memory.
Returned: an unsigned 64-bit integer.
location to return the number of elements contained
Gets the number of elements in a typed array.
Passed: a <JSCValue>.
Returned: an unsigned 64-bit integer.
number of elements.
Gets the offset over the underlying array buffer data.
Passed: a <JSCValue>.
Returned: an unsigned 64-bit integer.
offset, in bytes.
Gets the size of a typed array.
Passed: a <JSCValue>.
Returned: an unsigned 64-bit integer.
size, in bytes.
Gets the type of elements contained in a typed array.
Passed: a <JSCValue>.
Returned: a <%JSCTypedArrayType>.
type of the elements, or none if self
is not a typed array.