MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_register_interface_impl

Function gjs_register_interface_impl

gi/private.cpp:214–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214GJS_JSAPI_RETURN_CONVENTION
215static bool gjs_register_interface_impl(JSContext* cx, const char* name,
216 JS::HandleObject interfaces,
217 JS::HandleObject properties,
218 GType* gtype) {
219 uint32_t n_interfaces, n_properties;
220 if (!validate_interfaces_and_properties_args(cx, interfaces, properties,
221 &n_interfaces, &n_properties))
222 return false;
223
224 Gjs::AutoPointer<GType> iface_types{g_new(GType, n_interfaces)};
225
226 // We do interface addition in two passes so that any failure is caught
227 // early, before registering the GType (which we can't undo)
228 if (!get_interface_gtypes(cx, interfaces, n_interfaces, iface_types))
229 return false;
230
231 if (g_type_from_name(name) != G_TYPE_INVALID) {
232 gjs_throw(cx, "Type name %s is already registered", name);
233 return false;
234 }
235
236 GTypeInfo type_info = gjs_gobject_interface_info;
237 GType interface_type = g_type_register_static(G_TYPE_INTERFACE, name,
238 &type_info, GTypeFlags(0));
239
240 g_type_set_qdata(interface_type, ObjectBase::custom_type_quark(),
241 GINT_TO_POINTER(1));
242
243 if (!save_properties_for_class_init(cx, properties, n_properties,
244 interface_type))
245 return false;
246
247 for (uint32_t ix = 0; ix < n_interfaces; ix++)
248 g_type_interface_add_prerequisite(interface_type, iface_types[ix]);
249
250 *gtype = interface_type;
251 return true;
252}
253
254GJS_JSAPI_RETURN_CONVENTION
255static bool gjs_register_interface(JSContext* cx, unsigned argc,

Callers 2

gjs_register_interfaceFunction · 0.85

Calls 4

get_interface_gtypesFunction · 0.85
gjs_throwFunction · 0.85

Tested by

no test coverage detected