Top |
JSCValue * | (*JSCClassGetPropertyFunction) () |
gboolean | (*JSCClassSetPropertyFunction) () |
gboolean | (*JSCClassHasPropertyFunction) () |
gboolean | (*JSCClassDeletePropertyFunction) () |
gchar ** | (*JSCClassEnumeratePropertiesFunction) () |
const char * | jsc_class_get_name () |
JSCClass * | jsc_class_get_parent () |
JSCValue * | jsc_class_add_constructor () |
JSCValue * | jsc_class_add_constructorv () |
JSCValue * | jsc_class_add_constructor_variadic () |
void | jsc_class_add_method () |
void | jsc_class_add_methodv () |
void | jsc_class_add_method_variadic () |
void | jsc_class_add_property () |
JSCContext * | context | Write / Construct Only |
char * | name | Read / Write / Construct Only |
JSCClass * | parent | Read / Write / Construct Only |
A JSSClass represents a custom JavaScript class registered by the user in a JSCContext. It allows to create new JavaScripts objects whose instances are created by the user using this API. It's possible to add constructors, properties and methods for a JSSClass by providing GCallbacks to implement them.
JSCValue * (*JSCClassGetPropertyFunction) (JSCClass *jsc_class
,JSCContext *context
,gpointer instance
,const char *name
);
The type of get_property in JSCClassVTable. This is only required when you need to handle external properties not added to the prototype.
a JSCValue or NULL
to forward the request to
the parent class or prototype chain.
[transfer full][nullable]
gboolean (*JSCClassSetPropertyFunction) (JSCClass *jsc_class
,JSCContext *context
,gpointer instance
,const char *name
,JSCValue *value
);
The type of set_property in JSCClassVTable. This is only required when you need to handle external properties not added to the prototype.
gboolean (*JSCClassHasPropertyFunction) (JSCClass *jsc_class
,JSCContext *context
,gpointer instance
,const char *name
);
The type of has_property in JSCClassVTable. This is only required when you need to handle external properties not added to the prototype.
gboolean (*JSCClassDeletePropertyFunction) (JSCClass *jsc_class
,JSCContext *context
,gpointer instance
,const char *name
);
The type of delete_property in JSCClassVTable. This is only required when you need to handle external properties not added to the prototype.
gchar ** (*JSCClassEnumeratePropertiesFunction) (JSCClass *jsc_class
,JSCContext *context
,gpointer instance
);
The type of enumerate_properties in JSCClassVTable. This is only required when you need to handle external properties not added to the prototype.
const char *
jsc_class_get_name (JSCClass *jsc_class
);
Get the class name of jsc_class
JSCClass *
jsc_class_get_parent (JSCClass *jsc_class
);
Get the parent class of jsc_class
JSCValue * jsc_class_add_constructor (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_params
,...
);
Add a constructor to jsc_class
. If name
is NULL
, the class name will be used. When new
is used with the constructor or jsc_value_constructor_call()
is called, callback
is invoked receiving the
parameters and user_data
as the last parameter. When the constructor object is cleared in the JSCClass context,
destroy_notify
is called with user_data
as parameter.
This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
jsc_context_set_value()
to make the constructor available in the global object.
Note that the value returned by callback
is adopted by jsc_class
, and the GDestroyNotify passed to
jsc_context_register_class()
is responsible for disposing of it.
[skip]
jsc_class |
a JSCClass |
|
name |
the constructor name or |
[nullable] |
callback |
a GCallback to be called to create an instance of |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the constructor return value |
|
n_params |
the number of parameter types to follow or 0 if constructor doesn't receive parameters. |
|
... |
a list of GTypes, one for each parameter. |
JSCValue * jsc_class_add_constructorv (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_parameters
,GType *parameter_types
);
Add a constructor to jsc_class
. If name
is NULL
, the class name will be used. When new
is used with the constructor or jsc_value_constructor_call()
is called, callback
is invoked receiving the
parameters and user_data
as the last parameter. When the constructor object is cleared in the JSCClass context,
destroy_notify
is called with user_data
as parameter.
This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
jsc_context_set_value()
to make the constructor available in the global object.
Note that the value returned by callback
is adopted by jsc_class
, and the GDestroyNotify passed to
jsc_context_register_class()
is responsible for disposing of it.
[rename-to jsc_class_add_constructor]
jsc_class |
a JSCClass |
|
name |
the constructor name or |
[nullable] |
callback |
a GCallback to be called to create an instance of |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the constructor return value |
|
n_parameters |
the number of parameters |
|
parameter_types |
a list of GTypes, one for each parameter, or |
[nullable][array length=n_parameters][element-type GType] |
JSCValue * jsc_class_add_constructor_variadic (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
);
Add a constructor to jsc_class
. If name
is NULL
, the class name will be used. When new
is used with the constructor or jsc_value_constructor_call()
is called, callback
is invoked receiving
a GPtrArray of JSCValues as arguments and user_data
as the last parameter. When the constructor object
is cleared in the JSCClass context, destroy_notify
is called with user_data
as parameter.
This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
jsc_context_set_value()
to make the constructor available in the global object.
Note that the value returned by callback
is adopted by jsc_class
, and the GDestroyNotify passed to
jsc_context_register_class()
is responsible for disposing of it.
jsc_class |
a JSCClass |
|
name |
the constructor name or |
[nullable] |
callback |
a GCallback to be called to create an instance of |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the constructor return value |
void jsc_class_add_method (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_params
,...
);
Add method with name
to jsc_class
. When the method is called by JavaScript or jsc_value_object_invoke_method()
,
callback
is called receiving the class instance as first parameter, followed by the method parameters and then
user_data
as last parameter. When the method is cleared in the JSCClass context, destroy_notify
is called with
user_data
as parameter.
Note that the value returned by callback
must be transfer full. In case of non-refcounted boxed types, you should 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 jsc_value_new_object()
that receives the copy as the instance parameter.
[skip]
jsc_class |
a JSCClass |
|
name |
the method name |
|
callback |
a GCallback to be called to invoke method |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the method return value, or |
|
n_params |
the number of parameter types to follow or 0 if the method doesn't receive parameters. |
|
... |
a list of GTypes, one for each parameter. |
void jsc_class_add_methodv (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
,guint n_parameters
,GType *parameter_types
);
Add method with name
to jsc_class
. When the method is called by JavaScript or jsc_value_object_invoke_method()
,
callback
is called receiving the class instance as first parameter, followed by the method parameters and then
user_data
as last parameter. When the method is cleared in the JSCClass context, destroy_notify
is called with
user_data
as parameter.
Note that the value returned by callback
must be transfer full. In case of non-refcounted boxed types, you should 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 jsc_value_new_object()
that receives the copy as the instance parameter.
[rename-to jsc_class_add_method]
jsc_class |
a JSCClass |
|
name |
the method name |
|
callback |
a GCallback to be called to invoke method |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the method return value, or |
|
n_parameters |
the number of parameter types to follow or 0 if the method doesn't receive parameters. |
|
parameter_types |
a list of GTypes, one for each parameter, or |
[nullable][array length=n_parameters][element-type GType] |
void jsc_class_add_method_variadic (JSCClass *jsc_class
,const char *name
,GCallback callback
,gpointer user_data
,GDestroyNotify destroy_notify
,GType return_type
);
Add method with name
to jsc_class
. When the method is called by JavaScript or jsc_value_object_invoke_method()
,
callback
is called receiving the class instance as first parameter, followed by a GPtrArray of JSCValues
with the method arguments and then user_data
as last parameter. When the method is cleared in the JSCClass context,
destroy_notify
is called with user_data
as parameter.
Note that the value returned by callback
must be transfer full. In case of non-refcounted boxed types, you should 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 jsc_value_new_object()
that receives the copy as the instance parameter.
jsc_class |
a JSCClass |
|
name |
the method name |
|
callback |
a GCallback to be called to invoke method |
[scope async] |
user_data |
user data to pass to |
[closure] |
destroy_notify |
destroy notifier for |
[nullable] |
return_type |
the GType of the method return value, or |
void jsc_class_add_property (JSCClass *jsc_class
,const char *name
,GType property_type
,GCallback getter
,GCallback setter
,gpointer user_data
,GDestroyNotify destroy_notify
);
Add a property with name
to jsc_class
. When the property value needs to be getted, getter
is called
receiving the the class instance as first parameter and user_data
as last parameter. When the property
value needs to be set, setter
is called receiving the the class instance as first parameter, followed
by the value to be set and then user_data
as the last parameter. When the property is cleared in the
JSCClass context, destroy_notify
is called with user_data
as parameter.
Note that the value returned by getter
must be transfer full. In case of non-refcounted boxed types, you should 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 jsc_value_new_object()
that receives the copy as the instance parameter.
jsc_class |
a JSCClass |
|
name |
the property name |
|
property_type |
the GType of the property value |
|
getter |
a GCallback to be called to get the property value. |
[scope async][nullable] |
setter |
a GCallback 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] |
typedef struct { JSCClassGetPropertyFunction get_property; JSCClassSetPropertyFunction set_property; JSCClassHasPropertyFunction has_property; JSCClassDeletePropertyFunction delete_property; JSCClassEnumeratePropertiesFunction enumerate_properties; } JSCClassVTable;
Virtual table for a JSCClass. This can be optionally used when registering a JSCClass in a JSCContext
to provide a custom implementation for the class. All virtual functions are optional and can be set to
NULL
to fallback to the default implementation.
JSCClassGetPropertyFunction |
a JSCClassGetPropertyFunction for getting a property. |
|
JSCClassSetPropertyFunction |
a JSCClassSetPropertyFunction for setting a property. |
|
JSCClassHasPropertyFunction |
a JSCClassHasPropertyFunction for querying a property. |
|
JSCClassDeletePropertyFunction |
a JSCClassDeletePropertyFunction for deleting a property. |
|
JSCClassEnumeratePropertiesFunction |
a JSCClassEnumeratePropertiesFunction for enumerating properties. |
“context”
property“context” JSCContext *
The JSCContext in which the class was registered.
Owner: JSCClass
Flags: Write / Construct Only
“name”
property “name” char *
The name of the class.
Owner: JSCClass
Flags: Read / Write / Construct Only
Default value: NULL
“parent”
property“parent” JSCClass *
The parent class or NULL
in case of final classes.
Owner: JSCClass
Flags: Read / Write / Construct Only