Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a js_class to implement the Class trait without boilerplate #3872

Merged
merged 7 commits into from
Jul 8, 2024

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Jun 4, 2024

This also adds a JsInstance that verifies that this is of the proper class, and an Ignore that ignore arguments.

The syntax is a bit special because of limitations of macro_rules. For example, the way fields are defined. It was impossible to keep both assignments (e.g. public field = 123;) and dynamic fields.

This reduces significantly the boilerplate for declaring classes. The example in class.rs is more than twice as long (if you remove comments) than the macro is.

hansl added 2 commits June 4, 2024 12:31
This also adds a JsInstance that verifies that `this` is of the proper
class, and an `Ignore` that ignore arguments.

The syntax is a bit special because of limitations of macro_rules. For
example, the way fields are defined. It was impossible to keep both
assignments (e.g. `public field = 123;`) and dynamic fields.

This reduces significantly the boilerplate for declaring classes. The
example in class.rs is more than twice as long (if you remove comments)
than the macro is.
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 58.82353% with 7 lines in your changes missing coverage. Please review.

Project coverage is 51.19%. Comparing base (6ddc2b4) to head (79f1586).
Report is 190 commits behind head on main.

Files Patch % Lines
core/interop/src/lib.rs 53.33% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3872      +/-   ##
==========================================
+ Coverage   47.24%   51.19%   +3.94%     
==========================================
  Files         476      470       -6     
  Lines       46892    45401    -1491     
==========================================
+ Hits        22154    23242    +1088     
+ Misses      24738    22159    -2579     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jedel1043 jedel1043 added enhancement New feature or request API labels Jun 30, 2024
@jedel1043 jedel1043 requested a review from a team June 30, 2024 00:19
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.

Really impressive work! Definitely having a boilerplate-free way to create JsClasses is a thing we should have.

I was wondering, what is the benefit of doing it with a macro_rules vs a procedural macro? I'm just worried about using macro_rules for this since it would pretty much disable all IDE autocompletions vs a procedural macro, which is a lot nicer to IDEs.

I was envisioning something like wasm_bindgen's getter and setter attributes

@hansl
Copy link
Contributor Author

hansl commented Jul 2, 2024

It was just easier for me to build a macro, and I wanted to have a more JS-ey way to describe the class. It would make sense to have a proc macro at some point, I just don't have the time yet. This reduces a lot of code already.

@jedel1043
Copy link
Member

It was just easier for me to build a macro, and I wanted to have a more JS-ey way to describe the class. It would make sense to have a proc macro at some point, I just don't have the time yet. This reduces a lot of code already.

Fail enough. I think we can start by offering a macro rules, then switch to a proc macro in the future.

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.

Thank you! I have some suggestions that remove the unwraps.

core/interop/src/lib.rs Outdated Show resolved Hide resolved
core/interop/src/lib.rs Outdated Show resolved Hide resolved
@hansl hansl requested a review from jedel1043 July 2, 2024 19:00
@hansl
Copy link
Contributor Author

hansl commented Jul 2, 2024

@jedel1043 PTAL

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.

Looks perfect to me!

@jedel1043 jedel1043 requested a review from a team July 2, 2024 19:04
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me! Thanks for all your work on this!

@nekevss nekevss added this pull request to the merge queue Jul 8, 2024
Merged via the queue into boa-dev:main with commit 58d0fe6 Jul 8, 2024
14 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants