| 2750 | } |
| 2751 | |
| 2752 | bool gjs_array_from_basic_zero_terminated_array( |
| 2753 | JSContext* cx, JS::MutableHandleValue value_out, GITypeTag element_tag, |
| 2754 | void* c_array) { |
| 2755 | g_assert(GI_TYPE_TAG_IS_BASIC(element_tag) && |
| 2756 | "Use gjs_array_from_zero_terminated_c_array for non-basic types"); |
| 2757 | |
| 2758 | if (!c_array) { |
| 2759 | // OK, but no conversion to do |
| 2760 | value_out.setNull(); |
| 2761 | return true; |
| 2762 | } |
| 2763 | |
| 2764 | // Special case array(uint8_t) |
| 2765 | if (element_tag == GI_TYPE_TAG_UINT8) { |
| 2766 | size_t length = strlen(static_cast<char*>(c_array)); |
| 2767 | JSObject* byte_array = |
| 2768 | gjs_byte_array_from_data_copy(cx, length, c_array); |
| 2769 | if (!byte_array) |
| 2770 | return false; |
| 2771 | |
| 2772 | value_out.setObject(*byte_array); |
| 2773 | return true; |
| 2774 | } |
| 2775 | |
| 2776 | // Special case array(gunichar) to JS string |
| 2777 | if (element_tag == GI_TYPE_TAG_UNICHAR) { |
| 2778 | return gjs_string_from_ucs4(cx, static_cast<gunichar*>(c_array), -1, |
| 2779 | value_out); |
| 2780 | } |
| 2781 | |
| 2782 | JS::RootedValueVector elems{cx}; |
| 2783 | |
| 2784 | GIArgument arg; |
| 2785 | switch (element_tag) { |
| 2786 | case GI_TYPE_TAG_INT8: |
| 2787 | if (!fill_vector_from_basic_zero_terminated_c_array<int8_t>( |
| 2788 | cx, &elems, element_tag, &arg, c_array)) |
| 2789 | return false; |
| 2790 | break; |
| 2791 | case GI_TYPE_TAG_UINT16: |
| 2792 | if (!fill_vector_from_basic_zero_terminated_c_array<uint16_t>( |
| 2793 | cx, &elems, element_tag, &arg, c_array)) |
| 2794 | return false; |
| 2795 | break; |
| 2796 | case GI_TYPE_TAG_INT16: |
| 2797 | if (!fill_vector_from_basic_zero_terminated_c_array<int16_t>( |
| 2798 | cx, &elems, element_tag, &arg, c_array)) |
| 2799 | return false; |
| 2800 | break; |
| 2801 | case GI_TYPE_TAG_UINT32: |
| 2802 | if (!fill_vector_from_basic_zero_terminated_c_array<uint32_t>( |
| 2803 | cx, &elems, element_tag, &arg, c_array)) |
| 2804 | return false; |
| 2805 | break; |
| 2806 | case GI_TYPE_TAG_INT32: |
| 2807 | if (!fill_vector_from_basic_zero_terminated_c_array<int32_t>( |
| 2808 | cx, &elems, element_tag, &arg, c_array)) |
| 2809 | return false; |
no test coverage detected