MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

upload chunks for fetch

+18 -2
+18 -2
src/modules/fetch.c
··· 259 259 return create_typed_array(js, TYPED_ARRAY_UINT8, ab, 0, len, "Uint8Array"); 260 260 } 261 261 262 + static bool fetch_get_upload_chunk(ant_value_t value, const uint8_t **out, size_t *len) { 263 + ant_value_t slot = js_get_slot(value, SLOT_BUFFER); 264 + TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(slot); 265 + 266 + if (!ta || ta->type != TYPED_ARRAY_UINT8) return false; 267 + if (!ta->buffer || ta->buffer->is_detached) { 268 + *out = NULL; 269 + *len = 0; 270 + return true; 271 + } 272 + 273 + *out = ta->buffer->data + ta->byte_offset; 274 + *len = ta->byte_length; 275 + return true; 276 + } 277 + 262 278 static void fetch_http_on_response(ant_http_request_t *http_req, const ant_http_response_t *resp, void *user_data) { 263 279 fetch_request_t *req = (fetch_request_t *)user_data; 264 280 ··· 463 479 return js_mkundef(); 464 480 } 465 481 466 - if (!buffer_source_get_bytes(js, value, &chunk, &chunk_len)) { 467 - ant_value_t reason = js_mkerr_typed(js, JS_ERR_TYPE, "fetch request body stream chunk must be a BufferSource"); 482 + if (!fetch_get_upload_chunk(value, &chunk, &chunk_len)) { 483 + ant_value_t reason = js_mkerr_typed(js, JS_ERR_TYPE, "fetch request body stream chunk must be a Uint8Array"); 468 484 ant_http_request_cancel(req->http_req); 469 485 fetch_reject(req, fetch_rejection_reason(js, reason)); 470 486 fetch_request_release(req);