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

Function gjs_array_from_g_value_array

gi/arg.cpp:2640–2671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2638}
2639
2640GJS_JSAPI_RETURN_CONVENTION
2641bool gjs_array_from_g_value_array(JSContext* cx, JS::MutableHandleValue value_p,
2642 const GI::TypeInfo& element_type,
2643 GITransfer transfer, const GValue* gvalue) {
2644 void* data = nullptr;
2645 size_t length = 0;
2646 GIArrayType array_type;
2647 GType value_gtype = G_VALUE_TYPE(gvalue);
2648
2649 // GByteArray is just a typedef for GArray internally
2650 if (g_type_is_a(value_gtype, G_TYPE_BYTE_ARRAY) ||
2651 g_type_is_a(value_gtype, G_TYPE_ARRAY)) {
2652 array_type = g_type_is_a(value_gtype, G_TYPE_BYTE_ARRAY)
2653 ? GI_ARRAY_TYPE_BYTE_ARRAY
2654 : GI_ARRAY_TYPE_ARRAY;
2655 auto* array = Gjs::gvalue_get<GArray*>(gvalue);
2656 data = array->data;
2657 length = array->len;
2658 } else if (g_type_is_a(value_gtype, G_TYPE_PTR_ARRAY)) {
2659 array_type = GI_ARRAY_TYPE_PTR_ARRAY;
2660 auto* ptr_array = Gjs::gvalue_get<GPtrArray*>(gvalue);
2661 data = ptr_array->pdata;
2662 length = ptr_array->len;
2663 } else {
2664 g_assert_not_reached();
2665 gjs_throw(cx, "%s is not an array type", g_type_name(value_gtype));
2666 return false;
2667 }
2668
2669 return gjs_array_from_carray_internal(cx, value_p, array_type, element_type,
2670 transfer, length, data);
2671}
2672
2673template <typename TAG>
2674GJS_JSAPI_RETURN_CONVENTION

Callers 1

Calls 2

gjs_throwFunction · 0.85

Tested by

no test coverage detected