Skip to content

Fix/headers iterable #4611#4638

Merged
jedel1043 merged 8 commits intoboa-dev:mainfrom
Rahul-2k4:fix/headers-iterable-4611
Feb 27, 2026
Merged

Fix/headers iterable #4611#4638
jedel1043 merged 8 commits intoboa-dev:mainfrom
Rahul-2k4:fix/headers-iterable-4611

Conversation

@Rahul-2k4
Copy link
Copy Markdown
Contributor

@Rahul-2k4 Rahul-2k4 commented Feb 20, 2026

Summary

This PR makes Headers iterable in Boa runtime so it can be consumed by iterable APIs.

This Pull Request closes #4611

What changed

  • Added a regression test for Headers iterability:
    • spread: [...new Headers([["x", "y"]])]
    • Map construction: new Map(new Headers([["x", "y"]]))
  • Wired Headers.prototype[Symbol.iterator] during fetch registration.
  • Exposed entries, keys, and values as class methods on Headers.

Why

Headers should be iterable over [name, value] pairs. Without @@iterator, spread and
Map construction throw a TypeError.

Testing

cargo test -p boa_runtime fetch::tests -- --nocapture

All fetch tests pass, including the new regression test.

@Rahul-2k4 Rahul-2k4 changed the title Fix/headers iterable 4611 Fix/headers iterable #4611 Feb 20, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 20, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,862 52,862 0
Passed 49,504 49,504 0
Ignored 2,262 2,262 0
Failed 1,096 1,096 0
Panics 0 0 0
Conformance 93.65% 93.65% 0.00%

Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Looks almost perfect!

Comment thread core/runtime/src/fetch/headers.rs Outdated
@Rahul-2k4 Rahul-2k4 force-pushed the fix/headers-iterable-4611 branch from 9848a6e to 2e1480c Compare February 20, 2026 19:15
@jedel1043
Copy link
Copy Markdown
Member

If you're using AI agents to do this work, maybe you should use something like git-worktree to avoid accidentally pushing unrelated commits? Just a suggestion.

@Rahul-2k4
Copy link
Copy Markdown
Contributor Author

Rahul-2k4 commented Feb 20, 2026

yep sure @jedel1043 ill keep that in mind . i got little confused because of some uncommited changes of my other pr . and again thank you for the suggestion of worktree that it will keep my workspace clean . Will keep in mind and ill surely improve from next time and thanks for the quick reviews

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.23%. Comparing base (6ddc2b4) to head (49b5a13).
⚠️ Report is 691 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/fetch/mod.rs 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4638      +/-   ##
==========================================
+ Coverage   47.24%   57.23%   +9.99%     
==========================================
  Files         476      550      +74     
  Lines       46892    60428   +13536     
==========================================
+ Hits        22154    34587   +12433     
- Misses      24738    25841    +1103     

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

Comment thread core/runtime/src/fetch/mod.rs
@jedel1043 jedel1043 added A-Bug Something isn't working C-Builtins PRs and Issues related to builtins/intrinsics C-Runtime Issues and PRs related to Boa's runtime features and removed C-Builtins PRs and Issues related to builtins/intrinsics labels Feb 25, 2026
Comment thread core/runtime/src/fetch/mod.rs Outdated
@jedel1043 jedel1043 added the Waiting On Author Waiting on PR changes from the author label Feb 25, 2026
@Rahul-2k4 Rahul-2k4 force-pushed the fix/headers-iterable-4611 branch from cd41627 to ca51b07 Compare February 25, 2026 05:52
@Rahul-2k4 Rahul-2k4 force-pushed the fix/headers-iterable-4611 branch from ca51b07 to b286eec Compare February 25, 2026 06:03
Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Looks great! We'll hopefully remove all the boilerplate of setting up the method symbol when #4697 gets merged.

@Rahul-2k4
Copy link
Copy Markdown
Contributor Author

@jedel1043 yep sure

@Rahul-2k4 Rahul-2k4 requested a review from a team as a code owner February 26, 2026 09:23
Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Thank you, looks good!

@jedel1043 jedel1043 enabled auto-merge February 27, 2026 17:55
@jedel1043 jedel1043 added this pull request to the merge queue Feb 27, 2026
@jedel1043 jedel1043 removed the Waiting On Author Waiting on PR changes from the author label Feb 27, 2026
Merged via the queue into boa-dev:main with commit 88ba55b Feb 27, 2026
18 checks passed
@Rahul-2k4 Rahul-2k4 deleted the fix/headers-iterable-4611 branch February 27, 2026 19:58
akash-R-A-J pushed a commit to akash-R-A-J/boa that referenced this pull request Mar 1, 2026
## Summary

This PR makes `Headers` iterable in Boa runtime so it can be consumed by
iterable APIs.

This Pull Request closes boa-dev#4611 

  ### What changed

  - Added a regression test for `Headers` iterability:
    - spread: `[...new Headers([["x", "y"]])]`
    - `Map` construction: `new Map(new Headers([["x", "y"]]))`
- Wired `Headers.prototype[Symbol.iterator]` during fetch registration.
- Exposed `entries`, `keys`, and `values` as class methods on `Headers`.

  ### Why

`Headers` should be iterable over `[name, value]` pairs. Without
`@@iterator`, spread and
  `Map` construction throw a `TypeError`.

  ## Testing

  ```bash
  cargo test -p boa_runtime fetch::tests -- --nocapture

  All fetch tests pass, including the new regression test.
github-merge-queue Bot pushed a commit that referenced this pull request Mar 6, 2026
# Summary

This PR adds support for well-known symbol-keyed methods, statics, and
accessors
in the `#[boa(class)]` macro. This allows builtins to declare them
declaratively
instead of manually patching prototypes after registration.

**Closes:** #4688

---

# What Changed

## `core/macros/src/class.rs`

- Introduced a `MethodName` enum (`String | Symbol`) replacing the raw
`String` name on:
  - `Function`
  - `Accessor`
  - `ClassVisitor`
- `MethodName::to_key_tokens()` now emits:
  - `js_string!(...)` for string keys
  - `JsSymbol::iterator()` (etc.) for symbol keys
- `name_of()` now:
  - Checks for `#[boa(symbol = "...")]` first
  - Validates against the 13 well-known symbol names
- Falls through to `#[boa(rename = "...")]` or default rename scheme
otherwise
- `serialize_class_impl()` now uses polymorphic key tokens for:
  - `builder.method()`
  - `builder.static_method()`
  - `builder.accessor()`
- `match` is handled via `Ident::new_raw` since it is a Rust keyword

## `core/macros/src/module.rs`

- Updated `Function::from_sig` callsite to wrap the name in
`MethodName::String(...)`

## `core/runtime/src/fetch/headers.rs`

- Added `#[boa(symbol = "iterator")]` on `JsHeaders`
- Replaced the manual prototype patching TODO from #4638

## `tests/macros/tests/class.rs`

- Added `Pair` struct with:
  - `#[boa(symbol = "toPrimitive")]`
  - `#[boa(symbol = "iterator")]`
- Added `boa_class_symbol_methods` test covering:
  - Numeric coercion (`+p`)
  - Addition (`p + 3`)
  - Spread (`[...p]`)
  - `for...of`

---

# Accepted Symbol Names

The following well-known symbol names are supported:

- `asyncIterator`
- `hasInstance`
- `isConcatSpreadable`
- `iterator`
- `match`
- `matchAll`
- `replace`
- `search`
- `species`
- `split`
- `toPrimitive`
- `toStringTag`
- `unscopables`

Unknown names produce a compile-time error listing valid options.

---

# Usage Example

```rust
#[boa_class]
impl MyType {
    #[boa(symbol = "iterator")]
    fn iter(&self, ctx: &mut Context) -> JsValue {
        /* ... */
    }

    #[boa(symbol = "toPrimitive")]
    fn to_prim(&self) -> i32 {
        42
    }
}
```

---------

Co-authored-by: José Julián Espina <jedel0124@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Bug Something isn't working C-Runtime Issues and PRs related to Boa's runtime features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Headers should be iterable

2 participants