From 5b0b68d81b9418baac1273f2735e54d19d30207c Mon Sep 17 00:00:00 2001 From: Okiki Date: Sat, 2 Mar 2024 10:22:34 +0000 Subject: [PATCH] ci: fix types Signed-off-by: Okiki --- tests/_arrays.ts | 11 +++++++++-- tests/_callbacks.ts | 11 +++++++++-- tests/_iterators.ts | 11 +++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/_arrays.ts b/tests/_arrays.ts index 443f65f..5b041ab 100644 --- a/tests/_arrays.ts +++ b/tests/_arrays.ts @@ -185,7 +185,7 @@ export async function textDecoderComplexArray( * @returns An async generator that yields Unicode code points. */ export async function asCodePointsBufferWindowArray( - iterable: AsyncIterator | Iterator + iterable: AsyncIterable | Iterable ) { const arr: number[] = []; @@ -196,11 +196,18 @@ export async function asCodePointsBufferWindowArray( const byteSequence = new Uint8Array(UTF8_MAX_BYTE_LENGTH); let byteSequenceRemainingBytes = 0; + // Create an async iterator from the source (works for both async and sync iterables). + const iterator = Symbol.asyncIterator in iterable + ? iterable[Symbol.asyncIterator]() : + Symbol.iterator in iterable + ? iterable[Symbol.iterator]() + : iterable; + let head = 0; // Head pointer (start position) let tail = 0; // Tail pointer (end position) while (true) { - const result = await iterable.next(); + const result = await iterator.next(); if (result.done) break; const chunk = result.value; diff --git a/tests/_callbacks.ts b/tests/_callbacks.ts index 3ed0636..47124d2 100644 --- a/tests/_callbacks.ts +++ b/tests/_callbacks.ts @@ -247,7 +247,7 @@ export async function textDecoderCustomIteratorCallback( * @returns An async generator that yields Unicode code points. */ export async function asCodePointsBufferWindowCallback( - iterable: AsyncIterator | Iterator, + iterable: AsyncIterable | Iterable, cb: (codePoint: number) => void ) { /** @@ -257,11 +257,18 @@ export async function asCodePointsBufferWindowCallback( const byteSequence = new Uint8Array(UTF8_MAX_BYTE_LENGTH); let byteSequenceRemainingBytes = 0; + // Create an async iterator from the source (works for both async and sync iterables). + const iterator = Symbol.asyncIterator in iterable + ? iterable[Symbol.asyncIterator]() : + Symbol.iterator in iterable + ? iterable[Symbol.iterator]() + : iterable; + let head = 0; // Head pointer (start position) let tail = 0; // Tail pointer (end position) while (true) { - const result = await iterable.next(); + const result = await iterator.next(); if (result.done) break; const chunk = result.value; diff --git a/tests/_iterators.ts b/tests/_iterators.ts index 6006f95..ceee1e7 100644 --- a/tests/_iterators.ts +++ b/tests/_iterators.ts @@ -179,7 +179,7 @@ export async function* textDecoderComplexIterator( * @returns An async generator that yields Unicode code points. */ export async function* asCodePointsBufferWindowIterator( - iterable: AsyncIterator | Iterator + iterable: AsyncIterable | Iterable ) { /** * - `byteSequence` stores the bytes of the current UTF-8 character being processed. @@ -188,11 +188,18 @@ export async function* asCodePointsBufferWindowIterator( const byteSequence = new Uint8Array(UTF8_MAX_BYTE_LENGTH); let byteSequenceRemainingBytes = 0; + // Create an async iterator from the source (works for both async and sync iterables). + const iterator = Symbol.asyncIterator in iterable + ? iterable[Symbol.asyncIterator]() : + Symbol.iterator in iterable + ? iterable[Symbol.iterator]() + : iterable; + let head = 0; // Head pointer (start position) let tail = 0; // Tail pointer (end position) while (true) { - const result = await iterable.next(); + const result = await iterator.next(); if (result.done) break; const chunk = result.value;