Class#

class Class(**properties: Any)#

Superclasses: Object

A JSSClass represents a custom JavaScript class registered by the user in a Context. 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 Callback<!– –>s to implement them.

Methods#

class Class
add_constructor(name: str | None, callback: Callable[[], None], user_data: Any, return_type: GType, parameter_types: list[GType] | None = None) Value#

Add a constructor to jsc_class. If name is None, the class name will be used. When <function>new</function> is used with the constructor or 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 Class 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 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 DestroyNotify passed to register_class() is responsible for disposing of it.

Parameters:
  • name – the constructor name or None

  • callback – a Callback to be called to create an instance of jsc_class

  • user_data – user data to pass to callback

  • return_type – the Type of the constructor return value

  • parameter_types

add_constructor_variadic(name: str | None, callback: Callable[[], None], user_data: Any, return_type: GType) Value#

Add a constructor to jsc_class. If name is None, the class name will be used. When <function>new</function> is used with the constructor or constructor_call() is called, callback is invoked receiving a GPtrArray of Value<!– –>s as arguments and user_data as the last parameter. When the constructor object is cleared in the Class 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 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 DestroyNotify passed to register_class() is responsible for disposing of it.

Parameters:
  • name – the constructor name or None

  • callback – a Callback to be called to create an instance of jsc_class

  • user_data – user data to pass to callback

  • return_type – the Type of the constructor return value

add_method(name: str, callback: Callable[[], None], user_data: Any, return_type: GType, parameter_types: list[GType] | None = None) None#

Add method with name to jsc_class. When the method is called by JavaScript or 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 Class 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 Type to ensure that the instance owned by Class is used. If you really want to return a new copy of the boxed type, use JSC_TYPE_VALUE and return a Value created with new_object() that receives the copy as the instance parameter.

Parameters:
  • name – the method name

  • callback – a Callback to be called to invoke method name of jsc_class

  • user_data – user data to pass to callback

  • return_type – the Type of the method return value, or %G_TYPE_NONE if the method is void.

  • parameter_types

add_method_variadic(name: str, callback: Callable[[], None], user_data: Any, return_type: GType) None#

Add method with name to jsc_class. When the method is called by JavaScript or object_invoke_method(), callback is called receiving the class instance as first parameter, followed by a GPtrArray of Value<!– –>s with the method arguments and then user_data as last parameter. When the method is cleared in the Class 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 Type to ensure that the instance owned by Class is used. If you really want to return a new copy of the boxed type, use JSC_TYPE_VALUE and return a Value created with new_object() that receives the copy as the instance parameter.

Parameters:
  • name – the method name

  • callback – a Callback to be called to invoke method name of jsc_class

  • user_data – user data to pass to callback

  • return_type – the Type of the method return value, or %G_TYPE_NONE if the method is void.

add_property(name: str, property_type: GType, getter: Callable[[], None] | None = None, setter: Callable[[], None] | None = None, user_data: Any = None) None#

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 Class 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 Type to ensure that the instance owned by Class is used. If you really want to return a new copy of the boxed type, use JSC_TYPE_VALUE and return a Value created with new_object() that receives the copy as the instance parameter.

Parameters:
  • name – the property name

  • property_type – the Type of the property value

  • getter – a Callback to be called to get the property value

  • setter – a Callback to be called to set the property value

  • user_data – user data to pass to getter and setter

get_name() str#

Get the class name of jsc_class

get_parent() Class#

Get the parent class of jsc_class

Properties#

class Class
props.context: Context#

The type of the None singleton.

props.name: str#

The type of the None singleton.

props.parent: Class#

The type of the None singleton.