Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Oct 12, 2024
1 parent 9970d6e commit c56620c
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 328 deletions.
28 changes: 13 additions & 15 deletions src/lib/abstract-ops/ecmascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export function CreateArrayFromList<T extends any[]>(elements: T): T {
return elements.slice() as T;
}

export function CopyDataBlockBytes(dest: ArrayBuffer,
destOffset: number,
src: ArrayBuffer,
srcOffset: number,
n: number) {
export function CopyDataBlockBytes(
dest: ArrayBuffer,
destOffset: number,
src: ArrayBuffer,
srcOffset: number,
n: number
) {
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
}

Expand Down Expand Up @@ -102,9 +104,7 @@ export interface AsyncIteratorRecord<T> {

export type SyncOrAsyncIteratorRecord<T> = SyncIteratorRecord<T> | AsyncIteratorRecord<T>;

export function CreateAsyncFromSyncIterator<T>(
syncIteratorRecord: SyncIteratorRecord<SyncOrAsync<T>>
): AsyncIteratorRecord<T> {
export function CreateAsyncFromSyncIterator<T>(syncIteratorRecord: SyncIteratorRecord<SyncOrAsync<T>>): AsyncIteratorRecord<T> {
const asyncIterator: AsyncIterator<T> = {
// https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next
next() {
Expand Down Expand Up @@ -154,10 +154,10 @@ function AsyncFromSyncIteratorContinuation<T>(result: IteratorResult<SyncOrAsync
}

// Aligns with core-js/modules/es.symbol.async-iterator.js
export const SymbolAsyncIterator: (typeof Symbol)['asyncIterator'] =
Symbol.asyncIterator ??
Symbol.for?.('Symbol.asyncIterator') ??
'@@asyncIterator';
export const SymbolAsyncIterator: (typeof Symbol)['asyncIterator']
= Symbol.asyncIterator
?? Symbol.for?.('Symbol.asyncIterator')
?? '@@asyncIterator';

export type SyncOrAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;
export type SyncOrAsyncIteratorMethod<T> = () => (Iterator<T> | AsyncIterator<T>);
Expand Down Expand Up @@ -205,9 +205,7 @@ export { GetIterator };

export function IteratorNext<T>(iteratorRecord: SyncIteratorRecord<T>): IteratorResult<T>;
export function IteratorNext<T>(iteratorRecord: AsyncIteratorRecord<T>): Promise<IteratorResult<T>>;
export function IteratorNext<T>(
iteratorRecord: SyncOrAsyncIteratorRecord<T>
): SyncOrAsync<IteratorResult<SyncOrAsync<T>>> {
export function IteratorNext<T>(iteratorRecord: SyncOrAsyncIteratorRecord<T>): SyncOrAsync<IteratorResult<SyncOrAsync<T>>> {
const result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
if (!typeIsObject(result)) {
throw new TypeError('The iterator.next() method must return an object');
Expand Down
24 changes: 12 additions & 12 deletions src/lib/helpers/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ export function typeIsObject(x: any): x is object {
return (typeof x === 'object' && x !== null) || typeof x === 'function';
}

export const rethrowAssertionErrorRejection: (e: any) => void =
DEBUG ?
(e) => {
// Used throughout the reference implementation, as `.catch(rethrowAssertionErrorRejection)`, to ensure any errors
// get shown. There are places in the spec where we do promise transformations and purposefully ignore or don't
// expect any errors, but assertion errors are always problematic.
if (e && e instanceof AssertionError) {
setTimeout(() => {
throw e;
}, 0);
export const rethrowAssertionErrorRejection: (e: any) => void
= DEBUG
? (e) => {
// Used throughout the reference implementation, as `.catch(rethrowAssertionErrorRejection)`, to ensure any errors
// get shown. There are places in the spec where we do promise transformations and purposefully ignore or don't
// expect any errors, but assertion errors are always problematic.
if (e && e instanceof AssertionError) {
setTimeout(() => {
throw e;
}, 0);
}
}
} :
noop;
: noop;

export function setFunctionName(fn: (...args: any[]) => any, name: string): void {
try {
Expand Down
17 changes: 11 additions & 6 deletions src/lib/helpers/webidl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export function promiseRejectedWith<T = never>(reason: any): Promise<T> {
export function PerformPromiseThen<T, TResult1 = T, TResult2 = never>(
promise: Promise<T>,
onFulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>,
onRejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2> {
onRejected?: (reason: any) => TResult2 | PromiseLike<TResult2>
): Promise<TResult1 | TResult2> {
// There doesn't appear to be any way to correctly emulate the behaviour from JavaScript, so this is just an
// approximation.
return originalPromiseThen.call(promise, onFulfilled, onRejected) as Promise<TResult1 | TResult2>;
Expand All @@ -41,7 +42,8 @@ export function PerformPromiseThen<T, TResult1 = T, TResult2 = never>(
export function uponPromise<T>(
promise: Promise<T>,
onFulfilled?: (value: T) => null | PromiseLike<null>,
onRejected?: (reason: any) => null | PromiseLike<null>): void {
onRejected?: (reason: any) => null | PromiseLike<null>
): void {
PerformPromiseThen(
PerformPromiseThen(promise, onFulfilled, onRejected),
undefined,
Expand All @@ -60,7 +62,8 @@ export function uponRejection(promise: Promise<unknown>, onRejected: (reason: an
export function transformPromiseWith<T, TResult1 = T, TResult2 = never>(
promise: Promise<T>,
fulfillmentHandler?: (value: T) => TResult1 | PromiseLike<TResult1>,
rejectionHandler?: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2> {
rejectionHandler?: (reason: any) => TResult2 | PromiseLike<TResult2>
): Promise<TResult1 | TResult2> {
return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
}

Expand All @@ -87,9 +90,11 @@ export function reflectCall<T, A extends any[], R>(F: (this: T, ...fnArgs: A) =>
return Function.prototype.apply.call(F, V, args);
}

export function promiseCall<T, A extends any[], R>(F: (this: T, ...fnArgs: A) => R | PromiseLike<R>,
V: T,
args: A): Promise<R> {
export function promiseCall<T, A extends any[], R>(
F: (this: T, ...fnArgs: A) => R | PromiseLike<R>,
V: T,
args: A
): Promise<R> {
assert(typeof F === 'function');
assert(V !== undefined);
assert(Array.isArray(args));
Expand Down
40 changes: 15 additions & 25 deletions src/lib/readable-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {

constructor(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number; size?: undefined });
constructor(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>);
constructor(rawUnderlyingSource: UnderlyingSource<R> | UnderlyingByteSource | null | undefined = {},
rawStrategy: QueuingStrategy<R> | null | undefined = {}) {
constructor(
rawUnderlyingSource: UnderlyingSource<R> | UnderlyingByteSource | null | undefined = {},
rawStrategy: QueuingStrategy<R> | null | undefined = {}
) {
if (rawUnderlyingSource === undefined) {
rawUnderlyingSource = null;
} else {
Expand Down Expand Up @@ -183,9 +185,7 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
* or cancel the stream, which would interfere with your abstraction.
*/
getReader(): ReadableStreamDefaultReader<R>;
getReader(
rawOptions: ReadableStreamGetReaderOptions | null | undefined = undefined
): ReadableStreamDefaultReader<R> | ReadableStreamBYOBReader {
getReader(rawOptions: ReadableStreamGetReaderOptions | null | undefined = undefined): ReadableStreamDefaultReader<R> | ReadableStreamBYOBReader {
if (!IsReadableStream(this)) {
throw streamBrandCheckException('getReader');
}
Expand Down Expand Up @@ -230,9 +230,7 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream');
}

const promise = ReadableStreamPipeTo(
this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal
);
const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);

setPromiseIsHandledToTrue(promise);

Expand All @@ -247,8 +245,10 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
* Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
*/
pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
pipeTo(destination: WritableStream<R> | null | undefined,
rawOptions: StreamPipeOptions | null | undefined = {}): Promise<void> {
pipeTo(
destination: WritableStream<R> | null | undefined,
rawOptions: StreamPipeOptions | null | undefined = {}
): Promise<void> {
if (!IsReadableStream(this)) {
return promiseRejectedWith(streamBrandCheckException('pipeTo'));
}
Expand All @@ -257,9 +257,7 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`);
}
if (!IsWritableStream(destination)) {
return promiseRejectedWith(
new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`)
);
return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`));
}

let options: ValidatedStreamPipeOptions;
Expand All @@ -270,19 +268,13 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
}

if (IsReadableStreamLocked(this)) {
return promiseRejectedWith(
new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')
);
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream'));
}
if (IsWritableStreamLocked(destination)) {
return promiseRejectedWith(
new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')
);
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream'));
}

return ReadableStreamPipeTo<R>(
this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal
);
return ReadableStreamPipeTo<R>(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
}

/**
Expand Down Expand Up @@ -413,9 +405,7 @@ export function CreateReadableStream<R>(
InitializeReadableStream(stream);

const controller: ReadableStreamDefaultController<R> = Object.create(ReadableStreamDefaultController.prototype);
SetUpReadableStreamDefaultController(
stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm
);
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);

return stream;
}
Expand Down
22 changes: 12 additions & 10 deletions src/lib/readable-stream/async-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ export class ReadableStreamAsyncIteratorImpl<R> {

next(): Promise<ReadableStreamDefaultReadResult<R>> {
const nextSteps = () => this._nextSteps();
this._ongoingPromise = this._ongoingPromise ?
transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) :
nextSteps();
this._ongoingPromise = this._ongoingPromise
? transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps)
: nextSteps();
return this._ongoingPromise;
}

return(value: any): Promise<ReadableStreamDefaultReadResult<any>> {
const returnSteps = () => this._returnSteps(value);
return this._ongoingPromise ?
transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) :
returnSteps();
return this._ongoingPromise
? transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps)
: returnSteps();
}

private _nextSteps(): Promise<ReadableStreamDefaultReadResult<R>> {
Expand Down Expand Up @@ -153,8 +153,10 @@ Object.defineProperty(ReadableStreamAsyncIteratorPrototype, SymbolAsyncIterator,

// Abstract operations for the ReadableStream.

export function AcquireReadableStreamAsyncIterator<R>(stream: ReadableStream<R>,
preventCancel: boolean): ReadableStreamAsyncIterator<R> {
export function AcquireReadableStreamAsyncIterator<R>(
stream: ReadableStream<R>,
preventCancel: boolean
): ReadableStreamAsyncIterator<R> {
const reader = AcquireReadableStreamDefaultReader<R>(stream);
const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
const iterator: ReadableStreamAsyncIteratorInstance<R> = Object.create(ReadableStreamAsyncIteratorPrototype);
Expand All @@ -173,8 +175,8 @@ function IsReadableStreamAsyncIterator<R = any>(x: any): x is ReadableStreamAsyn

try {
// noinspection SuspiciousTypeOfGuard
return (x as ReadableStreamAsyncIteratorInstance<any>)._asyncIteratorImpl instanceof
ReadableStreamAsyncIteratorImpl;
return (x as ReadableStreamAsyncIteratorInstance<any>)._asyncIteratorImpl
instanceof ReadableStreamAsyncIteratorImpl;
} catch {
return false;
}
Expand Down
15 changes: 8 additions & 7 deletions src/lib/readable-stream/byob-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export function ReadableStreamAddReadIntoRequest<T extends NonShared<ArrayBuffer
(stream._reader! as ReadableStreamBYOBReader)._readIntoRequests.push(readIntoRequest);
}

export function ReadableStreamFulfillReadIntoRequest(stream: ReadableByteStream,
chunk: ArrayBufferView,
done: boolean) {
export function ReadableStreamFulfillReadIntoRequest(
stream: ReadableByteStream,
chunk: ArrayBufferView,
done: boolean
) {
const reader = stream._reader as ReadableStreamBYOBReader;

assert(reader._readIntoRequests.length > 0);
Expand Down Expand Up @@ -124,8 +126,8 @@ export class ReadableStreamBYOBReader {
}

if (!IsReadableByteStreamController(stream._readableStreamController)) {
throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' +
'source');
throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte '
+ 'source');
}

ReadableStreamReaderGenericInitialize(this, stream);
Expand Down Expand Up @@ -320,6 +322,5 @@ export function ReadableStreamBYOBReaderErrorReadIntoRequests(reader: ReadableSt
// Helper functions for the ReadableStreamBYOBReader.

function byobReaderBrandCheckException(name: string): TypeError {
return new TypeError(
`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
}
Loading

0 comments on commit c56620c

Please sign in to comment.