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

Implement Set methods from ECMAScript Specification Features/#4128 #4145

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Hemenguelbindi
Copy link

This Pull Request fixes/closes #{issue_num}.

It changes the following:

  • Implemented the Set methods from the ECMAScript specification
    • Set.prototype.difference(other)
    • Set.prototype.intersection(other)
    • Set.prototype.isDisjointFrom(other)
    • Set.prototype.isSubsetOf(other)
    • Set.prototype.isSupersetOf(other)
    • Set.prototype.symmetricDifference(other)
    • Set.prototype.union(other)
  • Added test cases for all newly implemented methods to ensure specification compliance.
  • Updated relevant documentation and comments for clarity.

Additional Information:
This implementation aligns with the ECMAScript specification, section 24.2.4, and follows the behavior described in the Set Methods Proposal. Test coverage includes edge cases such as empty sets, overlapping sets, and disjoint sets.

Feel free to let me know if there are areas for improvement or adjustments!

Copy link

codecov bot commented Jan 26, 2025

Codecov Report

Attention: Patch coverage is 62.09677% with 47 lines in your changes missing coverage. Please review.

Project coverage is 53.60%. Comparing base (6ddc2b4) to head (9e515e3).
Report is 357 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/builtins/set/mod.rs 62.09% 47 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4145      +/-   ##
==========================================
+ Coverage   47.24%   53.60%   +6.36%     
==========================================
  Files         476      487      +11     
  Lines       46892    48998    +2106     
==========================================
+ Hits        22154    26267    +4113     
+ Misses      24738    22731    -2007     

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

@nekevss
Copy link
Member

nekevss commented Jan 26, 2025

This is looking great so far!

It looks like you may need to run cargo fmt --all

Also, if you remove set-methods from the test262_config.toml, then you should be able to run the Set built-in test262 suite with boa_tester:

cargo run --release --bin boa_tester -- run -vv -s test/built-ins/Set/prototype

If you want more verbose feedback, you can run:

cargo run --release --bin boa_tester -- run -vvv -s test/built-ins/Set/prototype

Adding the specific method on the end of the path can target that specific method.

@Hemenguelbindi
Copy link
Author

i am done all fix need this issus #4128

@nekevss nekevss requested a review from a team January 30, 2025 17:37
@nekevss nekevss added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics labels Jan 30, 2025
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.

This is looking great so far!

Have some general feedback to help increase test coverage on the implementation and a typo.

// 3. Let otherRec be ? GetSetRecord(other).
// (ECMAScript 2022, 24.2.3.6 step 3)
let other = args.get_or_undefined(0);
let Some(other_set) = other
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: implement GetSetRecord here over downcasting to OrderedSet

It is actually possible for other to be a user implemented set like object. An example of this would be this test262 test.

Copy link
Author

Choose a reason for hiding this comment

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

I understand you. I need to implement the equivalent of GetRecord. I think I should do this in the orderset file, and it will be called SetRecord, which will eliminate all the repetitive code I wrote before, right?

Copy link
Member

Choose a reason for hiding this comment

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

The method that needs to be implemented is here. My initial reaction based off reading is that this abstract op would be implemented in mod.rs.

.and_then(JsObject::downcast_ref::<OrderedSet>)
else {
return Err(JsNativeError::typ()
.with_message("Method Set.prototype.difference called on incompatible receiver")
Copy link
Member

Choose a reason for hiding this comment

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

typo: Set.prototype.difference => Set.prototype.intersection

let other = args.get_or_undefined(0);
// 4. Let other_set be the second argument.
// We try to downcast the second argument into an `OrderedSet`, which is the other set with which we perform the intersection.
let Some(other_set) = other
Copy link
Member

Choose a reason for hiding this comment

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

See comment on using GetSetRecord in difference

///
/// [spec]: https://tc39.es/ecma262/#sec-set.prototype.isdisjointfrom
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom
pub(crate) fn is_dis_joint_from(
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename to is_disjoint_from


// 3. Let otherRec be ? GetSetRecord(other).
let other = args.get_or_undefined(0);
let Some(other_set) = other
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: use GetSetRecord abstract op

See review comment on difference method.

// 2. Perform ? RequireInternalSlot(O, [[SetData]]).
// 3. Let otherRec be ? GetSetRecord(other).
let other = args.get_or_undefined(0);
let Some(other_set) = other
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: use GetSetRecord

See review comment on difference method

@nekevss nekevss requested a review from a team February 1, 2025 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants