diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-28 17:40:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 12:40:43 -0400 |
commit | 678313b17677e012ba9a07aeca58af1aafbf4e8c (patch) | |
tree | e48e25b165a7d6d566095442448f2e36fa09c561 /std/ws | |
parent | 47c2f034e95696a47770d60aec1362501e7f330d (diff) |
BREAKING: Remove Deno.EOF, use null instead (#4953)
Diffstat (limited to 'std/ws')
-rw-r--r-- | std/ws/README.md | 2 | ||||
-rw-r--r-- | std/ws/example_client.ts | 2 | ||||
-rw-r--r-- | std/ws/mod.ts | 22 | ||||
-rw-r--r-- | std/ws/test.ts | 10 |
4 files changed, 20 insertions, 16 deletions
diff --git a/std/ws/README.md b/std/ws/README.md index 2379d9f96..5dcb9ce90 100644 --- a/std/ws/README.md +++ b/std/ws/README.md @@ -102,7 +102,7 @@ const tpr = new TextProtoReader(new BufReader(Deno.stdin)); while (true) { await Deno.stdout.write(encode("> ")); const line = await tpr.readLine(); - if (line === Deno.EOF) { + if (line === null) { break; } if (line === "close") { diff --git a/std/ws/example_client.ts b/std/ws/example_client.ts index 3b1c6a33a..d680c6fef 100644 --- a/std/ws/example_client.ts +++ b/std/ws/example_client.ts @@ -31,7 +31,7 @@ const tpr = new TextProtoReader(new BufReader(Deno.stdin)); while (true) { await Deno.stdout.write(encode("> ")); const line = await tpr.readLine(); - if (line === Deno.EOF) { + if (line === null) { break; } if (line === "close") { diff --git a/std/ws/mod.ts b/std/ws/mod.ts index 9632fbbfb..7e444f274 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -8,7 +8,7 @@ import { Sha1 } from "../util/sha1.ts"; import { writeResponse } from "../http/io.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { Deferred, deferred } from "../util/async.ts"; -import { assertNotEOF } from "../testing/asserts.ts"; +import { assert } from "../testing/asserts.ts"; import { concat } from "../bytes/mod.ts"; import Conn = Deno.Conn; import Writer = Deno.Writer; @@ -149,7 +149,8 @@ export async function writeFrame( * @throws `Error` Frame is invalid */ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> { - let b = assertNotEOF(await buf.readByte()); + let b = await buf.readByte(); + assert(b !== null); let isLastFrame = false; switch (b >>> 4) { case 0b1000: @@ -163,25 +164,28 @@ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> { } const opcode = b & 0x0f; // has_mask & payload - b = assertNotEOF(await buf.readByte()); + b = await buf.readByte(); + assert(b !== null); const hasMask = b >>> 7; let payloadLength = b & 0b01111111; if (payloadLength === 126) { - const l = assertNotEOF(await readShort(buf)); + const l = await readShort(buf); + assert(l !== null); payloadLength = l; } else if (payloadLength === 127) { - const l = assertNotEOF(await readLong(buf)); + const l = await readLong(buf); + assert(l !== null); payloadLength = Number(l); } // mask let mask: Uint8Array | undefined; if (hasMask) { mask = new Uint8Array(4); - assertNotEOF(await buf.readFull(mask)); + assert((await buf.readFull(mask)) !== null); } // payload const payload = new Uint8Array(payloadLength); - assertNotEOF(await buf.readFull(payload)); + assert((await buf.readFull(payload)) !== null); return { isLastFrame, opcode, @@ -479,7 +483,7 @@ export async function handshake( const tpReader = new TextProtoReader(bufReader); const statusLine = await tpReader.readLine(); - if (statusLine === Deno.EOF) { + if (statusLine === null) { throw new Deno.errors.UnexpectedEof(); } const m = statusLine.match(/^(?<version>\S+) (?<statusCode>\S+) /); @@ -497,7 +501,7 @@ export async function handshake( } const responseHeaders = await tpReader.readMIMEHeader(); - if (responseHeaders === Deno.EOF) { + if (responseHeaders === null) { throw new Deno.errors.UnexpectedEof(); } diff --git a/std/ws/test.ts b/std/ws/test.ts index 20ba2ba61..0d4541f62 100644 --- a/std/ws/test.ts +++ b/std/ws/test.ts @@ -278,7 +278,7 @@ function dummyConn(r: Reader, w: Writer): Conn { rid: -1, closeRead: (): void => {}, closeWrite: (): void => {}, - read: (x): Promise<number | Deno.EOF> => r.read(x), + read: (x): Promise<number | null> => r.read(x), write: (x): Promise<number> => w.write(x), close: (): void => {}, localAddr: { transport: "tcp", hostname: "0.0.0.0", port: 0 }, @@ -335,8 +335,8 @@ test("[ws] createSecKeyHasCorrectLength", () => { test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed connection without close frame", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - read(_: Uint8Array): Promise<number | Deno.EOF> { - return Promise.resolve(Deno.EOF); + read(_: Uint8Array): Promise<number | null> { + return Promise.resolve(null); }, }; const conn = dummyConn(eofReader, buf); @@ -353,8 +353,8 @@ test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed test("[ws] WebSocket shouldn't throw `Deno.errors.UnexpectedEof` on recive()", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - read(_: Uint8Array): Promise<number | Deno.EOF> { - return Promise.resolve(Deno.EOF); + read(_: Uint8Array): Promise<number | null> { + return Promise.resolve(null); }, }; const conn = dummyConn(eofReader, buf); |