| 558 | } |
| 559 | |
| 560 | GJS_JSAPI_RETURN_CONVENTION |
| 561 | static bool gjs_string_to_intarray(JSContext* cx, JS::HandleString str, |
| 562 | GITypeTag element_type, void** arr_p, |
| 563 | size_t* length) { |
| 564 | switch (element_type) { |
| 565 | case GI_TYPE_TAG_INT8: |
| 566 | case GI_TYPE_TAG_UINT8: { |
| 567 | JS::UniqueChars result; |
| 568 | if (!gjs_string_to_utf8_n(cx, str, &result, length)) |
| 569 | return false; |
| 570 | |
| 571 | *arr_p = Gjs::js_chars_to_glib(std::move(result)).release(); |
| 572 | return true; |
| 573 | } |
| 574 | |
| 575 | case GI_TYPE_TAG_INT16: |
| 576 | case GI_TYPE_TAG_UINT16: { |
| 577 | char16_t* result16; |
| 578 | if (!gjs_string_get_char16_data(cx, str, &result16, length)) |
| 579 | return false; |
| 580 | *arr_p = result16; |
| 581 | return true; |
| 582 | } |
| 583 | |
| 584 | case GI_TYPE_TAG_UNICHAR: { |
| 585 | gunichar* result_ucs4; |
| 586 | if (!gjs_string_to_ucs4(cx, str, &result_ucs4, length)) |
| 587 | return false; |
| 588 | *arr_p = result_ucs4; |
| 589 | return true; |
| 590 | } |
| 591 | |
| 592 | default: |
| 593 | // can't convert a string to this type |
| 594 | gjs_throw(cx, "Cannot convert string to array of '%s'", |
| 595 | gi_type_tag_to_string(element_type)); |
| 596 | return false; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | GJS_JSAPI_RETURN_CONVENTION |
| 601 | static bool array_to_basic_c_array(JSContext* cx, JS::HandleValue v_array, |
no test coverage detected