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

Named accessor ops #965

Merged
merged 7 commits into from
Nov 18, 2024
Merged

Named accessor ops #965

merged 7 commits into from
Nov 18, 2024

Conversation

littledivy
Copy link
Member

Implement get/set accessors for object wrap ops.

#[op2]
impl DOMPoint {
  #[getter]
  fn x(&self) -> f64 {
    self.x
  }
  
  #[setter]
  fn x(&self, x: f64) {}
}
point.x;
point.x = 10; 

@littledivy littledivy marked this pull request as ready for review November 17, 2024 16:18
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 89.91597% with 12 lines in your changes missing coverage. Please review.

Project coverage is 81.53%. Comparing base (0c7f83e) to head (1c2d9c8).
Report is 164 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/bindings.rs 89.47% 8 Missing ⚠️
core/extensions.rs 60.00% 2 Missing ⚠️
ops/op2/dispatch_slow.rs 88.88% 1 Missing ⚠️
testing/checkin/runner/ops.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #965      +/-   ##
==========================================
+ Coverage   81.43%   81.53%   +0.09%     
==========================================
  Files          97       98       +1     
  Lines       23877    25361    +1484     
==========================================
+ Hits        19445    20678    +1233     
- Misses       4432     4683     +251     

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

Comment on lines +528 to +529
// All setters must start with "__set_".
let key = key.strip_prefix("__set_").expect("Invalid setter name");
Copy link
Member

Choose a reason for hiding this comment

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

Is there a particular reason for this? Why don't getters require to start with __get_?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to allow for getter and setters to be defined with the same name. Only one needs to be changed to avoid name collision

#[getter]
fn x() {}

#[setter]
fn x() {} // op2 automatically converts this to __set_x to avoid name collision

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Very nice, LGTM!

@littledivy littledivy merged commit 0fff924 into denoland:main Nov 18, 2024
18 checks passed
littledivy added a commit to denoland/deno that referenced this pull request Nov 19, 2024
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