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

Method init

gi/function.cpp:1289–1355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1287// clang-format on
1288
1289bool Function::init(JSContext* cx, GType gtype /* = G_TYPE_NONE */) {
1290 if (auto func_info = m_info.as<GI::InfoTag::FUNCTION>()) {
1291 GErrorResult<> result = func_info->prep_invoker(&m_invoker);
1292 if (result.isErr())
1293 return gjs_throw_gerror(cx, result.unwrapErr());
1294 } else if (auto vfunc_info = m_info.as<GI::InfoTag::VFUNC>()) {
1295 Gjs::GErrorResult<void*> result = vfunc_info->address(gtype);
1296 if (!result.isOk()) {
1297 if (result.inspectErr()->code != GI_INVOKE_ERROR_SYMBOL_NOT_FOUND)
1298 return gjs_throw_gerror(cx, result.unwrapErr());
1299
1300 gjs_throw(cx, "Virtual function not implemented: %s",
1301 result.inspectErr()->message);
1302 return false;
1303 }
1304
1305 GErrorResult<> result2 =
1306 m_info.init_function_invoker(result.unwrap(), &m_invoker);
1307 if (result2.isErr())
1308 return gjs_throw_gerror(cx, result2.unwrapErr());
1309 }
1310
1311 uint8_t n_args = m_info.n_args();
1312
1313 if (!m_arguments.initialize(cx, m_info))
1314 return false;
1315
1316 m_arguments.build_instance(m_info);
1317
1318 bool inc_counter;
1319 m_arguments.build_return(m_info, &inc_counter);
1320
1321 if (inc_counter)
1322 m_js_out_argc++;
1323
1324 for (uint8_t i = 0; i < n_args; i++) {
1325 Argument* gjs_arg = m_arguments.argument(i);
1326 GI::StackArgInfo arg_info;
1327
1328 if (gjs_arg && (gjs_arg->skip_in() || gjs_arg->skip_out())) {
1329 continue;
1330 }
1331
1332 m_info.load_arg(i, &arg_info);
1333 GIDirection direction = arg_info.direction();
1334
1335 m_arguments.build_arg(i, direction, arg_info, m_info, &inc_counter);
1336
1337 if (inc_counter) {
1338 switch (direction) {
1339 case GI_DIRECTION_INOUT:
1340 m_js_out_argc++;
1341 [[fallthrough]];
1342 case GI_DIRECTION_IN:
1343 m_js_in_argc++;
1344 break;
1345 case GI_DIRECTION_OUT:
1346 m_js_out_argc++;

Calls 15

gjs_throw_gerrorFunction · 0.85
gjs_throwFunction · 0.85
prep_invokerMethod · 0.80
unwrapErrMethod · 0.80
addressMethod · 0.80
isOkMethod · 0.80
inspectErrMethod · 0.80
init_function_invokerMethod · 0.80
unwrapMethod · 0.80
n_argsMethod · 0.80
build_instanceMethod · 0.80
build_returnMethod · 0.80