Skip to content

feat(fetch): implement bodyUsed and clone() for Request and Response (#4992)#5041

Closed
RajdeepKushwaha5 wants to merge 3 commits intoboa-dev:mainfrom
RajdeepKushwaha5:fix/issue-4992-clone-bodyused
Closed

feat(fetch): implement bodyUsed and clone() for Request and Response (#4992)#5041
RajdeepKushwaha5 wants to merge 3 commits intoboa-dev:mainfrom
RajdeepKushwaha5:fix/issue-4992-clone-bodyused

Conversation

@RajdeepKushwaha5
Copy link

Description

Summary

This pull request implements the .clone() method and the .bodyUsed property for both the Request and Response Web APIs in boa_runtime, addressing issue #4992. Previously, cloning a request or response would fail because it wasn't implemented, and body consuming methods weren't properly ensuring that a given buffer is only drained once per spec.

Changes Made

  • Added a body_used: Cell<bool> internal state wrapped in #[unsafe_ignore_trace] inside both JsRequest and JsResponse.
  • Configured a #[boa(getter)] for bodyUsed returning a boolean for Request and Response.
  • Implemented clone() via standard standard JS method binding (clone_js internally mapped to clone), appropriately deep cloning fields (like Headers) while sharing the internal Request/Response structure safely.
  • Added a pub fn deep_clone(&self) -> Self standard to JsHeaders inside headers.rs in order to ensure the newly cloned Request/Response has its own distinct map of headers.
  • Updated bytes(), text(), and json() within JsResponse to fail eagerly with a TypeError if bodyUsed is currently true. Otherwise, it trips the internal flag and resolves the promise properly.

Testing

  • Locally passed cargo clippy -p boa_runtime --all-features with zero warnings.
  • Extensively ran cargo test -p boa_runtime resolving all internal checks.
  • Adheres to the established specification guidelines and integrates with standard JS error generation patterns using JsNativeError.

@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: 8c01e4484d7abc884589f5b7be103f4ff53764fb
Compare commits: f5ae9f7...8c01e44

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 38.88889% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.10%. Comparing base (6ddc2b4) to head (8c01e44).
⚠️ Report is 845 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/fetch/response.rs 37.83% 23 Missing ⚠️
core/runtime/src/fetch/request.rs 46.66% 8 Missing ⚠️
core/runtime/src/fetch/headers.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5041       +/-   ##
===========================================
+ Coverage   47.24%   59.10%   +11.86%     
===========================================
  Files         476      563       +87     
  Lines       46892    62580    +15688     
===========================================
+ Hits        22154    36988    +14834     
- Misses      24738    25592      +854     

☔ 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.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@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.

3 participants