| 212 | } |
| 213 | |
| 214 | GJS_JSAPI_RETURN_CONVENTION |
| 215 | static 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 | |
| 254 | GJS_JSAPI_RETURN_CONVENTION |
| 255 | static bool gjs_register_interface(JSContext* cx, unsigned argc, |
no test coverage detected