Skip to content

feat(fetch): Support ArrayBuffer and TypedArray request body in Fetch RequestInit#5043

Closed
RajdeepKushwaha5 wants to merge 3 commits intoboa-dev:mainfrom
RajdeepKushwaha5:fix/issue-4957-fetch-body-types
Closed

feat(fetch): Support ArrayBuffer and TypedArray request body in Fetch RequestInit#5043
RajdeepKushwaha5 wants to merge 3 commits intoboa-dev:mainfrom
RajdeepKushwaha5:fix/issue-4957-fetch-body-types

Conversation

@RajdeepKushwaha5
Copy link

Description

This PR implements support for injecting standard JavaScript Array buffers (ArrayBuffer, Uint8Array, DataView, and general TypedArray variants) into the body option of the RequestInit dictionary conforming with the Fetch API, addressing Issue #4957.

Previously, attempting to generate a Fetch Request from bytes threw a TypeError("body is not a supported type").

Changes Made:

  • Modified the signature of into_request_builder, create_from_js, and request::constructor internally to pass context: &mut Context through the calling tree.
  • Checked the body field locally against engine native JsArrayBuffer, JsTypedArray, and JsDataView builtin wrappers.
  • Handled properly extracting byte arrays factoring in both the start offset and the data length.
  • Added a fetch/tests/request.rs automated execution block to securely validate Uint8Array alongside DataView bindings during cargo test.

Related Issue:
Fixes #4957

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds binary request body support to Boa’s Fetch RequestInit.body, enabling ArrayBuffer, TypedArray, and DataView inputs (per #4957) by propagating &mut Context through the request-construction path.

Changes:

  • Extend RequestInit::into_request_builder to accept and extract bytes from ArrayBuffer/TypedArray/DataView.
  • Thread &mut Context through JsRequest::{constructor,create_from_js} and fetch_inner to support the new conversions.
  • Add a fetch Request test covering Uint8Array and DataView bodies.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

File Description
core/runtime/src/fetch/request.rs Implements byte extraction for ArrayBuffer/TypedArray/DataView bodies; updates request construction signatures to accept Context.
core/runtime/src/fetch/mod.rs Updates fetch option application to pass Context into into_request_builder.
core/runtime/src/fetch/tests/request.rs Updates create_from_js callsite and adds a test for Uint8Array/DataView request bodies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -105,11 +107,59 @@ impl RequestInit {

if let Some(body) = &self.body {
// TODO: add more support types.
Comment on lines +167 to +176
const buf = new Uint8Array([104, 101, 108, 108, 111]); // "hello"
globalThis.req1 = new Request("http://unit.test", {
method: "POST",
body: buf,
});
const dv = new DataView(buf.buffer);
globalThis.req2 = new Request("http://unit.test", {
method: "POST",
body: dv,
});
Comment on lines +124 to +136
} else if let Ok(ta) = JsTypedArray::from_object(object.clone()) {
let buffer = ta.buffer(context)?;
let array_buffer = JsArrayBuffer::from_object(
buffer
.as_object()
.expect("buffer must be an object")
.clone(),
)?;
if let Some(bytes) = array_buffer.to_vec() {
let offset = ta.byte_offset(context)?;
let length = ta.byte_length(context)?;
request_body = bytes[offset..offset + length].to_vec();
} else {
Comment on lines +125 to +131
let buffer = ta.buffer(context)?;
let array_buffer = JsArrayBuffer::from_object(
buffer
.as_object()
.expect("buffer must be an object")
.clone(),
)?;
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,935 49,935 0
Ignored 2,207 2,207 0
Failed 821 821 0
Panics 0 0 0
Conformance 94.28% 94.28% 0.00%

Tested main commit: f5ae9f7385337d34f68fa9969054efe8c0161305
Tested PR commit: a6b5eb9805da203e9fe9ad56b71c72426249db23
Compare commits: f5ae9f7...a6b5eb9

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 59.61538% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.18%. Comparing base (6ddc2b4) to head (a6b5eb9).
⚠️ Report is 845 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/fetch/request.rs 58.82% 21 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5043       +/-   ##
===========================================
+ Coverage   47.24%   59.18%   +11.93%     
===========================================
  Files         476      563       +87     
  Lines       46892    62577    +15685     
===========================================
+ Hits        22154    37036    +14882     
- Misses      24738    25541      +803     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043 jedel1043 closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Uint8Array / ArrayBuffer request body in Fetch RequestInit

3 participants