/** * @file Shims for the seven ES2025 `Set` methods, all Node 22. * These take a "set-like" argument rather than only a real `Set`: anything * with a numeric `size`, a callable `has`, and a callable `keys`. That is the * part a naive implementation gets wrong, and it is observable in four ways a * caller can see: * * - WHICH of the two `has` methods runs. Every method except `union` picks a * side by comparing sizes, so a set-like with a counting `has` can tell. * - WHAT throws and when. `size` is read first, then `has`, then `keys`, so a * set-like whose `size` getter throws never reaches the `has` lookup. * - The ORDER of the result, which is insertion order and differs per method. * - Whether the set-like's iterator is CLOSED. A method that stops early has to * call the iterator's `return`. The spec's GetSetRecord abstraction is not * modeled as such. Only its observable consequences are, which is what * `test/test262-config` checks. Every touch of the receiver goes through a * PRIMORDIAL rather than a method call, for three more reasons a caller can * observe: a patched `Set.prototype.add` must not run while the result is * built, a subclass's overrides must not run either, and a receiver that is * not a real `Set` has to throw - which an uncurried primordial does on its * own. */ /** * Call an iterator's `return` if it has one, per IteratorClose. * * A method that stops before the iterator is exhausted owes it this call, and * test262 checks that the count matches. */ export declare function closeIterator(iterator: unknown): void; /** * The native `Set.prototype.` returning a set, or undefined below Node * 22. Read off the prototype at module load, so a later patch of the global * cannot change what this module hands out. */ export declare function nativeSetCombine(name: string): SetCombineFn | undefined; /** * The native `Set.prototype.` returning a boolean, or undefined below * Node 22. */ export declare function nativeSetPredicate(name: string): SetPredicateFn | undefined; /** * A step function over `iterator`, with `next` read ONCE. * * Reading `next` on every turn of the loop is observable: test262 records the * property gets, and the spec's GetIteratorDirect looks it up a single time. */ export declare function nextOf(iterator: unknown): () => IteratorResult; /** * The set-like's keys as an array, draining its iterator. */ export declare function recordKeysOf(record: SetRecord): T[]; /** * `Set.prototype.difference` shim. The receiver's elements that `other` lacks, * in the receiver's order. */ export declare function setDifferenceShim(set: ReadonlySet, other: SetLike): Set; /** * `Set.prototype.intersection` shim. * * The smaller side is iterated, which is why the result order depends on which * side that is. The choice is not an optimization detail: it decides whose * `has` runs, and a caller with a custom `has` sees the difference. */ export declare function setIntersectionShim(set: ReadonlySet, other: SetLike): Set; /** * `Set.prototype.isDisjointFrom` shim. Iterates the smaller side, so which * `has` runs depends on the sizes, and closes the set-like's iterator when it * stops early. */ export declare function setIsDisjointFromShim(set: ReadonlySet, other: SetLike): boolean; /** * `Set.prototype.isSubsetOf` shim. A receiver larger than `other` cannot be a * subset, so the size check short-circuits before any `has` call. */ export declare function setIsSubsetOfShim(set: ReadonlySet, other: SetLike): boolean; /** * `Set.prototype.isSupersetOf` shim. Reads `other`'s keys rather than calling * its `has`, which is the reverse of `isSubsetOf`, and closes that iterator * when it stops early. */ export declare function setIsSupersetOfShim(set: ReadonlySet, other: SetLike): boolean; /** * A method returning a new set: union, intersection, difference, * symmetricDifference. */ export type SetCombineFn = (set: ReadonlySet, other: SetLike) => Set; /** * A method returning a boolean: isSubsetOf, isSupersetOf, isDisjointFrom. */ export type SetPredicateFn = (set: ReadonlySet, other: SetLike) => boolean; /** * A set-like argument, reduced to the three members these methods use. */ export interface SetLike { has: (value: T) => boolean; keys: () => Iterator; size: number; } /** * The parts of the spec's Set Record a caller can observe. */ export interface SetRecord { has: (value: T) => boolean; keys: () => Iterator; size: number; } /** * Read `size`, `has`, and `keys` off a set-like, IN THAT ORDER. * * The order is observable: a set-like whose `size` getter throws must never * reach the `has` lookup. An undefined `size` becomes NaN and throws a * TypeError; a negative one throws a RangeError. */ export declare function setRecordOf(other: unknown): SetRecord; /** * The receiver's element count, read through the real `size` accessor so a * non-Set receiver throws here rather than silently reporting undefined. */ export declare function setSizeOf(set: ReadonlySet): number; /** * `Set.prototype.symmetricDifference` shim. The elements in exactly one side: * the receiver's first, then `other`'s. */ export declare function setSymmetricDifferenceShim(set: ReadonlySet, other: SetLike): Set; /** * `Set.prototype.union` shim. Every element of the receiver in its own order, * then each element of `other` not already present. */ export declare function setUnionShim(set: ReadonlySet, other: SetLike): Set; /** * The receiver's elements as an array, in insertion order. * * Copied up front through the primordial iterator: a set-like's `keys` may * mutate the receiver mid-run, and every method is specified against the * receiver as it was on entry. */ export declare function setValuesOf(set: ReadonlySet): T[]; export declare const setDifferenceNative: SetCombineFn | undefined; export declare const setDifference: SetCombineFn; export declare const setIntersectionNative: SetCombineFn | undefined; export declare const setIntersection: SetCombineFn; export declare const setIsDisjointFromNative: SetPredicateFn | undefined; export declare const setIsDisjointFrom: SetPredicateFn; export declare const setIsSubsetOfNative: SetPredicateFn | undefined; export declare const setIsSubsetOf: SetPredicateFn; export declare const setIsSupersetOfNative: SetPredicateFn | undefined; export declare const setIsSupersetOf: SetPredicateFn; export declare const setSymmetricDifferenceNative: SetCombineFn | undefined; export declare const setSymmetricDifference: SetCombineFn; export declare const setUnionNative: SetCombineFn | undefined; export declare const setUnion: SetCombineFn;