Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ copyright: false
1. If _toSkip_ &lt; *-0*<sub>𝔽</sub>, then
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
1. Return ? IteratorClose(_iterated_, _error_).
1. If _toSkip_ is finite and _toSkip_ > 𝔽(2<sup>53</sup> - 1), then
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
1. Return ? IteratorClose(_iterated_, _error_).
1. Let _skipped_ be *+0*<sub>𝔽</sub>.
1. Set _iterated_ to ? GetIteratorDirect(_O_).
1. Repeat,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function includes<T>(this: IterableIterator<T>, searchElement: T, skippedElement
}
toSkip = skippedElements as number;
}
if (toSkip < 0) {
if (toSkip < 0 || Number.isFinite(toSkip) && toSkip > Number.MAX_SAFE_INTEGER) {
try { this.return?.(); } catch {}
throw new RangeError;
}
Expand Down
13 changes: 13 additions & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ test('skipped elements', async t => {
assert.equal([4, 5, 6, 7].values().includes(7, 5), false);
});

await test('Number.MAX_SAFE_INTEGER', async t => {
assert.equal([0].values().includes(0, Number.MAX_SAFE_INTEGER), false);
});

await test('positive non-integral', async t => {
assert.throws(() => {
[].values().includes(0, 0.1);
Expand Down Expand Up @@ -215,6 +219,15 @@ test('skipped elements', async t => {
[].values().includes(0, { valueOf() { return 0; } });
}, TypeError);
});

await test('greater than Number.MAX_SAFE_INTEGER', async t => {
assert.throws(() => {
[].values().includes(0, Number.MAX_SAFE_INTEGER + 1);
}, RangeError);
assert.throws(() => {
[].values().includes(0, Number.MAX_SAFE_INTEGER + 3);
}, RangeError);
});
});

test('name', async t => {
Expand Down
Loading