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

Function array_from_basic_linked_list

gi/arg.cpp:3041–3073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3039
3040template <typename T>
3041GJS_JSAPI_RETURN_CONVENTION
3042static bool array_from_basic_linked_list(JSContext* cx,
3043 JS::MutableHandleValue value_out,
3044 GITypeTag element_tag, T* list) {
3045 static_assert(std::is_same_v<T, GList> || std::is_same_v<T, GSList>);
3046 g_assert(
3047 GI_TYPE_TAG_IS_BASIC(element_tag) &&
3048 "use gjs_array_from_g_list() for lists containing non-basic types");
3049
3050 GIArgument arg;
3051 JS::RootedValueVector elems{cx};
3052
3053 for (size_t i = 0; list; list = list->next, ++i) {
3054 // for basic types, type tag == storage type
3055 gi_type_tag_argument_from_hash_pointer(element_tag, list->data, &arg);
3056
3057 if (!elems.growBy(1)) {
3058 JS_ReportOutOfMemory(cx);
3059 return false;
3060 }
3061
3062 if (!gjs_value_from_basic_gi_argument(cx, elems[i], element_tag, &arg))
3063 return false;
3064 }
3065
3066 JS::RootedObject obj{cx, JS::NewArrayObject(cx, elems)};
3067 if (!obj)
3068 return false;
3069
3070 value_out.setObject(*obj);
3071
3072 return true;
3073}
3074
3075bool gjs_array_from_basic_glist_gi_argument(JSContext* cx,
3076 JS::MutableHandleValue value_out,

Calls 1

Tested by

no test coverage detected