mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Updates to js to clean up default library
This commit is contained in:
parent
1aa7e18ba3
commit
ffb41e61f1
8 changed files with 39 additions and 37 deletions
15
js/blob.ts
15
js/blob.ts
|
@ -1,15 +1,18 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// 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";
|
import { containsOnlyASCII } from "./util";
|
||||||
|
|
||||||
const bytesSymbol = Symbol("bytes");
|
const bytesSymbol = Symbol("bytes");
|
||||||
|
|
||||||
export class DenoBlob implements Blob {
|
export class DenoBlob implements domTypes.Blob {
|
||||||
private readonly [bytesSymbol]: Uint8Array;
|
private readonly [bytesSymbol]: Uint8Array;
|
||||||
readonly size: number = 0;
|
readonly size: number = 0;
|
||||||
readonly type: string = "";
|
readonly type: string = "";
|
||||||
|
|
||||||
constructor(blobParts?: BlobPart[], options?: BlobPropertyBag) {
|
constructor(
|
||||||
|
blobParts?: domTypes.BlobPart[],
|
||||||
|
options?: domTypes.BlobPropertyBag
|
||||||
|
) {
|
||||||
if (arguments.length === 0) {
|
if (arguments.length === 0) {
|
||||||
this[bytesSymbol] = new Uint8Array();
|
this[bytesSymbol] = new Uint8Array();
|
||||||
return;
|
return;
|
||||||
|
@ -53,8 +56,8 @@ export class DenoBlob implements Blob {
|
||||||
}
|
}
|
||||||
|
|
||||||
function processBlobParts(
|
function processBlobParts(
|
||||||
blobParts: BlobPart[],
|
blobParts: domTypes.BlobPart[],
|
||||||
options: BlobPropertyBag
|
options: domTypes.BlobPropertyBag
|
||||||
): Uint8Array {
|
): Uint8Array {
|
||||||
const normalizeLineEndingsToNative = options.ending === "native";
|
const normalizeLineEndingsToNative = options.ending === "native";
|
||||||
// ArrayBuffer.transfer is not yet implemented in V8, so we just have to
|
// ArrayBuffer.transfer is not yet implemented in V8, so we just have to
|
||||||
|
@ -77,7 +80,7 @@ function processBlobParts(
|
||||||
}
|
}
|
||||||
|
|
||||||
function toUint8Arrays(
|
function toUint8Arrays(
|
||||||
blobParts: BlobPart[],
|
blobParts: domTypes.BlobPart[],
|
||||||
doNormalizeLineEndingsToNative: boolean
|
doNormalizeLineEndingsToNative: boolean
|
||||||
): Uint8Array[] {
|
): Uint8Array[] {
|
||||||
const ret: Uint8Array[] = [];
|
const ret: Uint8Array[] = [];
|
||||||
|
|
|
@ -149,6 +149,7 @@ function stringifyWithQuotes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @internal
|
||||||
export function stringifyArgs(
|
export function stringifyArgs(
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
args: any[],
|
args: any[],
|
||||||
|
@ -178,6 +179,7 @@ export function stringifyArgs(
|
||||||
type PrintFunc = (x: string, isErr?: boolean) => void;
|
type PrintFunc = (x: string, isErr?: boolean) => void;
|
||||||
|
|
||||||
export class Console {
|
export class Console {
|
||||||
|
// @internal
|
||||||
constructor(private printFunc: PrintFunc) {}
|
constructor(private printFunc: PrintFunc) {}
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
|
|
18
js/errors.ts
18
js/errors.ts
|
@ -1,25 +1,25 @@
|
||||||
import * as msg from "gen/msg_generated";
|
import { Base, ErrorKind } from "gen/msg_generated";
|
||||||
export { ErrorKind } from "gen/msg_generated";
|
export { ErrorKind } from "gen/msg_generated";
|
||||||
|
|
||||||
// @internal
|
export class DenoError<T extends ErrorKind> extends Error {
|
||||||
export class DenoError<T extends msg.ErrorKind> extends Error {
|
constructor(readonly kind: T, msg: string) {
|
||||||
constructor(readonly kind: T, errStr: string) {
|
super(msg);
|
||||||
super(errStr);
|
this.name = ErrorKind[kind];
|
||||||
this.name = msg.ErrorKind[kind];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export function maybeThrowError(base: msg.Base): void {
|
export function maybeThrowError(base: Base): void {
|
||||||
const err = maybeError(base);
|
const err = maybeError(base);
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
throw err;
|
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();
|
const kind = base.errorKind();
|
||||||
if (kind === msg.ErrorKind.NoError) {
|
if (kind === ErrorKind.NoError) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new DenoError(kind, base.error()!);
|
return new DenoError(kind, base.error()!);
|
||||||
|
|
36
js/fetch.ts
36
js/fetch.ts
|
@ -10,23 +10,15 @@ import {
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { sendAsync } from "./dispatch";
|
import { sendAsync } from "./dispatch";
|
||||||
import * as msg from "gen/msg_generated";
|
import * as msg from "gen/msg_generated";
|
||||||
import {
|
import * as domTypes from "./dom_types";
|
||||||
Headers,
|
|
||||||
Request,
|
|
||||||
Response,
|
|
||||||
Blob,
|
|
||||||
RequestInit,
|
|
||||||
HeadersInit,
|
|
||||||
FormData
|
|
||||||
} from "./dom_types";
|
|
||||||
import { TextDecoder } from "./text_encoding";
|
import { TextDecoder } from "./text_encoding";
|
||||||
import { DenoBlob } from "./blob";
|
import { DenoBlob } from "./blob";
|
||||||
|
|
||||||
// ref: https://fetch.spec.whatwg.org/#dom-headers
|
// 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();
|
private headerMap: Map<string, string> = new Map();
|
||||||
|
|
||||||
constructor(init?: HeadersInit) {
|
constructor(init?: domTypes.HeadersInit) {
|
||||||
if (arguments.length === 0 || init === undefined) {
|
if (arguments.length === 0 || init === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +87,7 @@ export class DenoHeaders implements Headers {
|
||||||
}
|
}
|
||||||
|
|
||||||
forEach(
|
forEach(
|
||||||
callbackfn: (value: string, key: string, parent: Headers) => void,
|
callbackfn: (value: string, key: string, parent: domTypes.Headers) => void,
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
thisArg?: any
|
thisArg?: any
|
||||||
): void {
|
): void {
|
||||||
|
@ -105,7 +97,7 @@ export class DenoHeaders implements Headers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FetchResponse implements Response {
|
class FetchResponse implements domTypes.Response {
|
||||||
readonly url: string = "";
|
readonly url: string = "";
|
||||||
body: null;
|
body: null;
|
||||||
bodyUsed = false; // TODO
|
bodyUsed = false; // TODO
|
||||||
|
@ -113,7 +105,7 @@ class FetchResponse implements Response {
|
||||||
readonly type = "basic"; // TODO
|
readonly type = "basic"; // TODO
|
||||||
redirected = false; // TODO
|
redirected = false; // TODO
|
||||||
headers: DenoHeaders;
|
headers: DenoHeaders;
|
||||||
readonly trailer: Promise<Headers>;
|
readonly trailer: Promise<domTypes.Headers>;
|
||||||
//private bodyChunks: Uint8Array[] = [];
|
//private bodyChunks: Uint8Array[] = [];
|
||||||
private first = true;
|
private first = true;
|
||||||
private bodyWaiter: Resolvable<ArrayBuffer>;
|
private bodyWaiter: Resolvable<ArrayBuffer>;
|
||||||
|
@ -135,16 +127,16 @@ class FetchResponse implements Response {
|
||||||
return this.bodyWaiter;
|
return this.bodyWaiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
async blob(): Promise<Blob> {
|
async blob(): Promise<domTypes.Blob> {
|
||||||
const arrayBuffer = await this.arrayBuffer();
|
const arrayBuffer = await this.arrayBuffer();
|
||||||
return new DenoBlob([arrayBuffer], {
|
return new DenoBlob([arrayBuffer], {
|
||||||
type: this.headers.get("content-type") || ""
|
type: this.headers.get("content-type") || ""
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async formData(): Promise<FormData> {
|
async formData(): Promise<domTypes.FormData> {
|
||||||
notImplemented();
|
notImplemented();
|
||||||
return {} as FormData;
|
return {} as domTypes.FormData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async json(): Promise<object> {
|
async json(): Promise<object> {
|
||||||
|
@ -162,9 +154,9 @@ class FetchResponse implements Response {
|
||||||
return 200 <= this.status && this.status < 300;
|
return 200 <= this.status && this.status < 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): Response {
|
clone(): domTypes.Response {
|
||||||
notImplemented();
|
notImplemented();
|
||||||
return {} as Response;
|
return {} as domTypes.Response;
|
||||||
}
|
}
|
||||||
|
|
||||||
onHeader?: (res: FetchResponse) => void;
|
onHeader?: (res: FetchResponse) => void;
|
||||||
|
@ -187,9 +179,9 @@ class FetchResponse implements Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetch(
|
export async function fetch(
|
||||||
input?: Request | string,
|
input?: domTypes.Request | string,
|
||||||
init?: RequestInit
|
init?: domTypes.RequestInit
|
||||||
): Promise<Response> {
|
): Promise<domTypes.Response> {
|
||||||
const url = input as string;
|
const url = input as string;
|
||||||
log("dispatch FETCH_REQ", url);
|
log("dispatch FETCH_REQ", url);
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ export interface FileInfo {
|
||||||
isSymlink(): boolean;
|
isSymlink(): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @internal
|
||||||
export class FileInfoImpl implements FileInfo {
|
export class FileInfoImpl implements FileInfo {
|
||||||
readonly _isFile: boolean;
|
readonly _isFile: boolean;
|
||||||
readonly _isSymlink: boolean;
|
readonly _isSymlink: boolean;
|
||||||
|
|
2
js/os.ts
2
js/os.ts
|
@ -15,6 +15,7 @@ export function exit(exitCode = 0): never {
|
||||||
return util.unreachable();
|
return util.unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @internal
|
||||||
export function codeFetch(
|
export function codeFetch(
|
||||||
moduleSpecifier: string,
|
moduleSpecifier: string,
|
||||||
containingFile: string
|
containingFile: string
|
||||||
|
@ -44,6 +45,7 @@ export function codeFetch(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @internal
|
||||||
export function codeCache(
|
export function codeCache(
|
||||||
filename: string,
|
filename: string,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
|
|
|
@ -41,6 +41,7 @@ function popStack(): TraceInfo[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push to trace stack if we are tracing
|
// Push to trace stack if we are tracing
|
||||||
|
// @internal
|
||||||
export function maybePushTrace(op: msg.Any, sync: boolean): void {
|
export function maybePushTrace(op: msg.Any, sync: boolean): void {
|
||||||
if (current === null) {
|
if (current === null) {
|
||||||
return; // no trace requested
|
return; // no trace requested
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
export type TypedArray = Uint8Array | Float32Array | Int32Array;
|
export type TypedArray = Uint8Array | Float32Array | Int32Array;
|
||||||
|
|
||||||
|
// @internal
|
||||||
export interface ModuleInfo {
|
export interface ModuleInfo {
|
||||||
moduleName: string | null;
|
moduleName: string | null;
|
||||||
filename: string | null;
|
filename: string | null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue