提交 ffb41e61 编写于 作者: K Kitson Kelly 提交者: Ryan Dahl

Updates to js to clean up default library

上级 1aa7e18b
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { Blob, BlobPart, BlobPropertyBag } from "./dom_types";
import * as domTypes from "./dom_types";
import { containsOnlyASCII } from "./util";
const bytesSymbol = Symbol("bytes");
export class DenoBlob implements Blob {
export class DenoBlob implements domTypes.Blob {
private readonly [bytesSymbol]: Uint8Array;
readonly size: number = 0;
readonly type: string = "";
constructor(blobParts?: BlobPart[], options?: BlobPropertyBag) {
constructor(
blobParts?: domTypes.BlobPart[],
options?: domTypes.BlobPropertyBag
) {
if (arguments.length === 0) {
this[bytesSymbol] = new Uint8Array();
return;
......@@ -53,8 +56,8 @@ export class DenoBlob implements Blob {
}
function processBlobParts(
blobParts: BlobPart[],
options: BlobPropertyBag
blobParts: domTypes.BlobPart[],
options: domTypes.BlobPropertyBag
): Uint8Array {
const normalizeLineEndingsToNative = options.ending === "native";
// ArrayBuffer.transfer is not yet implemented in V8, so we just have to
......@@ -77,7 +80,7 @@ function processBlobParts(
}
function toUint8Arrays(
blobParts: BlobPart[],
blobParts: domTypes.BlobPart[],
doNormalizeLineEndingsToNative: boolean
): Uint8Array[] {
const ret: Uint8Array[] = [];
......
......@@ -149,6 +149,7 @@ function stringifyWithQuotes(
}
}
// @internal
export function stringifyArgs(
// tslint:disable-next-line:no-any
args: any[],
......@@ -178,6 +179,7 @@ export function stringifyArgs(
type PrintFunc = (x: string, isErr?: boolean) => void;
export class Console {
// @internal
constructor(private printFunc: PrintFunc) {}
// tslint:disable-next-line:no-any
......
import * as msg from "gen/msg_generated";
import { Base, ErrorKind } from "gen/msg_generated";
export { ErrorKind } from "gen/msg_generated";
// @internal
export class DenoError<T extends msg.ErrorKind> extends Error {
constructor(readonly kind: T, errStr: string) {
super(errStr);
this.name = msg.ErrorKind[kind];
export class DenoError<T extends ErrorKind> extends Error {
constructor(readonly kind: T, msg: string) {
super(msg);
this.name = ErrorKind[kind];
}
}
// @internal
export function maybeThrowError(base: msg.Base): void {
export function maybeThrowError(base: Base): void {
const err = maybeError(base);
if (err != null) {
throw err;
}
}
export function maybeError(base: msg.Base): null | DenoError<msg.ErrorKind> {
// @internal
export function maybeError(base: Base): null | DenoError<ErrorKind> {
const kind = base.errorKind();
if (kind === msg.ErrorKind.NoError) {
if (kind === ErrorKind.NoError) {
return null;
} else {
return new DenoError(kind, base.error()!);
......
......@@ -10,23 +10,15 @@ import {
import { flatbuffers } from "flatbuffers";
import { sendAsync } from "./dispatch";
import * as msg from "gen/msg_generated";
import {
Headers,
Request,
Response,
Blob,
RequestInit,
HeadersInit,
FormData
} from "./dom_types";
import * as domTypes from "./dom_types";
import { TextDecoder } from "./text_encoding";
import { DenoBlob } from "./blob";
// ref: https://fetch.spec.whatwg.org/#dom-headers
export class DenoHeaders implements Headers {
export class DenoHeaders implements domTypes.Headers {
private headerMap: Map<string, string> = new Map();
constructor(init?: HeadersInit) {
constructor(init?: domTypes.HeadersInit) {
if (arguments.length === 0 || init === undefined) {
return;
}
......@@ -95,7 +87,7 @@ export class DenoHeaders implements Headers {
}
forEach(
callbackfn: (value: string, key: string, parent: Headers) => void,
callbackfn: (value: string, key: string, parent: domTypes.Headers) => void,
// tslint:disable-next-line:no-any
thisArg?: any
): void {
......@@ -105,7 +97,7 @@ export class DenoHeaders implements Headers {
}
}
class FetchResponse implements Response {
class FetchResponse implements domTypes.Response {
readonly url: string = "";
body: null;
bodyUsed = false; // TODO
......@@ -113,7 +105,7 @@ class FetchResponse implements Response {
readonly type = "basic"; // TODO
redirected = false; // TODO
headers: DenoHeaders;
readonly trailer: Promise<Headers>;
readonly trailer: Promise<domTypes.Headers>;
//private bodyChunks: Uint8Array[] = [];
private first = true;
private bodyWaiter: Resolvable<ArrayBuffer>;
......@@ -135,16 +127,16 @@ class FetchResponse implements Response {
return this.bodyWaiter;
}
async blob(): Promise<Blob> {
async blob(): Promise<domTypes.Blob> {
const arrayBuffer = await this.arrayBuffer();
return new DenoBlob([arrayBuffer], {
type: this.headers.get("content-type") || ""
});
}
async formData(): Promise<FormData> {
async formData(): Promise<domTypes.FormData> {
notImplemented();
return {} as FormData;
return {} as domTypes.FormData;
}
async json(): Promise<object> {
......@@ -162,9 +154,9 @@ class FetchResponse implements Response {
return 200 <= this.status && this.status < 300;
}
clone(): Response {
clone(): domTypes.Response {
notImplemented();
return {} as Response;
return {} as domTypes.Response;
}
onHeader?: (res: FetchResponse) => void;
......@@ -187,9 +179,9 @@ class FetchResponse implements Response {
}
export async function fetch(
input?: Request | string,
init?: RequestInit
): Promise<Response> {
input?: domTypes.Request | string,
init?: domTypes.RequestInit
): Promise<domTypes.Response> {
const url = input as string;
log("dispatch FETCH_REQ", url);
......
......@@ -61,6 +61,7 @@ export interface FileInfo {
isSymlink(): boolean;
}
// @internal
export class FileInfoImpl implements FileInfo {
readonly _isFile: boolean;
readonly _isSymlink: boolean;
......
......@@ -15,6 +15,7 @@ export function exit(exitCode = 0): never {
return util.unreachable();
}
// @internal
export function codeFetch(
moduleSpecifier: string,
containingFile: string
......@@ -44,6 +45,7 @@ export function codeFetch(
};
}
// @internal
export function codeCache(
filename: string,
sourceCode: string,
......
......@@ -41,6 +41,7 @@ function popStack(): TraceInfo[] {
}
// Push to trace stack if we are tracing
// @internal
export function maybePushTrace(op: msg.Any, sync: boolean): void {
if (current === null) {
return; // no trace requested
......
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
export type TypedArray = Uint8Array | Float32Array | Int32Array;
// @internal
export interface ModuleInfo {
moduleName: string | null;
filename: string | null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册