0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

Make EOF unique symbol (#3244)

This commit is contained in:
Yoshiya Hinosawa 2019-10-31 23:57:09 +09:00 committed by Ry Dahl
parent 64957d92ef
commit 4f8c936974
3 changed files with 15 additions and 13 deletions

View file

@ -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

View file

@ -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<number | EOF>;
read(p: Uint8Array): Promise<number | Deno.EOF>;
}
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<domTypes.FormData>;
json(): Promise<any>;
text(): Promise<string>;
read(p: Uint8Array): Promise<number | io.EOF>;
read(p: Uint8Array): Promise<number | Deno.EOF>;
close(): void;
cancel(): Promise<void>;
getReader(): domTypes.ReadableStreamReader;

View file

@ -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);