Class Value
- All Implemented Interfaces:
Proxy
JSCContext
. The JSCValue
protects the referenced value from being garbage collected.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Value.Builder<B extends Value.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionValue
(MemorySegment address) Create a Value proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionstatic Value
Create a newJSCValue
referencing an array with the given items.static Value
arrayBuffer
(Context context, @Nullable MemorySegment data, long size) Creates a newArrayBuffer
from existingdata
in memory.arrayBufferGetData
(@Nullable MemorySegment size) Gets a pointer to memory that contains the array buffer data.long
Gets the size in bytes of the array buffer.static Value
arrayFromGarray
(Context context, @Nullable Value[] array) Create a newJSCValue
referencing an array with the items fromarray
.static Value
arrayFromStrv
(Context context, String[] strv) Create a newJSCValue
referencing an array of strings with the items fromstrv
.protected Value
asParent()
Returns this instance as if it were its parent type.static Value
Create a newJSCValue
fromvalue
static Value.Builder
<? extends Value.Builder> builder()
AValue.Builder
object constructs aValue
with the specified properties.constructorCall
(@Nullable Value[] parameters) Invoke <function>new</function> with constructor referenced by this Value.static Value
Create a newJSCValue
referencing a new value created by parsingjson
.static Value
function
(Context context, @Nullable String name, Callback callback, Type returnType, @Nullable Type[] parameterTypes) Create a function incontext
.functionCall
(@Nullable Value[] parameters) Call function referenced by this Value, passing the givenparameters
.static Value
functionVariadic
(Context context, @Nullable String name, Callback callback, Type returnType) Create a function incontext
.Get theJSCContext
in which this Value was created.static Type
getType()
Get the GType of the Value classboolean
isArray()
Get whether the value referenced by this Value is an array.boolean
Check whether the this Value is anArrayBuffer
.boolean
Get whether the value referenced by this Value is a boolean.boolean
Get whether the value referenced by this Value is a constructor.boolean
Get whether the value referenced by this Value is a functionboolean
isNull()
Get whether the value referenced by this Value is <function>null</function>.boolean
isNumber()
Get whether the value referenced by this Value is a number.boolean
isObject()
Get whether the value referenced by this Value is an object.boolean
isString()
Get whether the value referenced by this Value is a stringboolean
Determines whether a value is a typed array.boolean
Get whether the value referenced by this Value is <function>undefined</function>.newTypedArrayWithBuffer
(TypedArrayType type, long offset, long length) Create a new typed array value with elements from an array buffer.static Value
Create a newJSCValue
referencing <function>null</function> incontext
.static Value
Create a newJSCValue
fromnumber
.static Value
object
(Context context, @Nullable MemorySegment instance, @Nullable Class jscClass) Create a newJSCValue
frominstance
.void
objectDefinePropertyAccessor
(String propertyName, Set<ValuePropertyFlags> flags, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Define or modify a property withpropertyName
in object referenced by this Value.void
objectDefinePropertyAccessor
(String propertyName, ValuePropertyFlags flags, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Define or modify a property withpropertyName
in object referenced by this Value.void
objectDefinePropertyData
(String propertyName, Set<ValuePropertyFlags> flags, @Nullable Value propertyValue) Define or modify a property withpropertyName
in object referenced by this Value.void
objectDefinePropertyData
(String propertyName, ValuePropertyFlags flags, @Nullable Value propertyValue) Define or modify a property withpropertyName
in object referenced by this Value.boolean
objectDeleteProperty
(String name) Try to delete property withname
from this Value.String[]
Get the list of property names of this Value.objectGetProperty
(String name) Get property withname
from this Value.objectGetPropertyAtIndex
(int index) Get property atindex
from this Value.boolean
objectHasProperty
(String name) Get whether this Value has property withname
.objectInvokeMethod
(String name, @Nullable Value[] parameters) Invoke method withname
on object referenced by this Value, passing the givenparameters
.boolean
objectIsInstanceOf
(String name) Get whether the value referenced by this Value is an instance of classname
.void
objectSetProperty
(String name, Value property) Setproperty
withname
on this Value.void
objectSetPropertyAtIndex
(int index, Value property) Setproperty
atindex
on this Value.static Value
Create a newJSCValue
fromstring
.static Value
stringFromBytes
(Context context, @Nullable Bytes bytes) Create a newJSCValue
frombytes
.boolean
Convert this Value to a boolean.double
toDouble()
Convert this Value to a double.int
toInt32()
Convert this Value to agint32
.toJson
(int indent) Create a JSON string of this Value serialization.toString()
Convert this Value to a string.Convert this Value to a string and return the results asGBytes
.static Value
typedArray
(Context context, TypedArrayType type, long length) Create a new typed array containing a given amount of elements.Obtain theArrayBuffer
for the memory region of the typed array elements.typedArrayGetData
(@Nullable Out<Long> length) 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.long
Gets the number of elements in a typed array.long
Gets the offset over the underlying array buffer data.long
Gets the size of a typed array.Gets the type of elements contained in a typed array.static Value
Create a newJSCValue
referencing <function>undefined</function> incontext
.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Value
Create a Value proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
array
Create a newJSCValue
referencing an array with the given items. IffirstItemType
isG_TYPE_NONE
an empty array is created.- Parameters:
context
- aJSCContext
firstItemType
-GType
of first item, orG_TYPE_NONE
varargs
- value of the first item, followed optionally by more type/value pairs, followed byG_TYPE_NONE
.- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
arrayBuffer
Creates a newArrayBuffer
from existingdata
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
destroyNotify
callback can be provided, which will be invoked withuserData
as parameter when theArrayBuffer
object is released. This is intended to be used for freeing resources related to the memory region which contains the data: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
userData
can be the same value asdata
:void *bytes = g_malloc0 (100); JSCValue *value = jsc_value_new_array_buffer (context, bytes, 100, g_free, bytes);
- Parameters:
context
- AJSCContext
data
- Pointer to a region of memory.size
- Size in bytes of the memory region.- Returns:
- A
JSCValue
, ornull
in case of exception. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
arrayFromGarray
Create a newJSCValue
referencing an array with the items fromarray
. Ifarray
isnull
or empty a new empty array will be created. Elements ofarray
should be pointers to aJSCValue
.- Parameters:
context
- aJSCContext
array
- aGPtrArray
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
arrayFromStrv
Create a newJSCValue
referencing an array of strings with the items fromstrv
. Ifarray
isnull
or empty a new empty array will be created.- Parameters:
context
- aJSCContext
strv
- anull
-terminated array of strings- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
boolean_
Create a newJSCValue
fromvalue
- Parameters:
context
- aJSCContext
value
- agboolean
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
fromJson
Create a newJSCValue
referencing a new value created by parsingjson
.- Parameters:
context
- aJSCContext
json
- the JSON string to be parsed- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
functionVariadic
public static Value functionVariadic(Context context, @Nullable @Nullable String name, Callback callback, Type returnType) Create a function incontext
. Ifname
isnull
an anonymous function will be created. When the function is called by JavaScript or jsc_value_function_call(),callback
is called receiving anGPtrArray
ofJSCValue
<!-- -->s with the arguments and thenuserData
as last parameter. When the function is cleared incontext
,destroyNotify
is called withuserData
as parameter.Note that the value returned by
callback
must be fully transferred. In case of boxed types, you could useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as instance parameter.- Parameters:
context
- aJSCContext
name
- the function name ornull
callback
- aGCallback
.returnType
- theGType
of the function return value, orG_TYPE_NONE
if the function is void.- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
function
public static Value function(Context context, @Nullable @Nullable String name, Callback callback, Type returnType, @Nullable @Nullable Type[] parameterTypes) Create a function incontext
. Ifname
isnull
an anonymous function will be created. When the function is called by JavaScript or jsc_value_function_call(),callback
is called receiving the function parameters and thenuserData
as last parameter. When the function is cleared incontext
,destroyNotify
is called withuserData
as parameter.Note that the value returned by
callback
must be fully transferred. In case of boxed types, you could useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as instance parameter.- Parameters:
context
- aJSCContext
name
- the function name ornull
callback
- aGCallback
.returnType
- theGType
of the function return value, orG_TYPE_NONE
if the function is void.parameterTypes
- a list ofGType
<!-- -->s, one for each parameter, ornull
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
null_
Create a newJSCValue
referencing <function>null</function> incontext
.- Parameters:
context
- aJSCContext
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
number
Create a newJSCValue
fromnumber
.- Parameters:
context
- aJSCContext
number
- a number- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
object
public static Value object(Context context, @Nullable @Nullable MemorySegment instance, @Nullable @Nullable Class jscClass) Create a newJSCValue
frominstance
. Ifinstance
isnull
a new empty object is created. Wheninstance
is provided,jscClass
must be provided too.jscClass
takes ownership ofinstance
that will be freed by theGDestroyNotify
passed to jsc_context_register_class().- Parameters:
context
- aJSCContext
instance
- an object instance ornull
jscClass
- theJSCClass
ofinstance
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
string
Create a newJSCValue
fromstring
. If you need to create aJSCValue
from a string containing null characters, use jsc_value_new_string_from_bytes() instead.- Parameters:
context
- aJSCContext
string
- a null-terminated string- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
stringFromBytes
Create a newJSCValue
frombytes
.- Parameters:
context
- aJSCContext
bytes
- aGBytes
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
typedArray
Create a new typed array containing a given amount of elements.Create a
JSCValue
referencing a new typed array with space forlength
elements of a giventype
. As all typed arrays must have an associatedArrayBuffer
, a new one of suitable size will be allocated to store the elements, which will be initialized to zero.The
type
must not beTypedArrayType.NONE
.- Parameters:
context
- aJSCContext
type
- the type of array elementslength
- number of elements in the array- Returns:
- a
JSCValue
- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
undefined
Create a newJSCValue
referencing <function>undefined</function> incontext
.- Parameters:
context
- aJSCContext
- Returns:
- a
JSCValue
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
arrayBufferGetData
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. Ifsize
is notnull
, 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 this Value 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.- Parameters:
size
- location where to store the size of the memory region.- Returns:
- pointer to memory.
-
arrayBufferGetSize
public long arrayBufferGetSize()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
.- Returns:
- size, in bytes.
-
constructorCall
Invoke <function>new</function> with constructor referenced by this Value. IfnParameters
is 0 no parameters will be passed to the constructor.- Parameters:
parameters
- theJSCValue
<!-- -->s to pass as parameters to the constructor, ornull
- Returns:
- a
JSCValue
referencing the newly created object instance.
-
functionCall
Call function referenced by this Value, passing the givenparameters
. IfnParameters
is 0 no parameters will be passed to the function.This function always returns a
JSCValue
, in case of void functions aJSCValue
referencing <function>undefined</function> is returned- Parameters:
parameters
- theJSCValue
<!-- -->s to pass as parameters to the function, ornull
- Returns:
- a
JSCValue
with the return value of the function.
-
getContext
Get theJSCContext
in which this Value was created.- Returns:
- the
JSCValue
context.
-
isArray
public boolean isArray()Get whether the value referenced by this Value is an array.- Returns:
- whether the value is an array.
-
isArrayBuffer
public boolean isArrayBuffer()Check whether the this Value is anArrayBuffer
.- Returns:
- whether the value is an
ArrayBuffer
-
isBoolean
public boolean isBoolean()Get whether the value referenced by this Value is a boolean.- Returns:
- whether the value is a boolean.
-
isConstructor
public boolean isConstructor()Get whether the value referenced by this Value is a constructor.- Returns:
- whether the value is a constructor.
-
isFunction
public boolean isFunction()Get whether the value referenced by this Value is a function- Returns:
- whether the value is a function.
-
isNull
public boolean isNull()Get whether the value referenced by this Value is <function>null</function>.- Returns:
- whether the value is null.
-
isNumber
public boolean isNumber()Get whether the value referenced by this Value is a number.- Returns:
- whether the value is a number.
-
isObject
public boolean isObject()Get whether the value referenced by this Value is an object.- Returns:
- whether the value is an object.
-
isString
public boolean isString()Get whether the value referenced by this Value is a string- Returns:
- whether the value is a string
-
isTypedArray
public boolean isTypedArray()Determines whether a value is a typed array.- Returns:
- Whether this Value is a typed array.
-
isUndefined
public boolean isUndefined()Get whether the value referenced by this Value is <function>undefined</function>.- Returns:
- whether the value is undefined.
-
newTypedArrayWithBuffer
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 giventype
, where the elements are stored at the memory region represented by the this Value.The
type
must not beTypedArrayType.NONE
.The
offset
andlength
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 asoffset
, and-1
aslength
), the whole this Value is exposed through the typed array. Omitting thelength
with a non-zerooffset
will expose the remainder of the this Value starting at the indicated offset.- Parameters:
type
- type of array elements.offset
- offset, in bytes.length
- number of array elements, or-1
.- Returns:
- a
JSCValue
-
objectDefinePropertyAccessor
public void objectDefinePropertyAccessor(String propertyName, Set<ValuePropertyFlags> flags, Type propertyType, @Nullable @Nullable Callback getter, @Nullable @Nullable Callback setter) Define or modify a property withpropertyName
in object referenced by this Value. When the property value needs to be getted or set,getter
andsetter
callbacks will be called. When the property is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with an accessor descriptor.Note that the value returned by
getter
must be fully transferred. In case of boxed types, you could useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as instance parameter.Note that
getter
andsetter
are called as functions and not methods, so they don't receive an instance as first parameter. Use jsc_class_add_property() if you want to add property accessor invoked as a method.- Parameters:
propertyName
- the name of the property to defineflags
-JSCValuePropertyFlags
propertyType
- theGType
of the propertygetter
- aGCallback
to be called to get the property valuesetter
- aGCallback
to be called to set the property value
-
objectDefinePropertyAccessor
public void objectDefinePropertyAccessor(String propertyName, ValuePropertyFlags flags, Type propertyType, @Nullable @Nullable Callback getter, @Nullable @Nullable Callback setter) Define or modify a property withpropertyName
in object referenced by this Value. When the property value needs to be getted or set,getter
andsetter
callbacks will be called. When the property is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with an accessor descriptor.Note that the value returned by
getter
must be fully transferred. In case of boxed types, you could useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as instance parameter.Note that
getter
andsetter
are called as functions and not methods, so they don't receive an instance as first parameter. Use jsc_class_add_property() if you want to add property accessor invoked as a method.- Parameters:
propertyName
- the name of the property to defineflags
-JSCValuePropertyFlags
propertyType
- theGType
of the propertygetter
- aGCallback
to be called to get the property valuesetter
- aGCallback
to be called to set the property value
-
objectDefinePropertyData
public void objectDefinePropertyData(String propertyName, Set<ValuePropertyFlags> flags, @Nullable @Nullable Value propertyValue) Define or modify a property withpropertyName
in object referenced by this Value. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with a data descriptor.- Parameters:
propertyName
- the name of the property to defineflags
-JSCValuePropertyFlags
propertyValue
- the default property value
-
objectDefinePropertyData
public void objectDefinePropertyData(String propertyName, ValuePropertyFlags flags, @Nullable @Nullable Value propertyValue) Define or modify a property withpropertyName
in object referenced by this Value. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with a data descriptor.- Parameters:
propertyName
- the name of the property to defineflags
-JSCValuePropertyFlags
propertyValue
- the default property value
-
objectDeleteProperty
Try to delete property withname
from this Value. This function will returnfalse
if the property was defined withoutValuePropertyFlags.CONFIGURABLE
flag.- Parameters:
name
- the property name- Returns:
true
if the property was deleted, orfalse
otherwise.
-
objectEnumerateProperties
Get the list of property names of this Value. Only properties defined withValuePropertyFlags.ENUMERABLE
flag will be collected.- Returns:
- a
null
-terminated array of strings containing the property names, ornull
if this Value doesn't have enumerable properties. Use g_strfreev() to free.
-
objectGetProperty
-
objectGetPropertyAtIndex
Get property atindex
from this Value.- Parameters:
index
- the property index- Returns:
- the property
JSCValue
.
-
objectHasProperty
Get whether this Value has property withname
.- Parameters:
name
- the property name- Returns:
true
if this Value has a property withname
, orfalse
otherwise
-
objectInvokeMethod
Invoke method withname
on object referenced by this Value, passing the givenparameters
. IfnParameters
is 0 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 jsc_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 aJSCValue
referencing <function>undefined</function> is returned.- Parameters:
name
- the method nameparameters
- theJSCValue
<!-- -->s to pass as parameters to the method, ornull
- Returns:
- a
JSCValue
with the return value of the method.
-
objectIsInstanceOf
Get whether the value referenced by this Value is an instance of classname
.- Parameters:
name
- a class name- Returns:
- whether the value is an object instance of class
name
.
-
objectSetProperty
-
objectSetPropertyAtIndex
Setproperty
atindex
on this Value.- Parameters:
index
- the property indexproperty
- theJSCValue
to set
-
toBoolean
public boolean toBoolean()Convert this Value to a boolean.- Returns:
- a
gboolean
result of the conversion.
-
toDouble
public double toDouble()Convert this Value to a double.- Returns:
- a
gdouble
result of the conversion.
-
toInt32
public int toInt32()Convert this Value to agint32
.- Returns:
- a
gint32
result of the conversion.
-
toJson
Create a JSON string of this Value serialization. Ifindent
is 0, the resulting JSON will not contain newlines. The size of the indent is clamped to 10 spaces.- Parameters:
indent
- The number of spaces to indent when nesting.- Returns:
- a null-terminated JSON string with serialization of this Value
-
toString
-
toStringAsBytes
Convert this Value to a string and return the results asGBytes
. This is needed to handle strings with null characters.- Returns:
- a
GBytes
with the result of the conversion.
-
typedArrayGetBuffer
Obtain theArrayBuffer
for the memory region of the typed array elements.- Returns:
- A
JSCValue
-
typedArrayGetData
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. Iflength
is notnull
, 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 theoffset
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 jsc_value_array_buffer_get_data() for details.
- Parameters:
length
- location to return the number of elements contained- Returns:
- pointer to memory.
-
typedArrayGetLength
public long typedArrayGetLength()Gets the number of elements in a typed array.- Returns:
- number of elements.
-
typedArrayGetOffset
public long typedArrayGetOffset()Gets the offset over the underlying array buffer data.- Returns:
- offset, in bytes.
-
typedArrayGetSize
public long typedArrayGetSize()Gets the size of a typed array.- Returns:
- size, in bytes.
-
typedArrayGetType
Gets the type of elements contained in a typed array.- Returns:
- type of the elements, or
TypedArrayType.NONE
if this Value is not a typed array.
-
builder
AValue.Builder
object constructs aValue
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withValue.Builder.build()
.
-