* ObjectPrototype::define_class: * @in_object: Object where the constructor is stored, typically a repo object. * @info: Introspection info for the GObject class. * @gtype: #GType for the GObject class. * @constructor: Return location for the constructor object. * @prototype: Return location for the prototype object. * * Define a GObject class constructor and prototype, including all the ne
| 3476 | * and prototype objects as out parameters, for convenience elsewhere. |
| 3477 | */ |
| 3478 | bool ObjectPrototype::define_class(JSContext* cx, JS::HandleObject in_object, |
| 3479 | const Maybe<const GI::ObjectInfo>& info, |
| 3480 | GType gtype, GType* interface_gtypes, |
| 3481 | uint32_t n_interface_gtypes, |
| 3482 | JS::MutableHandleObject constructor, |
| 3483 | JS::MutableHandleObject prototype) { |
| 3484 | ObjectPrototype* priv = ObjectPrototype::create_class( |
| 3485 | cx, in_object, info, gtype, constructor, prototype); |
| 3486 | if (!priv) |
| 3487 | return false; |
| 3488 | |
| 3489 | priv->set_interfaces(interface_gtypes, n_interface_gtypes); |
| 3490 | |
| 3491 | JS::RootedObject parent_constructor{cx}; |
| 3492 | if (!priv->get_parent_constructor(cx, &parent_constructor)) |
| 3493 | return false; |
| 3494 | // If this is a fundamental constructor (e.g. GObject.Object) the parent |
| 3495 | // constructor may be null. |
| 3496 | if (parent_constructor) { |
| 3497 | if (!JS_SetPrototype(cx, constructor, parent_constructor)) |
| 3498 | return false; |
| 3499 | } |
| 3500 | |
| 3501 | // hook_up_vfunc and the signal handler matcher functions can't be included |
| 3502 | // in gjs_object_instance_proto_funcs because they are custom symbols. |
| 3503 | const GjsAtoms& atoms = GjsContextPrivate::atoms(cx); |
| 3504 | return JS_DefineFunctionById(cx, prototype, atoms.hook_up_vfunc(), |
| 3505 | &ObjectBase::hook_up_vfunc, 3, |
| 3506 | GJS_MODULE_PROP_FLAGS) && |
| 3507 | JS_DefineFunctionById(cx, prototype, atoms.signal_find(), |
| 3508 | &ObjectBase::signal_find, 1, |
| 3509 | GJS_MODULE_PROP_FLAGS) && |
| 3510 | JS_DefineFunctionById( |
| 3511 | cx, prototype, atoms.signals_block(), |
| 3512 | &ObjectBase::signals_action<&g_signal_handlers_block_matched>, 1, |
| 3513 | GJS_MODULE_PROP_FLAGS) && |
| 3514 | JS_DefineFunctionById( |
| 3515 | cx, prototype, atoms.signals_unblock(), |
| 3516 | &ObjectBase::signals_action<&g_signal_handlers_unblock_matched>, |
| 3517 | 1, GJS_MODULE_PROP_FLAGS) && |
| 3518 | JS_DefineFunctionById(cx, prototype, atoms.signals_disconnect(), |
| 3519 | &ObjectBase::signals_action< |
| 3520 | &g_signal_handlers_disconnect_matched>, |
| 3521 | 1, GJS_MODULE_PROP_FLAGS); |
| 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * ObjectInstance::init_custom_class_from_gobject: |
nothing calls this directly
no test coverage detected