Skip to content

Copy BufferSource data in Body::extractBody per Fetch spec#6540

Merged
jasnell merged 3 commits into
mainfrom
erikcorry/body-spec-conformance
Apr 9, 2026
Merged

Copy BufferSource data in Body::extractBody per Fetch spec#6540
jasnell merged 3 commits into
mainfrom
erikcorry/body-spec-conformance

Conversation

@erikcorry

Copy link
Copy Markdown
Contributor

The Fetch spec requires that constructing a Body from a BufferSource creates an independent copy of the data. Previously we only copied resizable buffers and aliased the backing store for fixed-size ones. This change copies unconditionally for all buffer types, which simplifies the code and improves spec conformance.

The Fetch spec requires that constructing a Body from a BufferSource
creates an independent copy of the data. Previously we only copied
resizable buffers and aliased the backing store for fixed-size ones.
This change copies unconditionally for all buffer types, which
simplifies the code and improves spec conformance.
@erikcorry erikcorry self-assigned this Apr 9, 2026
@erikcorry erikcorry requested review from a team as code owners April 9, 2026 13:53
@erikcorry erikcorry requested a review from jasnell April 9, 2026 13:54
@ask-bonk

ask-bonk Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

The analysis is complete. The change is clean and correct:

  1. Spec conformance: The Fetch spec requires copying BufferSource data. The old code explicitly acknowledged its non-conformance.
  2. No compat flag needed: Moving toward spec conformance by fixing an acknowledged non-conformity. Only observable by code that deliberately mutated a buffer after passing it to a Request/Response constructor.
  3. Memory safety: The new code is actually safer -- no V8 backing store aliasing for the BufferSource path. The kj::heapArray produces a plain C++ heap allocation with no V8 lifetime dependencies.
  4. Updated comment is accurate: The Blob path still produces V8-backed memory, so the comment about V8 heap provenance remains necessary and correct.
  5. No test for the new behavior: This is the only minor concern -- there's no test verifying that the body is indeed an independent snapshot.

The only actionable item is the missing test. However, the PR description is clear about its intent, and the code change itself is straightforward and correct. The lack of a test is a minor observation, not a blocking issue. Since everything else looks clean and well-reasoned, this is LGTM.

LGTM

github run

Comment thread src/workerd/api/http.c++ Outdated
The Fetch spec requires that constructing a Body from a BufferSource
creates an independent copy of the data. Previously we only copied
resizable buffers and aliased the backing store for fixed-size ones.
This change copies unconditionally for all buffer types, which
simplifies the code and improves spec conformance.

Also removes the WPT expected failures for body/cloned-any.js since
the 'TypedArray is cloned' and 'ArrayBuffer is cloned' tests now pass.
@erikcorry erikcorry force-pushed the erikcorry/body-spec-conformance branch from a11055d to 765267c Compare April 9, 2026 14:34
@jasnell jasnell enabled auto-merge April 9, 2026 14:55
@jasnell jasnell merged commit d296e3e into main Apr 9, 2026
24 checks passed
@jasnell jasnell deleted the erikcorry/body-spec-conformance branch April 9, 2026 15:15
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.

2 participants