JavaScriptCore.Value¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/co |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
parent |
r |
Class Details¶
- class JavaScriptCore.Value(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
JavaScriptCore.Valuerepresents a reference to a value in aJavaScriptCore.Context. TheJavaScriptCore.Valueprotects the referenced value from being garbage collected.- classmethod new_array_buffer(context, data, size, destroy_notify, *user_data)¶
- Parameters:
context (
JavaScriptCore.Context) – AJavaScriptCore.Contextsize (
int) – Size in bytes of the memory region.destroy_notify (
GLib.DestroyNotifyorNone) – destroy notifier for user_data.
- Returns:
A
JavaScriptCore.Value, orNonein case of exception.- Return type:
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:
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:
void *bytes = g_malloc0 (100); JSCValue *value = jsc_value_new_array_buffer (context, bytes, 100, g_free, bytes);
New in version 2.38.
- classmethod new_array_from_garray(context, array)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextarray ([
JavaScriptCore.Value] orNone) – aGLib.PtrArray
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuereferencing an array with the items from array. If array isNoneor empty a new empty array will be created. Elements of array should be pointers to aJavaScriptCore.Value.
- classmethod new_array_from_strv(context, strv)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Context
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuereferencing an array of strings with the items from strv. If array isNoneor empty a new empty array will be created.
- classmethod new_boolean(context, value)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Context
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuefrom value
- classmethod new_from_json(context, json)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextjson (
str) – the JSON string to be parsed
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuereferencing a new value created by parsing json.New in version 2.28.
- classmethod new_function(context, name, callback, user_data, return_type, parameter_types)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextcallback (
GObject.Callback) – aGObject.Callback.return_type (
GObject.GType) – theGObject.GTypeof the function return value, orGObject.TYPE_NONEif the function is void.parameter_types ([
GObject.GType] orNone) – a list ofGObject.GTypes, one for each parameter, orNone
- Returns:
- Return type:
Create a function in context. If name is
Nonean anonymous function will be created. When the function is called by JavaScript orJavaScriptCore.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
GObject.TYPE_POINTERinstead of the actual boxedGObject.GTypeto ensure that the instance owned byJavaScriptCore.Classis used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return aJavaScriptCore.Valuecreated withJavaScriptCore.Value.new_object() that receives the copy as instance parameter.
- classmethod new_function_variadic(context, name, callback, user_data, return_type)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextcallback (
GObject.Callback) – aGObject.Callback.return_type (
GObject.GType) – theGObject.GTypeof the function return value, orGObject.TYPE_NONEif the function is void.
- Returns:
- Return type:
Create a function in context. If name is
Nonean anonymous function will be created. When the function is called by JavaScript orJavaScriptCore.Value.function_call(), callback is called receiving anGLib.PtrArrayofJavaScriptCore.Values 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
GObject.TYPE_POINTERinstead of the actual boxedGObject.GTypeto ensure that the instance owned byJavaScriptCore.Classis used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return aJavaScriptCore.Valuecreated withJavaScriptCore.Value.new_object() that receives the copy as instance parameter.
- classmethod new_null(context)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Context- Returns:
- Return type:
Create a new
JavaScriptCore.Valuereferencing null in context.
- classmethod new_number(context, number)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextnumber (
float) – a number
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuefrom number.
- classmethod new_object(context, instance, jsc_class)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextjsc_class (
JavaScriptCore.ClassorNone) – theJavaScriptCore.Classof instance
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuefrom instance. If instance isNonea 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 theGLib.DestroyNotifypassed toJavaScriptCore.Context.register_class().
- classmethod new_promise(context, executor, *user_data)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextexecutor (
JavaScriptCore.Executor) – an initialization callback
- Returns:
a deferred promise object
- Return type:
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.
New in version 2.48.
- classmethod new_string(context, string)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Context
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuefrom string. If you need to create aJavaScriptCore.Valuefrom a string containing null characters, useJavaScriptCore.Value.new_string_from_bytes() instead.
- classmethod new_string_from_bytes(context, bytes)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contextbytes (
GLib.BytesorNone) – aGLib.Bytes
- Returns:
- Return type:
Create a new
JavaScriptCore.Valuefrom bytes.
- classmethod new_typed_array(context, type, length)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Contexttype (
JavaScriptCore.TypedArrayType) – the type of array elementslength (
int) – number of elements in the array
- Returns:
- Return type:
Create a new typed array containing a given amount of elements.
Create a
JavaScriptCore.Valuereferencing a new typed array with space for length elements of a given type. 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* be
JavaScriptCore.TypedArrayType.NONE.New in version 2.38.
- classmethod new_undefined(context)¶
- Parameters:
context (
JavaScriptCore.Context) – aJavaScriptCore.Context- Returns:
- Return type:
Create a new
JavaScriptCore.Valuereferencing undefined in context.
- array_buffer_get_data(size)¶
- Parameters:
size (
intorNone) – location where to store the size of the memory region.- Returns:
pointer to memory.
- Return type:
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
None, 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.
New in version 2.38.
- array_buffer_get_size()¶
- Returns:
size, in bytes.
- Return type:
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.
New in version 2.38.
- constructor_call(parameters)¶
- Parameters:
parameters ([
JavaScriptCore.Value] orNone) – theJavaScriptCore.Values to pass as parameters to the constructor, orNone- Returns:
a
JavaScriptCore.Valuereferencing the newly created object instance.- Return type:
Invoke new with constructor referenced by self. If n_parameters is 0 no parameters will be passed to the constructor.
- function_call(parameters)¶
- Parameters:
parameters ([
JavaScriptCore.Value] orNone) – theJavaScriptCore.Values to pass as parameters to the function, orNone- Returns:
a
JavaScriptCore.Valuewith the return value of the function.- Return type:
Call function referenced by self, passing the given parameters. If n_parameters is 0 no parameters will be passed to the function.
This function always returns a
JavaScriptCore.Value, in case of void functions aJavaScriptCore.Valuereferencing undefined is returned
- get_context()¶
- Returns:
the
JavaScriptCore.Valuecontext.- Return type:
Get the
JavaScriptCore.Contextin which self was created.
- is_array()¶
- Returns:
whether the value is an array.
- Return type:
Get whether the value referenced by self is an array.
- is_array_buffer()¶
- Returns:
whether the value is an %ArrayBuffer
- Return type:
Check whether the self is an %ArrayBuffer.
New in version 2.38.
- is_boolean()¶
- Returns:
whether the value is a boolean.
- Return type:
Get whether the value referenced by self is a boolean.
- is_constructor()¶
- Returns:
whether the value is a constructor.
- Return type:
Get whether the value referenced by self is a constructor.
- is_function()¶
- Returns:
whether the value is a function.
- Return type:
Get whether the value referenced by self is a function
- is_null()¶
- Returns:
whether the value is null.
- Return type:
Get whether the value referenced by self is null.
- is_number()¶
- Returns:
whether the value is a number.
- Return type:
Get whether the value referenced by self is a number.
- is_object()¶
- Returns:
whether the value is an object.
- Return type:
Get whether the value referenced by self is an object.
- is_string()¶
- Returns:
whether the value is a string
- Return type:
Get whether the value referenced by self is a string
- is_typed_array()¶
- Returns:
Whether self is a typed array.
- Return type:
Determines whether a value is a typed array.
New in version 2.38.
- is_undefined()¶
- Returns:
whether the value is undefined.
- Return type:
Get whether the value referenced by self is undefined.
- new_typed_array_with_buffer(type, offset, length)¶
- Parameters:
type (
JavaScriptCore.TypedArrayType) – type of array elements.offset (
int) – offset, in bytes.length (
int) – number of array elements, or-1.
- Returns:
- Return type:
Create a new typed array value with elements from an array buffer.
Create a
JavaScriptCore.Valuereferencing 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
JavaScriptCore.TypedArrayType.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
-1as 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.New in version 2.38.
- object_define_property_accessor(property_name, flags, property_type, getter, setter, *user_data)¶
- Parameters:
property_name (
str) – the name of the property to defineflags (
JavaScriptCore.ValuePropertyFlags) –JavaScriptCore.ValuePropertyFlagsproperty_type (
GObject.GType) – theGObject.GTypeof the propertygetter (
GObject.CallbackorNone) – aGObject.Callbackto be called to get the property valuesetter (
GObject.CallbackorNone) – aGObject.Callbackto be called to set the property valueuser_data (
objectorNone) – user data to pass to getter and setter
Define or modify a property with property_name in object referenced by self. When the property value needs to be getted or set, getter and setter callbacks will be called. When the property is cleared in the
JavaScriptCore.Classcontext, 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
GObject.TYPE_POINTERinstead of the actual boxedGObject.GTypeto ensure that the instance owned byJavaScriptCore.Classis used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return aJavaScriptCore.Valuecreated withJavaScriptCore.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
JavaScriptCore.Class.add_property() if you want to add property accessor invoked as a method.
- object_define_property_data(property_name, flags, property_value)¶
- Parameters:
property_name (
str) – the name of the property to defineflags (
JavaScriptCore.ValuePropertyFlags) –JavaScriptCore.ValuePropertyFlagsproperty_value (
JavaScriptCore.ValueorNone) – the default property value
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.
- object_delete_property(name)¶
- Parameters:
name (
str) – the property name- Returns:
- Return type:
Try to delete property with name from self. This function will return
Falseif the property was defined withoutJavaScriptCore.ValuePropertyFlags.CONFIGURABLEflag.
- object_enumerate_properties()¶
- Returns:
a
None-terminated array of strings containing the property names, orNoneif self doesn’t have enumerable properties. UseGLib.strfreev() to free.- Return type:
Get the list of property names of self. Only properties defined with
JavaScriptCore.ValuePropertyFlags.ENUMERABLEflag will be collected.
- object_get_property(name)¶
- Parameters:
name (
str) – the property name- Returns:
the property
JavaScriptCore.Value.- Return type:
Get property with name from self.
- object_get_property_at_index(index)¶
- Parameters:
index (
int) – the property index- Returns:
the property
JavaScriptCore.Value.- Return type:
Get property at index from self.
- object_has_property(name)¶
- Parameters:
name (
str) – the property name- Returns:
- Return type:
Get whether self has property with name.
- object_invoke_method(name, parameters)¶
- Parameters:
name (
str) – the method nameparameters ([
JavaScriptCore.Value] orNone) – theJavaScriptCore.Values to pass as parameters to the method, orNone
- Returns:
a
JavaScriptCore.Valuewith the return value of the method.- Return type:
Invoke method with name on object referenced by self, passing the given parameters. If n_parameters 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
JavaScriptCore.Class.add_method(), so it should never be passed explicitly as parameter of this function.This function always returns a
JavaScriptCore.Value, in case of void methods aJavaScriptCore.Valuereferencing undefined is returned.
- object_is_instance_of(name)¶
- Parameters:
name (
str) – a class name- Returns:
whether the value is an object instance of class name.
- Return type:
Get whether the value referenced by self is an instance of class name.
- object_set_property(name, property)¶
- Parameters:
name (
str) – the property nameproperty (
JavaScriptCore.Value) – theJavaScriptCore.Valueto set
Set property with name on self.
- object_set_property_at_index(index, property)¶
- Parameters:
index (
int) – the property indexproperty (
JavaScriptCore.Value) – theJavaScriptCore.Valueto set
Set property at index on self.
- to_boolean()¶
-
Convert self to a boolean.
- to_double()¶
-
Convert self to a double.
- to_int32()¶
- Returns:
a #gint32 result of the conversion.
- Return type:
Convert self to a #gint32.
- to_json(indent)¶
- Parameters:
indent (
int) – The number of spaces to indent when nesting.- Returns:
a null-terminated JSON string with serialization of self
- Return type:
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.
New in version 2.28.
- to_string()¶
- Returns:
a null-terminated string result of the conversion.
- Return type:
Convert self to a string. Use
JavaScriptCore.Value.to_string_as_bytes() instead, if you need to handle strings containing null characters.
- to_string_as_bytes()¶
- Returns:
a
GLib.Byteswith the result of the conversion.- Return type:
Convert self to a string and return the results as
GLib.Bytes. This is needed to handle strings with null characters.
- typed_array_get_buffer()¶
- Returns:
- Return type:
Obtain the %ArrayBuffer for the memory region of the typed array elements.
New in version 2.38.
- typed_array_get_data()¶
- Returns:
pointer to memory.
- length:
location to return the number of elements contained
- Return type:
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
None, 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
JavaScriptCore.TypedArrayType), and has theoffsetover 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
JavaScriptCore.Value.array_buffer_get_data() for details.New in version 2.38.
- typed_array_get_length()¶
- Returns:
number of elements.
- Return type:
Gets the number of elements in a typed array.
New in version 2.38.
- typed_array_get_offset()¶
- Returns:
offset, in bytes.
- Return type:
Gets the offset over the underlying array buffer data.
New in version 2.38.
- typed_array_get_size()¶
- Returns:
size, in bytes.
- Return type:
Gets the size of a typed array.
New in version 2.38.
- typed_array_get_type()¶
- Returns:
type of the elements, or
JavaScriptCore.TypedArrayType.NONEif self is not a typed array.- Return type:
Gets the type of elements contained in a typed array.
New in version 2.38.
Property Details¶
- JavaScriptCore.Value.props.context¶
- Name:
context- Type:
- Default Value:
- Flags:
The
JavaScriptCore.Contextin which the value was created.