Skip to content

feat(macros): support symbol-named methods in #[boa(class)]#4697

Open
Yuvraj-cyborg wants to merge 3 commits intoboa-dev:mainfrom
Yuvraj-cyborg:symbol-naminh
Open

feat(macros): support symbol-named methods in #[boa(class)]#4697
Yuvraj-cyborg wants to merge 3 commits intoboa-dev:mainfrom
Yuvraj-cyborg:symbol-naminh

Conversation

@Yuvraj-cyborg
Copy link

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

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

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

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

@Yuvraj-cyborg
Copy link
Author

cc: @jedel1043

@github-actions
Copy link

github-actions bot commented Feb 23, 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%

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 21.73913% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.17%. Comparing base (6ddc2b4) to head (eebc6a4).
⚠️ Report is 710 commits behind head on main.

Files with missing lines Patch % Lines
core/macros/src/class.rs 0.00% 35 Missing ⚠️
core/macros/src/module.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4697      +/-   ##
==========================================
+ Coverage   47.24%   57.17%   +9.92%     
==========================================
  Files         476      550      +74     
  Lines       46892    60452   +13560     
==========================================
+ Hits        22154    34561   +12407     
- Misses      24738    25891    +1153     

☔ 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 added enhancement New feature or request API labels Feb 25, 2026
@Yuvraj-cyborg Yuvraj-cyborg requested a review from a team as a code owner February 25, 2026 11:22
@Yuvraj-cyborg
Copy link
Author

cc: @jedel1043

@jedel1043
Copy link
Member

No need to CC me, just requesting a review already pings my notifications haha

@Yuvraj-cyborg
Copy link
Author

No need to CC me, just requesting a review already pings my notifications haha

bad habit :)

Copy link
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.

Nice work! I have a suggestion to improve the maintainability of the code.

@jedel1043 jedel1043 added the waiting-on-author Waiting on PR changes from the author label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API enhancement New feature or request waiting-on-author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants