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

Function array_to_basic_c_array

gi/arg.cpp:600–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

598}
599
600GJS_JSAPI_RETURN_CONVENTION
601static bool array_to_basic_c_array(JSContext* cx, JS::HandleValue v_array,
602 size_t length, GITypeTag element_tag,
603 void** array_out) {
604 // Always one extra element, to cater for null terminated arrays
605 Gjs::AutoPointer<void*> array{array_allocate<void*>(length + 1)};
606
607 JS::RootedObject array_obj{cx, &v_array.toObject()};
608 JS::RootedValue elem{cx};
609 for (size_t ix = 0; ix < length; ix++) {
610 GIArgument arg;
611 gjs_arg_unset(&arg);
612
613 elem.setUndefined();
614 if (!JS_GetElement(cx, array_obj, ix, &elem)) {
615 gjs_throw(cx, "Missing array element %zu", ix);
616 return false;
617 }
618
619 if (!gjs_value_to_basic_gi_argument(cx, elem, element_tag, &arg,
620 nullptr, GJS_ARGUMENT_ARRAY_ELEMENT,
621 GjsArgumentFlags::NONE)) {
622 gjs_throw(cx, "Invalid element in array");
623 return false;
624 }
625
626 array[ix] = gjs_arg_get<void*>(&arg);
627 }
628
629 *array_out = array.release();
630 return true;
631}
632
633GJS_JSAPI_RETURN_CONVENTION
634static bool gjs_array_to_ptrarray(JSContext* cx, JS::Value array_value,

Callers 1

gjs_array_to_basic_arrayFunction · 0.85

Calls 4

gjs_arg_unsetFunction · 0.85
gjs_throwFunction · 0.85
releaseMethod · 0.45

Tested by

no test coverage detected