JavaScriptCore.Value

g GObject.Object GObject.Object JavaScriptCore.Value JavaScriptCore.Value GObject.Object->JavaScriptCore.Value

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new_array_buffer (context, data, size, destroy_notify, *user_data)

class

new_array_from_garray (context, array)

class

new_array_from_strv (context, strv)

class

new_boolean (context, value)

class

new_from_json (context, json)

class

new_function (context, name, callback, user_data, return_type, parameter_types)

class

new_function_variadic (context, name, callback, user_data, return_type)

class

new_null (context)

class

new_number (context, number)

class

new_object (context, instance, jsc_class)

class

new_string (context, string)

class

new_string_from_bytes (context, bytes)

class

new_typed_array (context, type, length)

class

new_undefined (context)

array_buffer_get_data (size)

array_buffer_get_size ()

constructor_call (parameters)

function_call (parameters)

get_context ()

is_array ()

is_array_buffer ()

is_boolean ()

is_constructor ()

is_function ()

is_null ()

is_number ()

is_object ()

is_string ()

is_typed_array ()

is_undefined ()

new_typed_array_with_buffer (type, offset, length)

object_define_property_accessor (property_name, flags, property_type, getter, setter, *user_data)

object_define_property_data (property_name, flags, property_value)

object_delete_property (name)

object_enumerate_properties ()

object_get_property (name)

object_get_property_at_index (index)

object_has_property (name)

object_invoke_method (name, parameters)

object_is_instance_of (name)

object_set_property (name, property)

object_set_property_at_index (index, property)

to_boolean ()

to_double ()

to_int32 ()

to_json (indent)

to_string ()

to_string_as_bytes ()

typed_array_get_buffer ()

typed_array_get_data ()

typed_array_get_length ()

typed_array_get_offset ()

typed_array_get_size ()

typed_array_get_type ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

context

JavaScriptCore.Context

r/w/co

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class JavaScriptCore.Value(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

JavaScriptCore.ValueClass

JavaScriptCore.Value represents a reference to a value in a JavaScriptCore.Context. The JavaScriptCore.Value protects the referenced value from being garbage collected.

classmethod new_array_buffer(context, data, size, destroy_notify, *user_data)
Parameters:
Returns:

A JavaScriptCore.Value, or None in case of exception.

Return type:

JavaScriptCore.Value or None

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:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value referencing an array with the items from array. If array is None or empty a new empty array will be created. Elements of array should be pointers to a JavaScriptCore.Value.

classmethod new_array_from_strv(context, strv)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value referencing an array of strings with the items from strv. If array is None or empty a new empty array will be created.

classmethod new_boolean(context, value)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value from value

classmethod new_from_json(context, json)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value referencing 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:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a function in context. If name is None an anonymous function will be created. When the function is called by JavaScript or JavaScriptCore.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_POINTER instead of the actual boxed GObject.GType to ensure that the instance owned by JavaScriptCore.Class is used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a JavaScriptCore.Value created with JavaScriptCore.Value.new_object() that receives the copy as instance parameter.

classmethod new_function_variadic(context, name, callback, user_data, return_type)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a function in context. If name is None an anonymous function will be created. When the function is called by JavaScript or JavaScriptCore.Value.function_call(), callback is called receiving an GLib.PtrArray of JavaScriptCore.Value 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 GObject.TYPE_POINTER instead of the actual boxed GObject.GType to ensure that the instance owned by JavaScriptCore.Class is used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a JavaScriptCore.Value created with JavaScriptCore.Value.new_object() that receives the copy as instance parameter.

classmethod new_null(context)
Parameters:

context (JavaScriptCore.Context) – a JavaScriptCore.Context

Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value referencing null in context.

classmethod new_number(context, number)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value from number.

classmethod new_object(context, instance, jsc_class)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value from instance. If instance is None 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 GLib.DestroyNotify passed to JavaScriptCore.Context.register_class().

classmethod new_string(context, string)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value from string. If you need to create a JavaScriptCore.Value from a string containing null characters, use JavaScriptCore.Value.new_string_from_bytes() instead.

classmethod new_string_from_bytes(context, bytes)
Parameters:
Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value from bytes.

classmethod new_typed_array(context, type, length)
Parameters:
Returns:

a JavaScriptCore.Value

Return type:

JavaScriptCore.Value

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

Create a JavaScriptCore.Value 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 JavaScriptCore.TypedArrayType.NONE.

New in version 2.38.

classmethod new_undefined(context)
Parameters:

context (JavaScriptCore.Context) – a JavaScriptCore.Context

Returns:

a JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

Create a new JavaScriptCore.Value referencing undefined in context.

array_buffer_get_data(size)
Parameters:

size (int or None) – location where to store the size of the memory region.

Returns:

pointer to memory.

Return type:

object or None

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:

int

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] or None) – the JavaScriptCore.Value s to pass as parameters to the constructor, or None

Returns:

a JavaScriptCore.Value referencing the newly created object instance.

Return type:

JavaScriptCore.Value

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] or None) – the JavaScriptCore.Value s to pass as parameters to the function, or None

Returns:

a JavaScriptCore.Value with the return value of the function.

Return type:

JavaScriptCore.Value

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 a JavaScriptCore.Value referencing undefined is returned

get_context()
Returns:

the JavaScriptCore.Value context.

Return type:

JavaScriptCore.Context

Get the JavaScriptCore.Context in which self was created.

is_array()
Returns:

whether the value is an array.

Return type:

bool

Get whether the value referenced by self is an array.

is_array_buffer()
Returns:

whether the value is an %ArrayBuffer

Return type:

bool

Check whether the self is an %ArrayBuffer.

New in version 2.38.

is_boolean()
Returns:

whether the value is a boolean.

Return type:

bool

Get whether the value referenced by self is a boolean.

is_constructor()
Returns:

whether the value is a constructor.

Return type:

bool

Get whether the value referenced by self is a constructor.

is_function()
Returns:

whether the value is a function.

Return type:

bool

Get whether the value referenced by self is a function

is_null()
Returns:

whether the value is null.

Return type:

bool

Get whether the value referenced by self is null.

is_number()
Returns:

whether the value is a number.

Return type:

bool

Get whether the value referenced by self is a number.

is_object()
Returns:

whether the value is an object.

Return type:

bool

Get whether the value referenced by self is an object.

is_string()
Returns:

whether the value is a string

Return type:

bool

Get whether the value referenced by self is a string

is_typed_array()
Returns:

Whether self is a typed array.

Return type:

bool

Determines whether a value is a typed array.

New in version 2.38.

is_undefined()
Returns:

whether the value is undefined.

Return type:

bool

Get whether the value referenced by self is undefined.

new_typed_array_with_buffer(type, offset, length)
Parameters:
Returns:

a JavaScriptCore.Value

Return type:

JavaScriptCore.Value

Create a new typed array value with elements from an array buffer.

Create a JavaScriptCore.Value 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 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 -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.

New in version 2.38.

object_define_property_accessor(property_name, flags, property_type, getter, setter, *user_data)
Parameters:

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.Class 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 GObject.TYPE_POINTER instead of the actual boxed GObject.GType to ensure that the instance owned by JavaScriptCore.Class is used. If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a JavaScriptCore.Value created with JavaScriptCore.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:

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:

True if the property was deleted, or False otherwise.

Return type:

bool

Try to delete property with name from self. This function will return False if the property was defined without JavaScriptCore.ValuePropertyFlags.CONFIGURABLE flag.

object_enumerate_properties()
Returns:

a None-terminated array of strings containing the property names, or None if self doesn’t have enumerable properties. Use GLib.strfreev() to free.

Return type:

[str] or None

Get the list of property names of self. Only properties defined with JavaScriptCore.ValuePropertyFlags.ENUMERABLE flag will be collected.

object_get_property(name)
Parameters:

name (str) – the property name

Returns:

the property JavaScriptCore.Value.

Return type:

JavaScriptCore.Value

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:

JavaScriptCore.Value

Get property at index from self.

object_has_property(name)
Parameters:

name (str) – the property name

Returns:

True if self has a property with name, or False otherwise

Return type:

bool

Get whether self has property with name.

object_invoke_method(name, parameters)
Parameters:
Returns:

a JavaScriptCore.Value with the return value of the method.

Return type:

JavaScriptCore.Value

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 a JavaScriptCore.Value referencing 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:

bool

Get whether the value referenced by self is an instance of class name.

object_set_property(name, property)
Parameters:

Set property with name on self.

object_set_property_at_index(index, property)
Parameters:

Set property at index on self.

to_boolean()
Returns:

a bool result of the conversion.

Return type:

bool

Convert self to a boolean.

to_double()
Returns:

a float result of the conversion.

Return type:

float

Convert self to a double.

to_int32()
Returns:

a #gint32 result of the conversion.

Return type:

int

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:

str

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:

str

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.Bytes with the result of the conversion.

Return type:

GLib.Bytes

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:

A JavaScriptCore.Value

Return type:

JavaScriptCore.Value

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:

(object or None, length: int)

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 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 JavaScriptCore.Value.array_buffer_get_data() for details.

New in version 2.38.

typed_array_get_length()
Returns:

number of elements.

Return type:

int

Gets the number of elements in a typed array.

New in version 2.38.

typed_array_get_offset()
Returns:

offset, in bytes.

Return type:

int

Gets the offset over the underlying array buffer data.

New in version 2.38.

typed_array_get_size()
Returns:

size, in bytes.

Return type:

int

Gets the size of a typed array.

New in version 2.38.

typed_array_get_type()
Returns:

type of the elements, or JavaScriptCore.TypedArrayType.NONE if self is not a typed array.

Return type:

JavaScriptCore.TypedArrayType

Gets the type of elements contained in a typed array.

New in version 2.38.

Property Details

JavaScriptCore.Value.props.context
Name:

context

Type:

JavaScriptCore.Context

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The JavaScriptCore.Context in which the value was created.