Class Class

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class Class extends GObject
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.
  • Constructor Details

    • Class

      public Class(MemorySegment address)
      Create a Class instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Class

      public Class()
      Create a new Class.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Class class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Class asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • addConstructorVariadic

      public Value addConstructorVariadic(@Nullable String name, @Nullable Callback callback, Type returnType)

      Add a constructor to jscClass. 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 userData as the last parameter. When the constructor object is cleared in the JSCClass context, destroyNotify is called with userData 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 jscClass, and the GDestroyNotify passed to jsc_context_register_class() is responsible for disposing of it.

      Parameters:
      name - the constructor name or null
      callback - a GCallback to be called to create an instance of this Class
      returnType - the GType of the constructor return value
      Returns:
      a JSCValue representing the class constructor.
    • addConstructor

      public Value addConstructor(@Nullable String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes)

      Add a constructor to jscClass. 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 userData as the last parameter. When the constructor object is cleared in the JSCClass context, destroyNotify is called with userData 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 jscClass, and the GDestroyNotify passed to jsc_context_register_class() is responsible for disposing of it.

      Parameters:
      name - the constructor name or null
      callback - a GCallback to be called to create an instance of this Class
      returnType - the GType of the constructor return value
      parameterTypes - a list of GTypes, one for each parameter, or null
      Returns:
      a JSCValue representing the class constructor.
    • addMethodVariadic

      public void addMethodVariadic(String name, @Nullable Callback callback, Type returnType)

      Add method with name to jscClass. 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 userData as last parameter. When the method is cleared in the JSCClass context, destroyNotify is called with userData 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.

      Parameters:
      name - the method name
      callback - a GCallback to be called to invoke method name of this Class
      returnType - the GType of the method return value, or G_TYPE_NONE if the method is void.
    • addMethod

      public void addMethod(String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes)

      Add method with name to jscClass. 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 userData as last parameter. When the method is cleared in the JSCClass context, destroyNotify is called with userData 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.

      Parameters:
      name - the method name
      callback - a GCallback to be called to invoke method name of this Class
      returnType - the GType of the method return value, or G_TYPE_NONE if the method is void.
      parameterTypes - a list of GTypes, one for each parameter, or null
    • addProperty

      public void addProperty(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter)

      Add a property with name to jscClass. When the property value is read, getter is called receiving the the class instance as first parameter and userData 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 userData as the last parameter. When the property is cleared in the JSCClass context, destroyNotify is called with userData 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.

      Parameters:
      name - the property name
      propertyType - the GType of the property value
      getter - a GCallback to be called to get the property value
      setter - a GCallback to be called to set the property value
    • getName

      public String getName()
      Get the class name of this Class
      Returns:
      the name of this Class
    • getParent

      public Class getParent()
      Get the parent class of this Class
      Returns:
      the parent class of this Class
    • builder

      public static Class.Builder<? extends Class.Builder> builder()
      A Class.Builder object constructs a Class with the specified properties. Use the various set...() methods to set properties, and finish construction with Class.Builder.build().
      Returns:
      the builder object