1.1 <JSCClass>

Class: <JSCClass>

It derives from <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 GCallback<!– –>s to implement them.

Properties

Property: class:context self

The <JSCContext> in which the class was registered.

Its value is a <JSCContext>, or #f.

It can only be set when the object is made, with #:context. It cannot be read.

Property: class:name self

The name of the class.

Its value is a string, or #f.

It can only be set when the object is made, with #:name.

Property: class:parent self

The parent class or #f in case of final classes.

Its value is a <JSCClass>, or #f.

It can only be set when the object is made, with #:parent.

Procedures

Method: class:add-constructor self name callback return-type [parameter-types] ⇒ %return
Method: add-constructor self name callback return-type [parameter-types] ⇒ %return

Add a constructor to self. If name is #f, the class name will be used. When new() is used with the constructor or 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 context:set-value to make the constructor available in the global object.

Note that the value returned by callback is adopted by self, and the GDestroyNotify passed to jsc_context_register_class() is responsible for disposing of it.

self

Passed: a <JSCClass>.

a <JSCClass>

name

Passed: a string, or #f.

the constructor name or #f

callback

Passed: a procedure.

a GCallback to be called to create an instance of self

See GCallback for how it is called.

return-type

Passed: a class, or a GType number.

the GType of the constructor return value

parameter-types

Passed, or left out: a list or vector, each a class, or a GType number, or #f.

%return

Returned: a <JSCValue>.

a <JSCValue> representing the class constructor.

n-parameters

Not passed: guile-gi gives the length of parameter-types.

user-data

Not passed: guile-gi supplies it.

user data to pass to callback

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

n-params

the number of parameter types to follow or 0 if constructor doesn’t receive parameters.

...

a list of GType<!– –>s, one for each parameter.

Method: class:add-constructor-variadic self name callback return-type ⇒ %return
Method: add-constructor-variadic self name callback return-type ⇒ %return

Add a constructor to self. If name is #f, the class name will be used. When new() is used with the constructor or value:constructor-call is called, callback is invoked receiving a <GPtrArray> of <JSCValue><!– –>s 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 context:set-value to make the constructor available in the global object.

Note that the value returned by callback is adopted by self, and the GDestroyNotify passed to jsc_context_register_class() is responsible for disposing of it.

self

Passed: a <JSCClass>.

a <JSCClass>

name

Passed: a string, or #f.

the constructor name or #f

callback

Passed: a procedure.

a GCallback to be called to create an instance of self

See GCallback for how it is called.

return-type

Passed: a class, or a GType number.

the GType of the constructor return value

%return

Returned: a <JSCValue>.

a <JSCValue> representing the class constructor.

user-data

Not passed: guile-gi supplies it.

user data to pass to callback

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: class:add-method self name callback return-type [parameter-types]
Method: add-method self name callback return-type [parameter-types]

Add method with name to self. When the method is called by JavaScript or 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 value:new-object that receives the copy as the instance parameter.

self

Passed: a <JSCClass>.

a <JSCClass>

name

Passed: a string.

the method name

callback

Passed: a procedure.

a GCallback to be called to invoke method name of self

See GCallback for how it is called.

return-type

Passed: a class, or a GType number.

the GType of the method return value, or G_TYPE_NONE if the method is void.

parameter-types

Passed, or left out: a list or vector, each a class, or a GType number, or #f.

n-parameters

Not passed: guile-gi gives the length of parameter-types.

user-data

Not passed: guile-gi supplies it.

user data to pass to callback

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

n-params

the number of parameter types to follow or 0 if the method doesn’t receive parameters.

...

a list of GType<!– –>s, one for each parameter.

Method: class:add-method-variadic self name callback return-type
Method: add-method-variadic self name callback return-type

Add method with name to self. When the method is called by JavaScript or value:object-invoke-method, callback is called receiving the class instance as first parameter, followed by a <GPtrArray> of <JSCValue><!– –>s 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 value:new-object that receives the copy as the instance parameter.

self

Passed: a <JSCClass>.

a <JSCClass>

name

Passed: a string.

the method name

callback

Passed: a procedure.

a GCallback to be called to invoke method name of self

See GCallback for how it is called.

return-type

Passed: a class, or a GType number.

the GType of the method return value, or G_TYPE_NONE if the method is void.

user-data

Not passed: guile-gi supplies it.

user data to pass to callback

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: class:add-property self name property-type [getter] [setter]
Method: add-property self name property-type [getter] [setter]

Add a property with name to self. When the property value is read, 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 value:new-object that receives the copy as the instance parameter.

self

Passed: a <JSCClass>.

a <JSCClass>

name

Passed: a string.

the property name

property-type

Passed: a class, or a GType number.

the GType of the property value

getter

Passed, or left out: a procedure, or #f.

a GCallback to be called to get the property value

See GCallback for how it is called.

setter

Passed, or left out: a procedure, or #f.

a GCallback to be called to set the property value

See GCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to getter and setter

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: class:get-name self ⇒ %return
Method: get-name self ⇒ %return

Get the class name of self

self

Passed: a <JSCClass>.

a JSCClass

%return

Returned: a string.

the name of self

Method: class:get-parent self ⇒ %return
Method: get-parent self ⇒ %return

Get the parent class of self

self

Passed: a <JSCClass>.

a JSCClass

%return

Returned: a <JSCClass>.

the parent class of self