Skip to content

Set operation methods should accept set-like objects via GetSetRecord #422

@frostney

Description

@frostney

Summary

The ES2026 Set operation methods (union, intersection, difference, symmetricDifference, isSubsetOf, isSupersetOf, isDisjointFrom) currently only accept TGocciaSetValue instances as the other argument. Per ES2026 §7.3.45, they should accept any set-like object — an object with size, has(), and keys() — via the GetSetRecord(obj) abstract operation.

Current behavior

const setLike = {
  size: 2,
  has(v) { return v === 1 || v === 2; },
  *keys() { yield 1; yield 2; }
};
new Set([1, 2, 3]).intersection(setLike);
// TypeError: Set.prototype.intersection: argument must be a Set

Expected behavior

new Set([1, 2, 3]).intersection(setLike);
// Set {1, 2}

What needs to happen

  1. Implement GetSetRecord(obj) — read .size (coerce to number), .has (require callable), .keys (require callable) from the argument and return a record. Throw TypeError if validation fails.
  2. Replace the is TGocciaSetValue argument checks in all 7 Set operation methods with a GetSetRecord call.
  3. Update the iteration in each method to use the keys iterator from the record instead of directly accessing FItems.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions