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

[Merged by Bors] - Safe wrapper for JsSet #2162

Closed
wants to merge 6 commits into from

Conversation

lameferret
Copy link
Contributor

@lameferret lameferret commented Jul 4, 2022

This PR adds a safe wrapper around JavaScript JsSet from builtins::set, and is being tracked at #2098.

Implements following methods

  • Set.prototype.size
  • Set.prototype.add(value)
  • Set.prototype.clear()
  • Set.prototype.delete(value)
  • Set.prototype.has(value)
  • Set.prototype.forEach(callbackFn[, thisArg])
    Implement wrapper for builtins::set_iterator, to be used by following.
  • Set.prototype.values()
  • Set.prototype.keys()
  • Set.prototype.entries()

*Note: Are there any other functions that should be added?

Also adds set_create() and made get_size() public in builtins::set.

@codecov
Copy link

codecov bot commented Jul 4, 2022

Codecov Report

Merging #2162 (0ae6918) into main (d0d7034) will decrease coverage by 0.18%.
The diff coverage is 2.89%.

@@            Coverage Diff             @@
##             main    #2162      +/-   ##
==========================================
- Coverage   42.32%   42.14%   -0.19%     
==========================================
  Files         228      230       +2     
  Lines       21047    21232     +185     
==========================================
+ Hits         8909     8949      +40     
- Misses      12138    12283     +145     
Impacted Files Coverage Δ
boa_engine/src/bigint.rs 38.34% <ø> (ø)
boa_engine/src/builtins/error/eval.rs 100.00% <ø> (ø)
boa_engine/src/builtins/error/syntax.rs 100.00% <ø> (ø)
boa_engine/src/builtins/error/uri.rs 100.00% <ø> (ø)
boa_engine/src/builtins/intl/mod.rs 60.95% <ø> (ø)
boa_engine/src/builtins/number/mod.rs 75.45% <ø> (ø)
boa_engine/src/builtins/set/mod.rs 78.02% <0.00%> (-7.53%) ⬇️
boa_engine/src/builtins/string/mod.rs 63.94% <ø> (ø)
...src/builtins/typed_array/integer_indexed_object.rs 0.00% <ø> (ø)
boa_engine/src/bytecompiler.rs 30.01% <0.00%> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0d7034...0ae6918. Read the comment docs.

@jedel1043 jedel1043 added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics API labels Jul 4, 2022
@jedel1043 jedel1043 added this to the v0.16.0 milestone Jul 4, 2022
@jedel1043
Copy link
Member

Ok, with #2115 we now have a simple API to handle JS iterators. Maybe it would be good if you checked out the PR and the corresponding implementation of JsMapIterator

@@ -164,7 +164,8 @@ impl Set {
Ok(set.into())
}

/// Utility for constructing `Set` Objects.
/// Utility for constructing `Set` objects.
#[allow(clippy::unnecessary_wraps)]
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for allowing this lint?
I think it would be better to return only a JsObject as the lint recommends

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because JsArray does it too (internal_methods::ordinary_define_own_property), I did the same to maintain some sort of consistency.

Copy link
Member

Choose a reason for hiding this comment

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

It's good to maintain consistency when it doesn't affect the usability of our program. However, this change impacts the usability, because now you need to handle an error on a function that cannot error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I understand.

boa_engine/src/object/jsobject.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/set/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Some leftover debug prints, but looks good!

boa_engine/src/builtins/set/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/set/mod.rs Outdated Show resolved Hide resolved
@lameferret lameferret requested a review from Razican July 7, 2022 13:19
Copy link
Member

@Razican Razican 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 to me now :)

Copy link
Member

@raskad raskad 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. Thanks for the additional typo fixes :)

@raskad
Copy link
Member

raskad commented Jul 7, 2022

bors r+

bors bot pushed a commit that referenced this pull request Jul 7, 2022
This PR adds a safe wrapper around JavaScript `JsSet` from `builtins::set`, and is being tracked at #2098.

Implements following methods 
- [x] `Set.prototype.size`
- [x] `Set.prototype.add(value)`
- [x] `Set.prototype.clear()`
- [x] `Set.prototype.delete(value)`
- [x] `Set.prototype.has(value)`
- [x] `Set.prototype.forEach(callbackFn[, thisArg])`
Implement wrapper for `builtins::set_iterator`, to be used by following.
- [x] `Set.prototype.values()`
- [x] `Set.prototype.keys()`
- [x] `Set.prototype.entries()`


*Note: Are there any other functions that should be added?

Also adds `set_create()` and made `get_size()` public in `builtins::set`.
@bors
Copy link

bors bot commented Jul 7, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Safe wrapper for JsSet [Merged by Bors] - Safe wrapper for JsSet Jul 7, 2022
@bors bors bot closed this Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants