Skip to content

Commit

Permalink
Improve brand checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed May 30, 2021
1 parent 0350488 commit f93e744
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib/byte-length-queuing-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ export function IsByteLengthQueuingStrategy(x: any): x is ByteLengthQueuingStrat
return false;
}

return true;
return x instanceof ByteLengthQueuingStrategy;
}
2 changes: 1 addition & 1 deletion src/lib/count-queuing-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ export function IsCountQueuingStrategy(x: any): x is CountQueuingStrategy {
return false;
}

return true;
return x instanceof CountQueuingStrategy;
}
2 changes: 1 addition & 1 deletion src/lib/readable-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export function IsReadableStream(x: unknown): x is ReadableStream {
return false;
}

return true;
return x instanceof ReadableStream;
}

export function IsReadableStreamDisturbed(stream: ReadableStream): boolean {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/readable-stream/async-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ function IsReadableStreamAsyncIterator<R = any>(x: any): x is ReadableStreamAsyn
return false;
}

return true;
try {
// noinspection SuspiciousTypeOfGuard
return (x as ReadableStreamAsyncIteratorInstance<any>)._asyncIteratorImpl instanceof ReadableStreamAsyncIteratorImpl;
} catch {
return false;
}
}

// Helper functions for the ReadableStream.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/readable-stream/byob-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function IsReadableStreamBYOBReader(x: any): x is ReadableStreamBYOBReade
return false;
}

return true;
return x instanceof ReadableStreamBYOBReader;
}

function ReadableStreamBYOBReaderRead<T extends ArrayBufferView>(reader: ReadableStreamBYOBReader,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/readable-stream/byte-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export function IsReadableByteStreamController(x: any): x is ReadableByteStreamC
return false;
}

return true;
return x instanceof ReadableByteStreamController;
}

function IsReadableStreamBYOBRequest(x: any): x is ReadableStreamBYOBRequest {
Expand All @@ -400,7 +400,7 @@ function IsReadableStreamBYOBRequest(x: any): x is ReadableStreamBYOBRequest {
return false;
}

return true;
return x instanceof ReadableStreamBYOBRequest;
}

function ReadableByteStreamControllerCallPullIfNeeded(controller: ReadableByteStreamController): void {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/readable-stream/default-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function IsReadableStreamDefaultController<R = any>(x: any): x is ReadableStream
return false;
}

return true;
return x instanceof ReadableStreamDefaultController;
}

function ReadableStreamDefaultControllerCallPullIfNeeded(controller: ReadableStreamDefaultController<any>): void {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/readable-stream/default-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function IsReadableStreamDefaultReader<R = any>(x: any): x is ReadableStr
return false;
}

return true;
return x instanceof ReadableStreamDefaultReader;
}

export function ReadableStreamDefaultReaderRead<R>(reader: ReadableStreamDefaultReader<R>,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/transform-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function IsTransformStream(x: unknown): x is TransformStream {
return false;
}

return true;
return x instanceof TransformStream;
}

// This is a no-op if both sides are already errored.
Expand Down Expand Up @@ -348,7 +348,7 @@ function IsTransformStreamDefaultController<O = any>(x: any): x is TransformStre
return false;
}

return true;
return x instanceof TransformStreamDefaultController;
}

function SetUpTransformStreamDefaultController<I, O>(stream: TransformStream<I, O>,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/writable-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function IsWritableStream(x: unknown): x is WritableStream {
return false;
}

return true;
return x instanceof WritableStream;
}

function IsWritableStreamLocked(stream: WritableStream): boolean {
Expand Down Expand Up @@ -786,7 +786,7 @@ function IsWritableStreamDefaultWriter<W = any>(x: any): x is WritableStreamDefa
return false;
}

return true;
return x instanceof WritableStreamDefaultWriter;
}

// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
Expand Down Expand Up @@ -997,7 +997,7 @@ function IsWritableStreamDefaultController(x: any): x is WritableStreamDefaultCo
return false;
}

return true;
return x instanceof WritableStreamDefaultController;
}

function SetUpWritableStreamDefaultController<W>(stream: WritableStream<W>,
Expand Down

0 comments on commit f93e744

Please sign in to comment.