Skip to content

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

Merged
jedel1043 merged 5 commits intoboa-dev:mainfrom
Yuvraj-cyborg:symbol-naminh
Mar 6, 2026
Merged

feat(macros): support symbol-named methods in #[boa(class)]#4697
jedel1043 merged 5 commits intoboa-dev:mainfrom
Yuvraj-cyborg:symbol-naminh

Conversation

@Yuvraj-cyborg
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

cc: @jedel1043

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 23, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,666 49,666 0
Ignored 2,284 2,284 0
Failed 1,013 1,013 0
Panics 0 0 0
Conformance 93.77% 93.77% 0.00%

Tested main commit: 51e910f9dc23f9b78177abda803bc5f2f292e69e
Tested PR commit: a5951f19b44d0b36f007a3df919c63dba91854a2
Compare commits: 51e910f...a5951f1

Comment thread core/runtime/src/fetch/headers.rs Outdated
@codecov
Copy link
Copy Markdown

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.28%. Comparing base (6ddc2b4) to head (a5951f1).
⚠️ Report is 762 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.28%   +10.03%     
===========================================
  Files         476      556       +80     
  Lines       46892    60657    +13765     
===========================================
+ Hits        22154    34745    +12591     
- Misses      24738    25912     +1174     

☔ 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 A-Enhancement New feature or request A-API Changes related to public APIs 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
Copy Markdown
Contributor Author

cc: @jedel1043

@jedel1043
Copy link
Copy Markdown
Member

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

@Yuvraj-cyborg
Copy link
Copy Markdown
Contributor Author

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

bad habit :)

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.

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

Comment thread core/macros/src/class.rs Outdated
@jedel1043 jedel1043 added the Waiting On Author Waiting on PR changes from the author label Feb 27, 2026
@Yuvraj-cyborg
Copy link
Copy Markdown
Contributor Author

hey @jedel1043 could you review this !!
I have made the changes

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.

Nice work!

@jedel1043 jedel1043 enabled auto-merge March 6, 2026 01:45
@jedel1043 jedel1043 removed the Waiting On Author Waiting on PR changes from the author label Mar 6, 2026
@jedel1043 jedel1043 added this pull request to the merge queue Mar 6, 2026
Merged via the queue into boa-dev:main with commit 4acbac3 Mar 6, 2026
19 checks passed
@jedel1043 jedel1043 linked an issue Mar 6, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-API Changes related to public APIs A-Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support symbol-named methods in #[boa(class)] macro

2 participants