- {
- JSValue len_val = JS_GetPropertyStr(ctx, arr, "length");
- if (JS_IsException(len_val))
- goto fail;
- if (JS_ToInt64(ctx, &len, len_val) < 0) {
- JS_FreeValue(ctx, len_val);
- goto fail;
- }
- JS_FreeValue(ctx, len_val);
- }
-
- {
- size_t alloc_count = (len > 0) ? (size_t)len : 1;
- items = js_malloc(ctx, sizeof(*items) * alloc_count);
- }
- if (!items)
- goto fail;
-
- for (i = 0; i < len; i++) {
- JSValue val;
- const char *str;
- val = JS_GetPropertyUint32(ctx, arr, (uint32_t)i);
- if (JS_IsException(val)) {
- JS_FreeValue(ctx, val);
- goto fail;
- }
- str = JS_ToCString(ctx, val);
- JS_FreeValue(ctx, val);
- if (!str)
- goto fail;
- items[i] = str;
- }
-
- list.items = items;
- list.count = (int)len;
-