From 4f8c9369744bfa4b1223cec916cb0e5b261831dc Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 31 Oct 2019 23:57:09 +0900 Subject: [PATCH] Make EOF unique symbol (#3244) --- cli/js/io.ts | 7 ++----- cli/js/lib.deno_runtime.d.ts | 12 +++++------- cli/js/tls_test.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cli/js/io.ts b/cli/js/io.ts index 1a7bf8c4c2..15a4ad09ba 100644 --- a/cli/js/io.ts +++ b/cli/js/io.ts @@ -3,11 +3,8 @@ // Documentation liberally lifted from them too. // Thank you! We love Go! -// TODO(kt3k): EOF should be `unique symbol` type. -// That might require some changes of ts_library_builder. -// See #2591 for more details. -export const EOF = null; -export type EOF = null; +export const EOF: unique symbol = Symbol("EOF"); +export type EOF = typeof EOF; // Seek whence values. // https://golang.org/pkg/io/#pkg-constants diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index c0bebf4616..4331319bf5 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -83,8 +83,8 @@ declare namespace Deno { // @url js/io.d.ts - export const EOF: null; - export type EOF = null; + export const EOF: unique symbol; + export type EOF = typeof EOF; export enum SeekMode { SEEK_START = 0, SEEK_CURRENT = 1, @@ -2283,8 +2283,6 @@ declare namespace eventTarget { declare namespace io { // @url js/io.d.ts - export const EOF: null; - export type EOF = null; export enum SeekMode { SEEK_START = 0, SEEK_CURRENT = 1, @@ -2308,10 +2306,10 @@ declare namespace io { * * Implementations must not retain `p`. */ - read(p: Uint8Array): Promise; + read(p: Uint8Array): Promise; } export interface SyncReader { - readSync(p: Uint8Array): number | EOF; + readSync(p: Uint8Array): number | Deno.EOF; } export interface Writer { /** Writes `p.byteLength` bytes from `p` to the underlying data @@ -2387,7 +2385,7 @@ declare namespace fetchTypes { formData(): Promise; json(): Promise; text(): Promise; - read(p: Uint8Array): Promise; + read(p: Uint8Array): Promise; close(): void; cancel(): Promise; getReader(): domTypes.ReadableStreamReader; diff --git a/cli/js/tls_test.ts b/cli/js/tls_test.ts index 58cafd23e7..6966a69112 100644 --- a/cli/js/tls_test.ts +++ b/cli/js/tls_test.ts @@ -184,7 +184,10 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise< await w.flush(); const tpr = new TextProtoReader(r); const statusLine = await tpr.readLine(); - assert(!!statusLine, "line must be read: " + statusLine); + assert(statusLine !== Deno.EOF, `line must be read: ${String(statusLine)}`); + if (statusLine === Deno.EOF) { + return; + } const m = statusLine.match(/^(.+?) (.+?) (.+?)$/); assert(m !== null, "must be matched"); const [_, proto, status, ok] = m; @@ -192,6 +195,10 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise< assertEquals(status, "200"); assertEquals(ok, "OK"); const headers = await tpr.readMIMEHeader(); + assert(headers !== Deno.EOF); + if (headers === Deno.EOF) { + return; + } const contentLength = parseInt(headers.get("content-length")); const bodyBuf = new Uint8Array(contentLength); await r.readFull(bodyBuf);