Top | Description | Object Hierarchy | Properties | ![]() | ![]() | ![]() | ![]() |
JSCValue represents a reference to a value in aJSCContext. The JSCValueprotects the referenced value from being garbage collected.
JSCContext *jsc_value_get_context (JSCValue *value
);
Get theJSCContext in whichvalue
was created.
JSCValue *jsc_value_new_undefined (JSCContext *context
);
Create a newJSCValue referencingundefined
incontext
.
gbooleanjsc_value_is_undefined (JSCValue *value
);
Get whether the value referenced byvalue
isundefined
.
JSCValue *jsc_value_new_null (JSCContext *context
);
Create a newJSCValue referencingnull
incontext
.
gbooleanjsc_value_is_null (JSCValue *value
);
Get whether the value referenced byvalue
isnull
.
JSCValue *jsc_value_new_number (JSCContext *context
,double number
);
Create a newJSCValue fromnumber
.
gbooleanjsc_value_is_number (JSCValue *value
);
Get whether the value referenced byvalue
is a number.
JSCValue *jsc_value_new_boolean (JSCContext *context
,gboolean value
);
Create a newJSCValue fromvalue
gbooleanjsc_value_is_boolean (JSCValue *value
);
Get whether the value referenced byvalue
is a boolean.
JSCValue *jsc_value_new_string (JSCContext *context
,constchar *string
);
Create a newJSCValue fromstring
. If you need to create aJSCValue from astring containing null characters, usejsc_value_new_string_from_bytes()
instead.
JSCValue *jsc_value_new_string_from_bytes (JSCContext *context
,GBytes *bytes
);
Create a newJSCValue frombytes
.
gbooleanjsc_value_is_string (JSCValue *value
);
Get whether the value referenced byvalue
is a string
char *jsc_value_to_string (JSCValue *value
);
Convertvalue
to a string. Usejsc_value_to_string_as_bytes()
instead, if you need tohandle strings containing null characters.
GBytes *jsc_value_to_string_as_bytes (JSCValue *value
);
Convertvalue
to a string and return the results asGBytes. This is neededto handle strings with null characters.
JSCValue *jsc_value_new_array (JSCContext *context
,GType first_item_type
,...
);
Create a newJSCValue referencing an array with the given items. Iffirst_item_type
isG_TYPE_NONE
an empty array is created.
context | ||
first_item_type | GType of first item, or | |
... | value of the first item, followed optionally by more type/value pairs, followed by |
JSCValue *jsc_value_new_array_from_garray (JSCContext *context
,GPtrArray *array
);
Create a newJSCValue referencing an array with the items fromarray
. Ifarray
isNULL
or empty a new empty array will be created. Elements ofarray
should bepointers to aJSCValue.
JSCValue *jsc_value_new_array_from_strv (JSCContext *context
,constchar *const *strv
);
Create a newJSCValue referencing an array of strings with the items fromstrv
. Ifarray
isNULL
or empty a new empty array will be created.
context | ||
strv | a | [array zero-terminated=1][element-type utf8] |
gbooleanjsc_value_is_array (JSCValue *value
);
Get whether the value referenced byvalue
is an array.
JSCValue *jsc_value_new_object (JSCContext *context
,gpointer instance
,JSCClass *jsc_class
);
Create a newJSCValue frominstance
. Ifinstance
isNULL
a new empty object is created.Wheninstance
is provided,jsc_class
must be provided too.jsc_class
takes ownership ofinstance
that will be freed by theGDestroyNotify passed tojsc_context_register_class()
.
context | ||
instance | an object instance or | [nullable][transfer full] |
jsc_class | theJSCClass of | [nullable] |
gbooleanjsc_value_is_object (JSCValue *value
);
Get whether the value referenced byvalue
is an object.
gbooleanjsc_value_object_is_instance_of (JSCValue *value
,constchar *name
);
Get whether the value referenced byvalue
is an instance of classname
.
voidjsc_value_object_set_property (JSCValue *value
,constchar *name
,JSCValue *property
);
Setproperty
withname
onvalue
.
JSCValue *jsc_value_object_get_property (JSCValue *value
,constchar *name
);
Get property withname
fromvalue
.
voidjsc_value_object_set_property_at_index (JSCValue *value
,guint index
,JSCValue *property
);
Setproperty
atindex
onvalue
.
JSCValue *jsc_value_object_get_property_at_index (JSCValue *value
,guint index
);
Get property atindex
fromvalue
.
gbooleanjsc_value_object_has_property (JSCValue *value
,constchar *name
);
Get whethervalue
has property withname
.
gbooleanjsc_value_object_delete_property (JSCValue *value
,constchar *name
);
Try to delete property withname
fromvalue
. This function will returnFALSE
ifthe property was defined withoutJSC_VALUE_PROPERTY_CONFIGURABLE
flag.
gchar **jsc_value_object_enumerate_properties (JSCValue *value
);
Get the list of property names ofvalue
. Only properties defined withJSC_VALUE_PROPERTY_ENUMERABLE
flag will be collected.
aNULL
-terminated array of strings containing theproperty names, orNULL
ifvalue
doesn't have enumerable properties. Useg_strfreev()
to free.
JSCValue *jsc_value_object_invoke_method (JSCValue *value
,constchar *name
,GType first_parameter_type
,...
);
Invoke method withname
on object referenced byvalue
, passing the given parameters. Iffirst_parameter_type
isG_TYPE_NONE
no parameters will be passed to the method.The object instance will be handled automatically even when the method is a custom oneregistered withjsc_class_add_method()
, so it should never be passed explicitly as parameterof this function.
This function always returns aJSCValue, in case of void methods aJSCValue referencingundefined
is returned.
value | ||
name | the method name | |
first_parameter_type | GType of first parameter, or | |
... | value of the first parameter, followed optionally by more type/value pairs, followed by |
JSCValue *jsc_value_object_invoke_methodv (JSCValue *value
,constchar *name
,guint n_parameters
,JSCValue **parameters
);
Invoke method withname
on object referenced byvalue
, passing the givenparameters
. Ifn_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 oneregistered withjsc_class_add_method()
, so it should never be passed explicitly as parameterof this function.
This function always returns aJSCValue, in case of void methods aJSCValue referencingundefined
is returned.
[rename-to jsc_value_object_invoke_method]
value | ||
name | the method name | |
n_parameters | the number of parameters | |
parameters | [nullable][array length=n_parameters][element-type JSCValue] |
voidjsc_value_object_define_property_data (JSCValue *value
,constchar *property_name
,JSCValuePropertyFlags flags
,JSCValue *property_value
);
Define or modify a property withproperty_name
in object referenced byvalue
. This is equivalent toJavaScriptObject.defineProperty()
when used with a data descriptor.
value | ||
property_name | the name of the property to define | |
flags | ||
property_value | the default property value. | [nullable] |
voidjsc_value_object_define_property_accessor (JSCValue *value
,constchar *property_name
,JSCValuePropertyFlags flags
,GType property_type
,GCallback getter
,GCallback setter
,gpointer user_data
,GDestroyNotify destroy_notify
);
Define or modify a property withproperty_name
in object referenced byvalue
. When theproperty value needs to be getted or set,getter
andsetter
callbacks will be called.When the property is cleared in theJSCClass context,destroy_notify
is called withuser_data
as parameter. This is equivalent to JavaScriptObject.defineProperty()
when used with an accessor descriptor.
Note that the value returned bygetter
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 createdwithjsc_value_new_object()
that receives the copy as instance parameter.
value | ||
property_name | the name of the property to define | |
flags | ||
property_type | theGType of the property | |
getter | aGCallback to be called to get the property value. | [scope async][nullable] |
setter | aGCallback to be called to set the property value. | [scope async][nullable] |
user_data | user data to pass to | [closure] |
destroy_notify | destroy notifier for | [nullable] |
JSCValue *jsc_value_new_function (JSCContext *context
,constchar *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_params
,...
);
Create a function incontext
. Ifname
isNULL
an anonymous function will be created.When the function is called by JavaScript orjsc_value_function_call()
,callback
is calledreceiving the function parameters and thenuser_data
as last parameter. When the function iscleared incontext
,destroy_notify
is called withuser_data
as parameter.
Note that the value returned bycallback
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 createdwithjsc_value_new_object()
that receives the copy as instance parameter.
context | ||
name | the function name or | [nullable] |
callback | [scope async] | |
user_data | user data to pass to | [closure] |
destroy_notify | destroy notifier for | [nullable] |
return_type | theGType of the function return value, or | |
n_params | the number of parameter types to follow or 0 if the function doesn't receive parameters. | |
... | a list ofGTypes, one for each parameter. |
JSCValue *jsc_value_new_functionv (JSCContext *context
,constchar *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_parameters
,GType *parameter_types
);
Create a function incontext
. Ifname
isNULL
an anonymous function will be created.When the function is called by JavaScript orjsc_value_function_call()
,callback
is calledreceiving the function parameters and thenuser_data
as last parameter. When the function iscleared incontext
,destroy_notify
is called withuser_data
as parameter.
Note that the value returned bycallback
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 createdwithjsc_value_new_object()
that receives the copy as instance parameter.
[rename-to jsc_value_new_function]
context | ||
name | the function name or | [nullable] |
callback | [scope async] | |
user_data | user data to pass to | [closure] |
destroy_notify | destroy notifier for | [nullable] |
return_type | theGType of the function return value, or | |
n_parameters | the number of parameters | |
parameter_types | [nullable][array length=n_parameters][element-type GType] |
JSCValue *jsc_value_new_function_variadic (JSCContext *context
,constchar *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
);
Create a function incontext
. Ifname
isNULL
an anonymous function will be created.When the function is called by JavaScript orjsc_value_function_call()
,callback
is calledreceiving anGPtrArray ofJSCValues with the arguments and thenuser_data
as last parameter.When the function is cleared incontext
,destroy_notify
is called withuser_data
as parameter.
Note that the value returned bycallback
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 createdwithjsc_value_new_object()
that receives the copy as instance parameter.
context | ||
name | the function name or | [nullable] |
callback | [scope async] | |
user_data | user data to pass to | [closure] |
destroy_notify | destroy notifier for | [nullable] |
return_type | theGType of the function return value, or |
gbooleanjsc_value_is_function (JSCValue *value
);
Get whether the value referenced byvalue
is a function
JSCValue *jsc_value_function_call (JSCValue *value
,GType first_parameter_type
,...
);
Call function referenced byvalue
, passing the given parameters. Iffirst_parameter_type
isG_TYPE_NONE
no parameters will be passed to the function.
This function always returns aJSCValue, in case of void functions aJSCValue referencingundefined
is returned
value | ||
first_parameter_type | GType of first parameter, or | |
... | value of the first parameter, followed optionally by more type/value pairs, followed by |
JSCValue *jsc_value_function_callv (JSCValue *value
,guint n_parameters
,JSCValue **parameters
);
Call function referenced byvalue
, passing the givenparameters
. Ifn_parameters
is 0 no parameters will be passed to the function.
This function always returns aJSCValue, in case of void functions aJSCValue referencingundefined
is returned
[rename-to jsc_value_function_call]
value | ||
n_parameters | the number of parameters | |
parameters | [nullable][array length=n_parameters][element-type JSCValue] |
gbooleanjsc_value_is_constructor (JSCValue *value
);
Get whether the value referenced byvalue
is a constructor.
JSCValue *jsc_value_constructor_call (JSCValue *value
,GType first_parameter_type
,...
);
Invokenew
with constructor referenced byvalue
. Iffirst_parameter_type
isG_TYPE_NONE
no parameters will be passed to the constructor.
value | ||
first_parameter_type | GType of first parameter, or | |
... | value of the first parameter, followed optionally by more type/value pairs, followed by |
JSCValue *jsc_value_constructor_callv (JSCValue *value
,guint n_parameters
,JSCValue **parameters
);
Invokenew
with constructor referenced byvalue
. Ifn_parameters
is 0 no parameters will be passed to the constructor.
[rename-to jsc_value_constructor_call]
value | ||
n_parameters | the number of parameters | |
parameters | theJSCValues to pass as parameters to the constructor, or | [nullable][array length=n_parameters][element-type JSCValue] |
JSCValue *jsc_value_new_from_json (JSCContext *context
,constchar *json
);
Create a newJSCValue referencing a new value created by parsingjson
.
Since:2.28
Flags used when defining properties withjsc_value_object_define_property_data()
andjsc_value_object_define_property_accessor()
.
the type of the property descriptor may be changed and theproperty may be deleted from the corresponding object. | ||
the property shows up during enumeration of the properties onthe corresponding object. | ||
the value associated with the property may be changed with anassignment operator. This doesn't have any effect when passed to |
“context”
property“context”JSCContext *
TheJSCContext in which the value was created.
Owner: JSCValue
Flags: Read / Write / Construct Only