| 1382 | } // namespace Gjs |
| 1383 | |
| 1384 | GJS_JSAPI_RETURN_CONVENTION |
| 1385 | JSObject* gjs_define_function(JSContext* cx, JS::HandleObject in_object, |
| 1386 | GType gtype, const GI::CallableInfo& info) { |
| 1387 | using std::string_literals::operator""s; |
| 1388 | std::string name; |
| 1389 | |
| 1390 | JS::RootedObject function{cx, Gjs::Function::create(cx, gtype, info)}; |
| 1391 | if (!function) |
| 1392 | return nullptr; |
| 1393 | |
| 1394 | if (info.is_function()) { |
| 1395 | name = info.name(); |
| 1396 | } else if (info.is_vfunc()) { |
| 1397 | name = "vfunc_"s + info.name(); |
| 1398 | } else { |
| 1399 | g_assert_not_reached(); |
| 1400 | } |
| 1401 | |
| 1402 | if (!JS_DefineProperty(cx, in_object, name.c_str(), function, |
| 1403 | GJS_MODULE_PROP_FLAGS)) { |
| 1404 | gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to define function"); |
| 1405 | function = nullptr; |
| 1406 | } |
| 1407 | |
| 1408 | return function; |
| 1409 | } |
| 1410 | |
| 1411 | bool gjs_invoke_constructor_from_c(JSContext* cx, const GI::FunctionInfo& info, |
| 1412 | JS::HandleObject obj, |
no test coverage detected