Update to Prettier 2 and use ES Private Fields (#4498)

This commit is contained in:
Kitson Kelly 2020-03-29 04:03:49 +11:00 committed by GitHub
parent 1397b8e0e7
commit bced52505f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
329 changed files with 2787 additions and 2430 deletions

View File

@ -28,37 +28,37 @@ function copyBytes(dst: Uint8Array, src: Uint8Array, off = 0): number {
}
export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
private buf: Uint8Array; // contents are the bytes buf[off : len(buf)]
private off = 0; // read at buf[off], write at buf[buf.byteLength]
#buf: Uint8Array; // contents are the bytes buf[off : len(buf)]
#off = 0; // read at buf[off], write at buf[buf.byteLength]
constructor(ab?: ArrayBuffer) {
if (ab == null) {
this.buf = new Uint8Array(0);
this.#buf = new Uint8Array(0);
return;
}
this.buf = new Uint8Array(ab);
this.#buf = new Uint8Array(ab);
}
bytes(): Uint8Array {
return this.buf.subarray(this.off);
return this.#buf.subarray(this.#off);
}
toString(): string {
const decoder = new TextDecoder();
return decoder.decode(this.buf.subarray(this.off));
return decoder.decode(this.#buf.subarray(this.#off));
}
empty(): boolean {
return this.buf.byteLength <= this.off;
return this.#buf.byteLength <= this.#off;
}
get length(): number {
return this.buf.byteLength - this.off;
return this.#buf.byteLength - this.#off;
}
get capacity(): number {
return this.buf.buffer.byteLength;
return this.#buf.buffer.byteLength;
}
truncate(n: number): void {
@ -69,27 +69,27 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
if (n < 0 || n > this.length) {
throw Error("bytes.Buffer: truncation out of range");
}
this._reslice(this.off + n);
this.#reslice(this.#off + n);
}
reset(): void {
this._reslice(0);
this.off = 0;
this.#reslice(0);
this.#off = 0;
}
private _tryGrowByReslice(n: number): number {
const l = this.buf.byteLength;
#tryGrowByReslice = (n: number): number => {
const l = this.#buf.byteLength;
if (n <= this.capacity - l) {
this._reslice(l + n);
this.#reslice(l + n);
return l;
}
return -1;
}
};
private _reslice(len: number): void {
assert(len <= this.buf.buffer.byteLength);
this.buf = new Uint8Array(this.buf.buffer, 0, len);
}
#reslice = (len: number): void => {
assert(len <= this.#buf.buffer.byteLength);
this.#buf = new Uint8Array(this.#buf.buffer, 0, len);
};
readSync(p: Uint8Array): number | EOF {
if (this.empty()) {
@ -101,8 +101,8 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
}
return EOF;
}
const nread = copyBytes(p, this.buf.subarray(this.off));
this.off += nread;
const nread = copyBytes(p, this.#buf.subarray(this.#off));
this.#off += nread;
return nread;
}
@ -112,8 +112,8 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
}
writeSync(p: Uint8Array): number {
const m = this._grow(p.byteLength);
return copyBytes(this.buf, p, m);
const m = this.#grow(p.byteLength);
return copyBytes(this.#buf, p, m);
}
write(p: Uint8Array): Promise<number> {
@ -121,14 +121,14 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
return Promise.resolve(n);
}
private _grow(n: number): number {
#grow = (n: number): number => {
const m = this.length;
// If buffer is empty, reset to recover space.
if (m === 0 && this.off !== 0) {
if (m === 0 && this.#off !== 0) {
this.reset();
}
// Fast: Try to grow by means of a reslice.
const i = this._tryGrowByReslice(n);
const i = this.#tryGrowByReslice(n);
if (i >= 0) {
return i;
}
@ -138,41 +138,41 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
// ArrayBuffer. We only need m+n <= c to slide, but
// we instead let capacity get twice as large so we
// don't spend all our time copying.
copyBytes(this.buf, this.buf.subarray(this.off));
copyBytes(this.#buf, this.#buf.subarray(this.#off));
} else if (c > MAX_SIZE - c - n) {
throw new Error("The buffer cannot be grown beyond the maximum size.");
} else {
// Not enough space anywhere, we need to allocate.
const buf = new Uint8Array(2 * c + n);
copyBytes(buf, this.buf.subarray(this.off));
this.buf = buf;
copyBytes(buf, this.#buf.subarray(this.#off));
this.#buf = buf;
}
// Restore this.off and len(this.buf).
this.off = 0;
this._reslice(m + n);
// Restore this.#off and len(this.#buf).
this.#off = 0;
this.#reslice(m + n);
return m;
}
};
grow(n: number): void {
if (n < 0) {
throw Error("Buffer.grow: negative count");
}
const m = this._grow(n);
this._reslice(m);
const m = this.#grow(n);
this.#reslice(m);
}
async readFrom(r: Reader): Promise<number> {
let n = 0;
while (true) {
try {
const i = this._grow(MIN_READ);
this._reslice(i);
const fub = new Uint8Array(this.buf.buffer, i);
const i = this.#grow(MIN_READ);
this.#reslice(i);
const fub = new Uint8Array(this.#buf.buffer, i);
const nread = await r.read(fub);
if (nread === EOF) {
return n;
}
this._reslice(i + nread);
this.#reslice(i + nread);
n += nread;
} catch (e) {
return n;
@ -184,14 +184,14 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
let n = 0;
while (true) {
try {
const i = this._grow(MIN_READ);
this._reslice(i);
const fub = new Uint8Array(this.buf.buffer, i);
const i = this.#grow(MIN_READ);
this.#reslice(i);
const fub = new Uint8Array(this.#buf.buffer, i);
const nread = r.readSync(fub);
if (nread === EOF) {
return n;
}
this._reslice(i + nread);
this.#reslice(i + nread);
n += nread;
} catch (e) {
return n;

View File

@ -13,7 +13,7 @@ export interface BuildInfo {
export const build: BuildInfo = {
arch: "" as Arch,
os: "" as OperatingSystem
os: "" as OperatingSystem,
};
export function setBuildInfo(os: OperatingSystem, arch: Arch): void {

View File

@ -17,7 +17,7 @@ function code(open: number, close: number): Code {
return {
open: `\x1b[${open}m`,
close: `\x1b[${close}m`,
regexp: new RegExp(`\\x1b\\[${close}m`, "g")
regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
};
}

View File

@ -21,12 +21,12 @@ import {
defaultBundlerOptions,
defaultRuntimeCompileOptions,
defaultTranspileOptions,
Host
Host,
} from "./compiler/host.ts";
import {
processImports,
processLocalImports,
resolveModules
resolveModules,
} from "./compiler/imports.ts";
import {
createWriteFile,
@ -35,7 +35,7 @@ import {
ignoredDiagnostics,
WriteFileState,
processConfigureResponse,
base64ToUint8Array
base64ToUint8Array,
} from "./compiler/util.ts";
import { Diagnostic, DiagnosticItem } from "./diagnostics.ts";
import { fromTypeScriptDiagnostic } from "./diagnostics_util.ts";
@ -93,7 +93,7 @@ async function compile(
const { bundle, config, configPath, outFile, rootNames, target } = request;
util.log(">>> compile start", {
rootNames,
type: CompilerRequestType[request.type]
type: CompilerRequestType[request.type],
});
// When a programme is emitted, TypeScript will call `writeFile` with
@ -108,14 +108,14 @@ async function compile(
bundle,
host: undefined,
outFile,
rootNames
rootNames,
};
const writeFile = createWriteFile(state);
const host = (state.host = new Host({
bundle,
target,
writeFile
writeFile,
}));
let diagnostics: readonly ts.Diagnostic[] | undefined;
@ -129,7 +129,7 @@ async function compile(
// requesting those from the privileged side, populating the in memory
// cache which will be used by the host, before resolving.
const resolvedRootModules = await processImports(
rootNames.map(rootName => [rootName, rootName]),
rootNames.map((rootName) => [rootName, rootName]),
undefined,
bundle || host.getCompilationSettings().checkJs
);
@ -143,7 +143,7 @@ async function compile(
rootNames,
options,
host,
oldProgram: TS_SNAPSHOT_PROGRAM
oldProgram: TS_SNAPSHOT_PROGRAM,
});
diagnostics = ts
@ -171,12 +171,12 @@ async function compile(
emitSkipped,
diagnostics: diagnostics.length
? fromTypeScriptDiagnostic(diagnostics)
: undefined
: undefined,
};
util.log("<<< compile end", {
rootNames,
type: CompilerRequestType[request.type]
type: CompilerRequestType[request.type],
});
return result;
@ -190,7 +190,7 @@ async function runtimeCompile(
util.log(">>> runtime compile start", {
rootName,
bundle,
sources: sources ? Object.keys(sources) : undefined
sources: sources ? Object.keys(sources) : undefined,
});
// resolve the root name, if there are sources, the root name does not
@ -232,7 +232,7 @@ async function runtimeCompile(
const resolvedNames = resolveModules(additionalFiles);
rootNames.push(
...(await processImports(
resolvedNames.map(rn => [rn, rn]),
resolvedNames.map((rn) => [rn, rn]),
undefined,
checkJsImports
))
@ -246,14 +246,14 @@ async function runtimeCompile(
rootNames,
sources,
emitMap: {},
emitBundle: undefined
emitBundle: undefined,
};
const writeFile = createWriteFile(state);
const host = (state.host = new Host({
bundle,
target,
writeFile
writeFile,
}));
const compilerOptions = [defaultRuntimeCompileOptions];
if (convertedOptions) {
@ -268,7 +268,7 @@ async function runtimeCompile(
rootNames,
options: host.getCompilationSettings(),
host,
oldProgram: TS_SNAPSHOT_PROGRAM
oldProgram: TS_SNAPSHOT_PROGRAM,
});
if (bundle) {
@ -288,7 +288,7 @@ async function runtimeCompile(
rootName,
sources: sources ? Object.keys(sources) : undefined,
bundle,
emitMap: Object.keys(state.emitMap)
emitMap: Object.keys(state.emitMap),
});
const maybeDiagnostics = diagnostics.length
@ -320,7 +320,7 @@ function runtimeTranspile(
inputText,
{
fileName,
compilerOptions
compilerOptions,
}
);
result[fileName] = { source, map };
@ -329,7 +329,7 @@ function runtimeTranspile(
}
async function tsCompilerOnMessage({
data: request
data: request,
}: {
data: CompilerRequest;
}): Promise<void> {
@ -364,7 +364,7 @@ async function tsCompilerOnMessage({
}
async function wasmCompilerOnMessage({
data: binary
data: binary,
}: {
data: string;
}): Promise<void> {
@ -411,12 +411,12 @@ Object.defineProperties(globalThis, {
value: bootstrapWasmCompilerRuntime,
enumerable: false,
writable: false,
configurable: false
configurable: false,
},
bootstrapTsCompilerRuntime: {
value: bootstrapTsCompilerRuntime,
enumerable: false,
writable: false,
configurable: false
}
configurable: false,
},
});

View File

@ -157,7 +157,7 @@ export async function transpileOnly(
util.log("Deno.transpileOnly", { sources: Object.keys(sources), options });
const payload = {
sources,
options: JSON.stringify(options)
options: JSON.stringify(options),
};
const result = await runtimeCompilerOps.transpile(payload);
return JSON.parse(result);
@ -172,12 +172,12 @@ export async function compile(
rootName: sources ? rootName : checkRelative(rootName),
sources,
options: JSON.stringify(options),
bundle: false
bundle: false,
};
util.log("Deno.compile", {
rootName: payload.rootName,
sources: !!sources,
options
options,
});
const result = await runtimeCompilerOps.compile(payload);
return JSON.parse(result);
@ -192,12 +192,12 @@ export async function bundle(
rootName: sources ? rootName : checkRelative(rootName),
sources,
options: JSON.stringify(options),
bundle: true
bundle: true,
};
util.log("Deno.bundle", {
rootName: payload.rootName,
sources: !!sources,
options
options,
});
const result = await runtimeCompilerOps.compile(payload);
return JSON.parse(result);

View File

@ -9,7 +9,7 @@ import { getAsset } from "./util.ts";
// load all type definitions and snapshot them.
const host = new Host({
target: CompilerHostTarget.Main,
writeFile(): void {}
writeFile(): void {},
});
const options = host.getCompilationSettings();
@ -34,7 +34,7 @@ host.getSourceFile(
export const TS_SNAPSHOT_PROGRAM = ts.createProgram({
rootNames: [`${ASSETS}/bootstrap.ts`],
options,
host
host,
});
export const SYSTEM_LOADER = getAsset("system_loader.js");

View File

@ -14,7 +14,7 @@ function normalizeUrl(rootName: string): string {
path,
false,
"/",
code => code === CHAR_FORWARD_SLASH
(code) => code === CHAR_FORWARD_SLASH
)}`;
} else {
return rootName;
@ -29,7 +29,7 @@ export function buildBundle(
// when outputting to AMD and a single outfile, TypeScript makes up the module
// specifiers which are used to define the modules, and doesn't expose them
// publicly, so we have to try to replicate
const sources = sourceFiles.map(sf => sf.fileName);
const sources = sourceFiles.map((sf) => sf.fileName);
const sharedPath = commonPath(sources);
rootName = normalizeUrl(rootName)
.replace(sharedPath, "")
@ -79,7 +79,7 @@ export function setRootExports(program: ts.Program, rootModule: string): void {
// that when there isn't. There appears to be no clean way of figuring that
// out, so inspecting SymbolFlags that might be present that are type only
.filter(
sym =>
(sym) =>
sym.flags & ts.SymbolFlags.Class ||
!(
sym.flags & ts.SymbolFlags.Interface ||
@ -94,5 +94,5 @@ export function setRootExports(program: ts.Program, rootModule: string): void {
sym.flags & ts.SymbolFlags.TypeAliasExcludes
)
)
.map(sym => sym.getName());
.map((sym) => sym.getName());
}

View File

@ -9,7 +9,7 @@ import * as util from "../util.ts";
export enum CompilerHostTarget {
Main = "main",
Runtime = "runtime",
Worker = "worker"
Worker = "worker",
}
export interface CompilerHostOptions {
@ -32,7 +32,7 @@ export const defaultBundlerOptions: ts.CompilerOptions = {
outDir: undefined,
outFile: `${OUT_DIR}/bundle.js`,
// disabled until we have effective way to modify source maps
sourceMap: false
sourceMap: false,
};
export const defaultCompileOptions: ts.CompilerOptions = {
@ -47,11 +47,11 @@ export const defaultCompileOptions: ts.CompilerOptions = {
sourceMap: true,
strict: true,
stripComments: true,
target: ts.ScriptTarget.ESNext
target: ts.ScriptTarget.ESNext,
};
export const defaultRuntimeCompileOptions: ts.CompilerOptions = {
outDir: undefined
outDir: undefined,
};
export const defaultTranspileOptions: ts.CompilerOptions = {
@ -59,7 +59,7 @@ export const defaultTranspileOptions: ts.CompilerOptions = {
module: ts.ModuleKind.ESNext,
sourceMap: true,
scriptComments: true,
target: ts.ScriptTarget.ESNext
target: ts.ScriptTarget.ESNext,
};
const ignoredCompilerOptions: readonly string[] = [
@ -117,43 +117,41 @@ const ignoredCompilerOptions: readonly string[] = [
"types",
"typeRoots",
"version",
"watch"
"watch",
];
export class Host implements ts.CompilerHost {
private readonly _options = defaultCompileOptions;
private _target: CompilerHostTarget;
private _writeFile: WriteFileCallback;
private _getAsset(filename: string): SourceFile {
const lastSegment = filename.split("/").pop()!;
const url = ts.libMap.has(lastSegment)
? ts.libMap.get(lastSegment)!
: lastSegment;
const sourceFile = SourceFile.get(url);
if (sourceFile) {
return sourceFile;
}
const name = url.includes(".") ? url : `${url}.d.ts`;
const sourceCode = getAsset(name);
return new SourceFile({
url,
filename: `${ASSETS}/${name}`,
mediaType: MediaType.TypeScript,
sourceCode
});
function getAssetInternal(filename: string): SourceFile {
const lastSegment = filename.split("/").pop()!;
const url = ts.libMap.has(lastSegment)
? ts.libMap.get(lastSegment)!
: lastSegment;
const sourceFile = SourceFile.get(url);
if (sourceFile) {
return sourceFile;
}
const name = url.includes(".") ? url : `${url}.d.ts`;
const sourceCode = getAsset(name);
return new SourceFile({
url,
filename: `${ASSETS}/${name}`,
mediaType: MediaType.TypeScript,
sourceCode,
});
}
export class Host implements ts.CompilerHost {
readonly #options = defaultCompileOptions;
#target: CompilerHostTarget;
#writeFile: WriteFileCallback;
/* Deno specific APIs */
constructor({ bundle = false, target, writeFile }: CompilerHostOptions) {
this._target = target;
this._writeFile = writeFile;
this.#target = target;
this.#writeFile = writeFile;
if (bundle) {
// options we need to change when we are generating a bundle
Object.assign(this._options, defaultBundlerOptions);
Object.assign(this.#options, defaultBundlerOptions);
}
}
@ -175,22 +173,22 @@ export class Host implements ts.CompilerHost {
for (const key of Object.keys(options)) {
if (
ignoredCompilerOptions.includes(key) &&
(!(key in this._options) || options[key] !== this._options[key])
(!(key in this.#options) || options[key] !== this.#options[key])
) {
ignoredOptions.push(key);
delete options[key];
}
}
Object.assign(this._options, options);
Object.assign(this.#options, options);
return {
ignoredOptions: ignoredOptions.length ? ignoredOptions : undefined,
diagnostics: errors.length ? errors : undefined
diagnostics: errors.length ? errors : undefined,
};
}
mergeOptions(...options: ts.CompilerOptions[]): ts.CompilerOptions {
Object.assign(this._options, ...options);
return Object.assign({}, this._options);
Object.assign(this.#options, ...options);
return Object.assign({}, this.#options);
}
/* TypeScript CompilerHost APIs */
@ -205,7 +203,7 @@ export class Host implements ts.CompilerHost {
getCompilationSettings(): ts.CompilerOptions {
util.log("compiler::host.getCompilationSettings()");
return this._options;
return this.#options;
}
getCurrentDirectory(): string {
@ -214,7 +212,7 @@ export class Host implements ts.CompilerHost {
getDefaultLibFileName(_options: ts.CompilerOptions): string {
util.log("compiler::host.getDefaultLibFileName()");
switch (this._target) {
switch (this.#target) {
case CompilerHostTarget.Main:
case CompilerHostTarget.Runtime:
return `${ASSETS}/lib.deno.window.d.ts`;
@ -237,7 +235,7 @@ export class Host implements ts.CompilerHost {
try {
assert(!shouldCreateNewSourceFile);
const sourceFile = fileName.startsWith(ASSETS)
? this._getAsset(fileName)
? getAssetInternal(fileName)
: SourceFile.get(fileName);
assert(sourceFile != null);
if (!sourceFile.tsSourceFile) {
@ -278,12 +276,12 @@ export class Host implements ts.CompilerHost {
): Array<ts.ResolvedModuleFull | undefined> {
util.log("compiler::host.resolveModuleNames", {
moduleNames,
containingFile
containingFile,
});
return moduleNames.map(specifier => {
return moduleNames.map((specifier) => {
const url = SourceFile.getUrl(specifier, containingFile);
const sourceFile = specifier.startsWith(ASSETS)
? this._getAsset(specifier)
? getAssetInternal(specifier)
: url
? SourceFile.get(url)
: undefined;
@ -293,7 +291,7 @@ export class Host implements ts.CompilerHost {
return {
resolvedFileName: sourceFile.url,
isExternalLibraryImport: specifier.startsWith(ASSETS),
extension: sourceFile.extension
extension: sourceFile.extension,
};
});
}
@ -310,6 +308,6 @@ export class Host implements ts.CompilerHost {
sourceFiles?: readonly ts.SourceFile[]
): void {
util.log("compiler::host.writeFile", fileName);
this._writeFile(fileName, data, sourceFiles);
this.#writeFile(fileName, data, sourceFiles);
}
}

View File

@ -34,7 +34,7 @@ function resolvePath(...pathSegments: string[]): string {
resolvedPath,
!resolvedAbsolute,
"/",
code => code === CHAR_FORWARD_SLASH
(code) => code === CHAR_FORWARD_SLASH
);
if (resolvedAbsolute) {
@ -120,7 +120,7 @@ export function processLocalImports(
url: moduleName,
filename: moduleName,
sourceCode: sources[moduleName],
mediaType: getMediaType(moduleName)
mediaType: getMediaType(moduleName),
});
sourceFile.cache(specifiers[i][0], referrer);
if (!sourceFile.processed) {

View File

@ -12,7 +12,7 @@ export enum MediaType {
TSX = 3,
Json = 4,
Wasm = 5,
Unknown = 6
Unknown = 6,
}
export interface SourceFileJson {
@ -50,6 +50,11 @@ function getExtension(fileName: string, mediaType: MediaType): ts.Extension {
}
}
/** A global cache of module source files that have been loaded. */
const moduleCache: Map<string, SourceFile> = new Map();
/** A map of maps which cache source files for quicker modules resolution. */
const specifierCache: Map<string, Map<string, SourceFile>> = new Map();
export class SourceFile {
extension!: ts.Extension;
filename!: string;
@ -63,20 +68,20 @@ export class SourceFile {
url!: string;
constructor(json: SourceFileJson) {
if (SourceFile._moduleCache.has(json.url)) {
if (moduleCache.has(json.url)) {
throw new TypeError("SourceFile already exists");
}
Object.assign(this, json);
this.extension = getExtension(this.url, this.mediaType);
SourceFile._moduleCache.set(this.url, this);
moduleCache.set(this.url, this);
}
cache(moduleSpecifier: string, containingFile?: string): void {
containingFile = containingFile || "";
let innerCache = SourceFile._specifierCache.get(containingFile);
let innerCache = specifierCache.get(containingFile);
if (!innerCache) {
innerCache = new Map();
SourceFile._specifierCache.set(containingFile, innerCache);
specifierCache.set(containingFile, innerCache);
}
innerCache.set(moduleSpecifier, this);
}
@ -112,14 +117,14 @@ export class SourceFile {
importedFiles,
referencedFiles,
libReferenceDirectives,
typeReferenceDirectives
typeReferenceDirectives,
} = preProcessedFileInfo;
const typeDirectives = parseTypeDirectives(this.sourceCode);
if (typeDirectives) {
for (const importedFile of importedFiles) {
files.push([
importedFile.fileName,
getMappedModuleName(importedFile, typeDirectives)
getMappedModuleName(importedFile, typeDirectives),
]);
}
} else if (
@ -145,18 +150,11 @@ export class SourceFile {
return files;
}
private static _moduleCache: Map<string, SourceFile> = new Map();
private static _specifierCache: Map<
string,
Map<string, SourceFile>
> = new Map();
static getUrl(
moduleSpecifier: string,
containingFile: string
): string | undefined {
const containingCache = this._specifierCache.get(containingFile);
const containingCache = specifierCache.get(containingFile);
if (containingCache) {
const sourceFile = containingCache.get(moduleSpecifier);
return sourceFile && sourceFile.url;
@ -165,10 +163,10 @@ export class SourceFile {
}
static get(url: string): SourceFile | undefined {
return this._moduleCache.get(url);
return moduleCache.get(url);
}
static has(url: string): boolean {
return this._moduleCache.has(url);
return moduleCache.has(url);
}
}

View File

@ -39,7 +39,7 @@ export function parseTypeDirectives(
directives.push({
fileName,
pos,
end: pos + matchString.length
end: pos + matchString.length,
});
}
if (!directives.length) {
@ -60,7 +60,7 @@ export function parseTypeDirectives(
const target: FileReference = {
fileName: targetFileName,
pos: targetPos,
end: targetPos + targetFileName.length
end: targetPos + targetFileName.length,
};
results.set(target, fileName);
}

View File

@ -33,7 +33,7 @@ export interface WriteFileState {
export enum CompilerRequestType {
Compile = 0,
RuntimeCompile = 1,
RuntimeTranspile = 2
RuntimeTranspile = 2,
}
export const OUT_DIR = "$deno$";
@ -255,7 +255,7 @@ export function convertCompilerOptions(
}
return {
options: out as ts.CompilerOptions,
files: files.length ? files : undefined
files: files.length ? files : undefined,
};
}
@ -287,7 +287,7 @@ export const ignoredDiagnostics = [
// TS7016: Could not find a declaration file for module '...'. '...'
// implicitly has an 'any' type. This is due to `allowJs` being off by
// default but importing of a JavaScript module.
7016
7016,
];
export function processConfigureResponse(

View File

@ -6,7 +6,7 @@ export {
readAll,
readAllSync,
writeAll,
writeAllSync
writeAllSync,
} from "./buffer.ts";
export { build, OperatingSystem, Arch } from "./build.ts";
export { chmodSync, chmod } from "./ops/fs/chmod.ts";
@ -18,7 +18,7 @@ export {
Diagnostic,
DiagnosticCategory,
DiagnosticItem,
DiagnosticMessageChain
DiagnosticMessageChain,
} from "./diagnostics.ts";
export { chdir, cwd } from "./ops/fs/dir.ts";
export { applySourceMap, formatDiagnostics } from "./ops/errors.ts";
@ -36,7 +36,7 @@ export {
seek,
seekSync,
OpenOptions,
OpenMode
OpenMode,
} from "./files.ts";
export { read, readSync, write, writeSync } from "./ops/io.ts";
export { FsEvent, fsEvents } from "./ops/fs_events.ts";
@ -57,7 +57,7 @@ export {
ReadSeeker,
WriteSeeker,
ReadWriteCloser,
ReadWriteSeeker
ReadWriteSeeker,
} from "./io.ts";
export { linkSync, link } from "./ops/fs/link.ts";
export {
@ -65,7 +65,7 @@ export {
makeTempDir,
makeTempFileSync,
makeTempFile,
MakeTempOptions
MakeTempOptions,
} from "./ops/fs/make_temp.ts";
export { metrics, Metrics } from "./ops/runtime.ts";
export { mkdirSync, mkdir, MkdirOptions } from "./ops/fs/mkdir.ts";
@ -76,7 +76,7 @@ export {
Listener,
Conn,
ShutdownMode,
shutdown
shutdown,
} from "./net.ts";
export {
dir,
@ -85,14 +85,14 @@ export {
execPath,
hostname,
loadavg,
osRelease
osRelease,
} from "./ops/os.ts";
export {
permissions,
PermissionName,
PermissionState,
PermissionStatus,
Permissions
Permissions,
} from "./permissions.ts";
export { openPlugin } from "./plugins.ts";
export { kill } from "./ops/process.ts";

View File

@ -10,7 +10,7 @@ export enum DiagnosticCategory {
Info = 2,
Error = 3,
Warning = 4,
Suggestion = 5
Suggestion = 5,
}
export interface DiagnosticMessageChain {

View File

@ -7,7 +7,7 @@ import {
Diagnostic,
DiagnosticCategory,
DiagnosticMessageChain,
DiagnosticItem
DiagnosticItem,
} from "./diagnostics.ts";
interface SourceInformation {
@ -45,7 +45,7 @@ function getSourceInformation(
const scriptResourceName = sourceFile.fileName;
const {
line: lineNumber,
character: startColumn
character: startColumn,
} = sourceFile.getLineAndCharacterOfPosition(start);
const endPosition = sourceFile.getLineAndCharacterOfPosition(start + length);
const endColumn =
@ -67,7 +67,7 @@ function getSourceInformation(
lineNumber,
scriptResourceName,
startColumn,
endColumn
endColumn,
};
}
@ -83,7 +83,7 @@ function fromDiagnosticMessageChain(
message,
code,
category: fromDiagnosticCategory(category),
next: fromDiagnosticMessageChain(next)
next: fromDiagnosticMessageChain(next),
};
});
}
@ -97,7 +97,7 @@ function parseDiagnostic(
code,
file,
start: startPosition,
length
length,
} = item;
const sourceInfo =
file && startPosition && length
@ -122,7 +122,7 @@ function parseDiagnostic(
code,
category,
startPosition,
endPosition
endPosition,
};
return sourceInfo ? { ...base, ...sourceInfo } : base;

View File

@ -54,7 +54,7 @@ function patchCallSite(callSite: CallSite, location: Location): CallSite {
},
getPromiseIndex(): number | null {
return callSite.getPromiseIndex();
}
},
};
}
@ -181,7 +181,7 @@ function prepareStackTrace(
applySourceMap({
filename,
line,
column
column,
})
);
}

View File

@ -22,7 +22,7 @@ export enum ErrorKind {
Http = 19,
URIError = 20,
TypeError = 21,
Other = 22
Other = 22,
}
export function getErrorClass(kind: ErrorKind): { new (msg: string): Error } {
@ -190,5 +190,5 @@ export const errors = {
WriteZero: WriteZero,
UnexpectedEof: UnexpectedEof,
BadResource: BadResource,
Http: Http
Http: Http,
};

View File

@ -24,8 +24,8 @@ export interface FileInfo {
// @internal
export class FileInfoImpl implements FileInfo {
private readonly _isFile: boolean;
private readonly _isSymlink: boolean;
readonly #isFile: boolean;
readonly #isSymlink: boolean;
size: number;
modified: number | null;
accessed: number | null;
@ -43,28 +43,18 @@ export class FileInfoImpl implements FileInfo {
blocks: number | null;
/* @internal */
constructor(private _res: StatResponse) {
constructor(res: StatResponse) {
const isUnix = build.os === "mac" || build.os === "linux";
const modified = this._res.modified;
const accessed = this._res.accessed;
const created = this._res.created;
const name = this._res.name;
const modified = res.modified;
const accessed = res.accessed;
const created = res.created;
const name = res.name;
// Unix only
const {
dev,
ino,
mode,
nlink,
uid,
gid,
rdev,
blksize,
blocks
} = this._res;
const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res;
this._isFile = this._res.isFile;
this._isSymlink = this._res.isSymlink;
this.size = this._res.size;
this.#isFile = res.isFile;
this.#isSymlink = res.isSymlink;
this.size = res.size;
this.modified = modified ? modified : null;
this.accessed = accessed ? accessed : null;
this.created = created ? created : null;
@ -82,14 +72,14 @@ export class FileInfoImpl implements FileInfo {
}
isFile(): boolean {
return this._isFile;
return this.#isFile;
}
isDirectory(): boolean {
return !this._isFile && !this._isSymlink;
return !this.#isFile && !this.#isSymlink;
}
isSymlink(): boolean {
return this._isSymlink;
return this.#isSymlink;
}
}

View File

@ -8,7 +8,7 @@ import {
SeekMode,
SyncReader,
SyncWriter,
SyncSeeker
SyncSeeker,
} from "./io.ts";
import { close } from "./ops/resources.ts";
import { read, readSync, write, writeSync } from "./ops/io.ts";
@ -18,7 +18,7 @@ import {
open as opOpen,
openSync as opOpenSync,
OpenOptions,
OpenMode
OpenMode,
} from "./ops/fs/open.ts";
export { OpenOptions, OpenMode } from "./ops/fs/open.ts";
@ -119,7 +119,7 @@ export const stdout = new File(1);
export const stderr = new File(2);
function checkOpenOptions(options: OpenOptions): void {
if (Object.values(options).filter(val => val === true).length === 0) {
if (Object.values(options).filter((val) => val === true).length === 0) {
throw new Error("OpenOptions requires at least one option to be true");
}

View File

@ -160,7 +160,7 @@ export function writable(value: unknown): PropertyDescriptor {
value,
writable: true,
enumerable: true,
configurable: true
configurable: true,
};
}
@ -168,14 +168,14 @@ export function nonEnumerable(value: unknown): PropertyDescriptor {
return {
value,
writable: true,
configurable: true
configurable: true,
};
}
export function readOnly(value: unknown): PropertyDescriptor {
return {
value,
enumerable: true
enumerable: true,
};
}
@ -183,7 +183,7 @@ export function readOnly(value: unknown): PropertyDescriptor {
export function getterOnly(getter: () => any): PropertyDescriptor {
return {
get: getter,
enumerable: true
enumerable: true,
};
}
@ -196,7 +196,7 @@ export const windowOrWorkerGlobalScopeMethods = {
fetch: writable(fetchTypes.fetch),
// queueMicrotask is bound in Rust
setInterval: writable(timers.setInterval),
setTimeout: writable(timers.setTimeout)
setTimeout: writable(timers.setTimeout),
};
// Other properties shared between WindowScope and WorkerGlobalScope
@ -216,7 +216,7 @@ export const windowOrWorkerGlobalScopeProperties = {
Request: nonEnumerable(request.Request),
Response: nonEnumerable(fetchTypes.Response),
performance: writable(new performanceUtil.Performance()),
Worker: nonEnumerable(workers.WorkerImpl)
Worker: nonEnumerable(workers.WorkerImpl),
};
export const eventTargetProperties = {
@ -233,5 +233,5 @@ export const eventTargetProperties = {
dispatchEvent: readOnly(eventTarget.EventTarget.prototype.dispatchEvent),
removeEventListener: readOnly(
eventTarget.EventTarget.prototype.removeEventListener
)
),
};

View File

@ -11,6 +11,6 @@ export const internalObject: { [key: string]: any } = {};
export function exposeForTest(name: string, value: any): void {
Object.defineProperty(internalObject, name, {
value,
enumerable: false
enumerable: false,
});
}

View File

@ -11,7 +11,7 @@ export type EOF = typeof EOF;
export enum SeekMode {
SEEK_START = 0,
SEEK_CURRENT = 1,
SEEK_END = 2
SEEK_END = 2,
}
// Reader is the interface that wraps the basic read() method.
@ -99,8 +99,8 @@ export function toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array> {
return {
value: b.subarray(0, result),
done: false
done: false,
};
}
},
};
}

View File

@ -38,7 +38,7 @@ declare namespace Deno {
enum TestStatus {
Passed = "passed",
Failed = "failed",
Ignored = "ignored"
Ignored = "ignored",
}
interface TestResult {
@ -60,7 +60,7 @@ declare namespace Deno {
Start = "start",
TestStart = "testStart",
TestEnd = "testEnd",
End = "end"
End = "end",
}
interface TestEventStart {
@ -402,7 +402,7 @@ declare namespace Deno {
export enum SeekMode {
SEEK_START = 0,
SEEK_CURRENT = 1,
SEEK_END = 2
SEEK_END = 2,
}
/** **UNSTABLE**: might make `Reader` into iterator of some sort. */
@ -766,12 +766,6 @@ declare namespace Deno {
*
* Based on [Go Buffer](https://golang.org/pkg/bytes/#Buffer). */
export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
private buf;
private off;
private _tryGrowByReslice;
private _reslice;
private _grow;
constructor(ab?: ArrayBuffer);
/** Returns a slice holding the unread portion of the buffer.
*
@ -1603,7 +1597,7 @@ declare namespace Deno {
export enum ShutdownMode {
Read = 0,
Write,
ReadWrite // TODO(ry) panics on ReadWrite.
ReadWrite, // TODO(ry) panics on ReadWrite.
}
/** **UNSTABLE**: Maybe should remove `how` parameter maybe remove
@ -1998,7 +1992,7 @@ declare namespace Deno {
SIGWINCH = 28,
SIGIO = 29,
SIGPWR = 30,
SIGSYS = 31
SIGSYS = 31,
}
enum MacOSSignal {
SIGHUP = 1,
@ -2031,7 +2025,7 @@ declare namespace Deno {
SIGWINCH = 28,
SIGINFO = 29,
SIGUSR1 = 30,
SIGUSR2 = 31
SIGUSR2 = 31,
}
/** **UNSTABLE**: make platform independent.
@ -2108,7 +2102,7 @@ declare namespace Deno {
Info = 2,
Error = 3,
Warning = 4,
Suggestion = 5
Suggestion = 5,
}
export interface DiagnosticMessageChain {

View File

@ -339,12 +339,8 @@ declare namespace __domTypes {
export enum NodeType {
ELEMENT_NODE = 1,
TEXT_NODE = 3,
DOCUMENT_FRAGMENT_NODE = 11
DOCUMENT_FRAGMENT_NODE = 11,
}
export const eventTargetHost: unique symbol;
export const eventTargetListeners: unique symbol;
export const eventTargetMode: unique symbol;
export const eventTargetNodeType: unique symbol;
export interface EventListener {
(evt: Event): void | Promise<void>;
}
@ -358,11 +354,11 @@ declare namespace __domTypes {
callback: EventListenerOrEventListenerObject;
options: AddEventListenerOptions;
}
export const eventTargetHost: unique symbol;
export const eventTargetListeners: unique symbol;
export const eventTargetMode: unique symbol;
export const eventTargetNodeType: unique symbol;
export interface EventTarget {
[eventTargetHost]: EventTarget | null;
[eventTargetListeners]: { [type in string]: EventListener[] };
[eventTargetMode]: string;
[eventTargetNodeType]: NodeType;
addEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
@ -438,7 +434,7 @@ declare namespace __domTypes {
NONE = 0,
CAPTURING_PHASE = 1,
AT_TARGET = 2,
BUBBLING_PHASE = 3
BUBBLING_PHASE = 3,
}
export interface EventPath {
item: EventTarget;
@ -532,17 +528,79 @@ declare namespace __domTypes {
options?: boolean | EventListenerOptions
): void;
}
export interface ReadableStream {
readonly locked: boolean;
cancel(): Promise<void>;
getReader(): ReadableStreamReader;
tee(): [ReadableStream, ReadableStream];
export interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}
export interface ReadableStreamReader {
cancel(): Promise<void>;
read(): Promise<any>;
export interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
}
export type ReadableStreamReadResult<T> =
| ReadableStreamReadValueResult<T>
| ReadableStreamReadDoneResult<T>;
export interface ReadableStreamDefaultReader<R = any> {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void;
}
export interface PipeOptions {
preventAbort?: boolean;
preventCancel?: boolean;
preventClose?: boolean;
signal?: AbortSignal;
}
/** This Streams API interface represents a readable stream of byte data. The
* Fetch API offers a concrete instance of a ReadableStream through the body
* property of a Response object. */
export interface ReadableStream<R = any> {
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
getReader(): ReadableStreamDefaultReader<R>;
/* disabled for now
pipeThrough<T>(
{
writable,
readable
}: {
writable: WritableStream<R>;
readable: ReadableStream<T>;
},
options?: PipeOptions
): ReadableStream<T>;
pipeTo(dest: WritableStream<R>, options?: PipeOptions): Promise<void>;
*/
tee(): [ReadableStream<R>, ReadableStream<R>];
}
export interface ReadableStreamReader<R = any> {
cancel(reason: any): Promise<void>;
read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void;
}
export interface ReadableStreamBYOBReader {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
read<T extends ArrayBufferView>(
view: T
): Promise<ReadableStreamReadResult<T>>;
releaseLock(): void;
}
export interface WritableStream<W = any> {
readonly locked: boolean;
abort(reason?: any): Promise<void>;
getWriter(): WritableStreamDefaultWriter<W>;
}
export interface WritableStreamDefaultWriter<W = any> {
readonly closed: Promise<void>;
readonly desiredSize: number | null;
readonly ready: Promise<void>;
abort(reason?: any): Promise<void>;
close(): Promise<void>;
releaseLock(): void;
write(chunk: W): Promise<void>;
}
export interface FormData extends DomIterable<string, FormDataEntryValue> {
append(name: string, value: string | Blob, fileName?: string): void;
delete(name: string): void;
@ -570,7 +628,7 @@ declare namespace __domTypes {
}
export interface Body {
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body: ReadableStream | null;
readonly body: ReadableStream<Uint8Array> | null;
/** Stores a `Boolean` that declares whether the body has been used in a
* response yet.
*/
@ -799,58 +857,63 @@ declare namespace __domTypes {
/** Creates a clone of a `Response` object. */
clone(): Response;
}
export interface DOMStringList {
/** Returns the number of strings in strings. */
readonly length: number;
/** Returns true if strings contains string, and false otherwise. */
contains(string: string): boolean;
/** Returns the string with index index from strings. */
item(index: number): string | null;
[index: number]: string;
}
/** The location (URL) of the object it is linked to. Changes done on it are
* reflected on the object it relates to. Both the Document and Window
* interface have such a linked Location, accessible via Document.location and
* Window.location respectively. */
export interface Location {
/**
* Returns a DOMStringList object listing the origins of the ancestor browsing
* contexts, from the parent browsing context to the top-level browsing
* context.
*/
readonly ancestorOrigins: string[];
/**
* Returns the Location object's URL's fragment (includes leading "#" if
/** Returns a DOMStringList object listing the origins of the ancestor
* browsing contexts, from the parent browsing context to the top-level
* browsing context. */
readonly ancestorOrigins: DOMStringList;
/** Returns the Location object's URL's fragment (includes leading "#" if
* non-empty).
*
* Can be set, to navigate to the same URL with a changed fragment (ignores
* leading "#").
*/
* leading "#"). */
hash: string;
/**
* Returns the Location object's URL's host and port (if different from the
* default port for the scheme). Can be set, to navigate to the same URL with
* a changed host and port.
*/
/** Returns the Location object's URL's host and port (if different from the
* default port for the scheme).
*
* Can be set, to navigate to the same URL with a changed host and port. */
host: string;
/**
* Returns the Location object's URL's host. Can be set, to navigate to the
* same URL with a changed host.
*/
/** Returns the Location object's URL's host.
*
* Can be set, to navigate to the same URL with a changed host. */
hostname: string;
/**
* Returns the Location object's URL. Can be set, to navigate to the given
* URL.
*/
/** Returns the Location object's URL.
*
* Can be set, to navigate to the given URL. */
href: string;
toString(): string;
/** Returns the Location object's URL's origin. */
readonly origin: string;
/**
* Returns the Location object's URL's path.
* Can be set, to navigate to the same URL with a changed path.
*/
/** Returns the Location object's URL's path.
*
* Can be set, to navigate to the same URL with a changed path. */
pathname: string;
/**
* Returns the Location object's URL's port.
* Can be set, to navigate to the same URL with a changed port.
*/
/** Returns the Location object's URL's port.
*
* Can be set, to navigate to the same URL with a changed port. */
port: string;
/**
* Returns the Location object's URL's scheme.
* Can be set, to navigate to the same URL with a changed scheme.
*/
/** Returns the Location object's URL's scheme.
*
* Can be set, to navigate to the same URL with a changed scheme. */
protocol: string;
/**
* Returns the Location object's URL's query (includes leading "?" if
* non-empty). Can be set, to navigate to the same URL with a changed query
* (ignores leading "?").
*/
/** Returns the Location object's URL's query (includes leading "?" if
* non-empty).
*
* Can be set, to navigate to the same URL with a changed query (ignores
* leading "?"). */
search: string;
/**
* Navigates to the given URL.
@ -860,21 +923,14 @@ declare namespace __domTypes {
* Reloads the current page.
*/
reload(): void;
/** @deprecated */
reload(forcedReload: boolean): void;
/**
* Removes the current page from the session history and navigates to the
* given URL.
*/
/** Removes the current page from the session history and navigates to the
* given URL. */
replace(url: string): void;
}
}
declare namespace __blob {
export const bytesSymbol: unique symbol;
export const blobBytesWeakMap: WeakMap<__domTypes.Blob, Uint8Array>;
export class DenoBlob implements __domTypes.Blob {
private readonly [bytesSymbol];
readonly size: number;
readonly type: string;
/** A blob object represents a file-like object of immutable, raw data. */
@ -899,7 +955,6 @@ declare namespace __console {
}
const isConsoleInstance: unique symbol;
export class Console {
private printFunc;
indentLevel: number;
[isConsoleInstance]: boolean;
/** Writes the arguments to stdout */
@ -982,7 +1037,7 @@ declare namespace __event {
constructor({
bubbles,
cancelable,
composed
composed,
}?: {
bubbles?: boolean | undefined;
cancelable?: boolean | undefined;
@ -1053,7 +1108,7 @@ declare namespace __customEvent {
bubbles,
cancelable,
composed,
detail
detail,
}: __domTypes.CustomEventInit);
}
export class CustomEvent extends __event.Event
@ -1083,7 +1138,7 @@ declare namespace __eventTarget {
constructor({
capture,
passive,
once
once,
}?: {
capture?: boolean | undefined;
passive?: boolean | undefined;
@ -1123,7 +1178,7 @@ declare namespace __io {
export enum SeekMode {
SEEK_START = 0,
SEEK_CURRENT = 1,
SEEK_END = 2
SEEK_END = 2,
}
export interface Reader {
/** Reads up to p.byteLength bytes into `p`. It resolves to the number
@ -1213,16 +1268,15 @@ declare namespace __io {
declare namespace __fetch {
class Body
implements __domTypes.Body, __domTypes.ReadableStream, __io.ReadCloser {
private rid;
implements
__domTypes.Body,
__domTypes.ReadableStream<Uint8Array>,
__io.ReadCloser {
readonly contentType: string;
bodyUsed: boolean;
private _bodyPromise;
private _data;
readonly locked: boolean;
readonly body: null | Body;
readonly body: __domTypes.ReadableStream<Uint8Array>;
constructor(rid: number, contentType: string);
private _bodyBuffer;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<__domTypes.Blob>;
formData(): Promise<__domTypes.FormData>;
@ -1231,7 +1285,9 @@ declare namespace __fetch {
read(p: Uint8Array): Promise<number | Deno.EOF>;
close(): void;
cancel(): Promise<void>;
getReader(): __domTypes.ReadableStreamReader;
getReader(options: { mode: "byob" }): __domTypes.ReadableStreamBYOBReader;
getReader(): __domTypes.ReadableStreamDefaultReader<Uint8Array>;
getReader(): __domTypes.ReadableStreamBYOBReader;
tee(): [__domTypes.ReadableStream, __domTypes.ReadableStream];
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
}
@ -1283,7 +1339,6 @@ declare namespace __textEncoding {
ignoreBOM?: boolean;
}
export class TextDecoder {
private _encoding;
/** Returns encoding's name, lowercased. */
readonly encoding: string;
/** Returns `true` if error mode is "fatal", and `false` otherwise. */
@ -1333,10 +1388,7 @@ declare namespace __timers {
declare namespace __urlSearchParams {
export class URLSearchParams {
private params;
private url;
constructor(init?: string | string[][] | Record<string, string>);
private updateSteps;
/** Appends a specified key/value pair as a new search parameter.
*
* searchParams.append('name', 'first');
@ -1431,8 +1483,6 @@ declare namespace __urlSearchParams {
* searchParams.toString();
*/
toString(): string;
private _handleStringInitialization;
private _handleArrayInitialization;
}
}
@ -1475,16 +1525,12 @@ declare namespace __workers {
name?: string;
}
export class WorkerImpl implements Worker {
private readonly id;
private isClosing;
private readonly isClosedPromise;
onerror?: (e: Event) => void;
onmessage?: (data: any) => void;
onmessageerror?: () => void;
constructor(specifier: string, options?: WorkerOptions);
postMessage(data: any): void;
terminate(): void;
private run;
}
}

View File

@ -13,12 +13,12 @@ Object.defineProperties(globalThis, {
value: bootstrapMainRuntime,
enumerable: false,
writable: false,
configurable: false
configurable: false,
},
bootstrapWorkerRuntime: {
value: bootstrapWorkerRuntime,
enumerable: false,
writable: false,
configurable: false
}
configurable: false,
},
});

View File

@ -168,7 +168,7 @@ export function listen(
res = netOps.listen({
transport: "tcp",
hostname: "127.0.0.1",
...(options as ListenOptions)
...(options as ListenOptions),
});
}
@ -205,7 +205,7 @@ export async function connect(
res = await netOps.connect({
transport: "tcp",
hostname: "127.0.0.1",
...options
...options,
});
}

View File

@ -24,7 +24,7 @@ export function fetchSourceFiles(
> {
return sendAsync("op_fetch_source_files", {
specifiers,
referrer
referrer,
});
}
@ -47,6 +47,6 @@ export function cache(
sendSync("op_cache", {
extension,
moduleId,
contents
contents,
});
}

View File

@ -54,7 +54,7 @@ export function recordFromBufMinimal(ui8: Uint8Array): RecordMinimal {
promiseId,
arg,
result,
err
err,
};
}

View File

@ -21,11 +21,11 @@ export function applySourceMap(location: Location): Location {
const res = sendSync("op_apply_source_map", {
filename,
line: line - 1,
column: column - 1
column: column - 1,
});
return {
filename: res.filename,
line: res.line + 1,
column: res.column + 1
column: res.column + 1,
};
}

View File

@ -36,6 +36,6 @@ export function open(
path,
options,
openMode,
mode
mode,
});
}

View File

@ -25,7 +25,7 @@ export interface StatResponse {
export async function lstat(path: string): Promise<FileInfo> {
const res = (await sendAsync("op_stat", {
path,
lstat: true
lstat: true,
})) as StatResponse;
return new FileInfoImpl(res);
}
@ -33,7 +33,7 @@ export async function lstat(path: string): Promise<FileInfo> {
export function lstatSync(path: string): FileInfo {
const res = sendSync("op_stat", {
path,
lstat: true
lstat: true,
}) as StatResponse;
return new FileInfoImpl(res);
}
@ -41,7 +41,7 @@ export function lstatSync(path: string): FileInfo {
export async function stat(path: string): Promise<FileInfo> {
const res = (await sendAsync("op_stat", {
path,
lstat: false
lstat: false,
})) as StatResponse;
return new FileInfoImpl(res);
}
@ -49,7 +49,7 @@ export async function stat(path: string): Promise<FileInfo> {
export function statSync(path: string): FileInfo {
const res = sendSync("op_stat", {
path,
lstat: false
lstat: false,
}) as StatResponse;
return new FileInfoImpl(res);
}

View File

@ -14,7 +14,7 @@ export function utimeSync(
path,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
mtime: toSecondsFromEpoch(mtime)
mtime: toSecondsFromEpoch(mtime),
});
}
@ -27,6 +27,6 @@ export async function utime(
path,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
mtime: toSecondsFromEpoch(mtime)
mtime: toSecondsFromEpoch(mtime),
});
}

View File

@ -17,7 +17,7 @@ class FsEvents implements AsyncIterableIterator<FsEvent> {
next(): Promise<IteratorResult<FsEvent>> {
return sendAsync("op_fs_events_poll", {
rid: this.rid
rid: this.rid,
});
}

View File

@ -19,7 +19,7 @@ export enum ShutdownMode {
// Corresponding to SHUT_RD, SHUT_WR, SHUT_RDWR
Read = 0,
Write,
ReadWrite // unused
ReadWrite, // unused
}
export function shutdown(rid: number, how: ShutdownMode): void {

View File

@ -40,7 +40,7 @@ export function env(
set(obj, prop: string, value: string): boolean {
setEnv(prop, value);
return Reflect.set(obj, prop, value);
}
},
});
}

View File

@ -7,6 +7,6 @@ export function isatty(rid: number): boolean {
export function setRaw(rid: number, mode: boolean): void {
sendSync("op_set_raw", {
rid,
mode
mode,
});
}

View File

@ -12,7 +12,7 @@ export function createWorker(
specifier,
hasSourceCode,
sourceCode,
name
name,
});
}

View File

@ -14,17 +14,21 @@ interface PluginOp {
}
class PluginOpImpl implements PluginOp {
constructor(private readonly opId: number) {}
readonly #opId: number;
constructor(opId: number) {
this.#opId = opId;
}
dispatch(
control: Uint8Array,
zeroCopy?: ArrayBufferView | null
): Uint8Array | null {
return core.dispatch(this.opId, control, zeroCopy);
return core.dispatch(this.#opId, control, zeroCopy);
}
setAsyncHandler(handler: AsyncHandler): void {
core.setAsyncHandler(this.opId, handler);
core.setAsyncHandler(this.#opId, handler);
}
}
@ -37,16 +41,16 @@ interface Plugin {
}
class PluginImpl implements Plugin {
private _ops: { [name: string]: PluginOp } = {};
#ops: { [name: string]: PluginOp } = {};
constructor(private readonly rid: number, ops: { [name: string]: number }) {
constructor(_rid: number, ops: { [name: string]: number }) {
for (const op in ops) {
this._ops[op] = new PluginOpImpl(ops[op]);
this.#ops[op] = new PluginOpImpl(ops[op]);
}
}
get ops(): { [name: string]: PluginOp } {
return Object.assign({}, this._ops);
return Object.assign({}, this.#ops);
}
}

View File

@ -113,7 +113,7 @@ export function run({
env = {},
stdout = "inherit",
stderr = "inherit",
stdin = "inherit"
stdin = "inherit",
}: RunOptions): Process {
const res = runOp({
cmd: cmd.map(String),
@ -124,7 +124,7 @@ export function run({
stderr: isRid(stderr) ? "" : stderr,
stdinRid: isRid(stdin) ? stdin : 0,
stdoutRid: isRid(stdout) ? stdout : 0,
stderrRid: isRid(stderr) ? stderr : 0
stderrRid: isRid(stderr) ? stderr : 0,
}) as RunResponse;
return new Process(res);
}

View File

@ -1,5 +1,7 @@
// Derived from https://github.com/vadimg/js_bintrees. MIT Licensed.
import { assert } from "./util.ts";
class RBNode<T> {
public left: this | null;
public right: this | null;
@ -24,16 +26,18 @@ class RBNode<T> {
}
}
class RBTree<T> {
private root: RBNode<T> | null;
export class RBTree<T> {
#comparator: (a: T, b: T) => number;
#root: RBNode<T> | null;
constructor(private comparator: (a: T, b: T) => number) {
this.root = null;
constructor(comparator: (a: T, b: T) => number) {
this.#comparator = comparator;
this.#root = null;
}
// returns null if tree is empty
/** Returns `null` if tree is empty. */
min(): T | null {
let res = this.root;
let res = this.#root;
if (res === null) {
return null;
}
@ -43,11 +47,11 @@ class RBTree<T> {
return res.data;
}
// returns node data if found, null otherwise
/** Returns node `data` if found, `null` otherwise. */
find(data: T): T | null {
let res = this.root;
let res = this.#root;
while (res !== null) {
const c = this.comparator(data, res.data!);
const c = this.#comparator(data, res.data);
if (c === 0) {
return res.data;
} else {
@ -57,13 +61,13 @@ class RBTree<T> {
return null;
}
// returns true if inserted, false if duplicate
/** returns `true` if inserted, `false` if duplicate. */
insert(data: T): boolean {
let ret = false;
if (this.root === null) {
if (this.#root === null) {
// empty tree
this.root = new RBNode(data);
this.#root = new RBNode(data);
ret = true;
} else {
const head = new RBNode((null as unknown) as T); // fake tree root
@ -75,8 +79,8 @@ class RBTree<T> {
let gp = null; // grandparent
let ggp = head; // grand-grand-parent
let p: RBNode<T> | null = null; // parent
let node: RBNode<T> | null = this.root;
ggp.right = this.root;
let node: RBNode<T> | null = this.#root;
ggp.right = this.#root;
// search down
while (true) {
@ -96,14 +100,15 @@ class RBTree<T> {
if (isRed(node) && isRed(p)) {
const dir2 = ggp.right === gp;
assert(gp);
if (node === p!.getChild(last)) {
ggp.setChild(dir2, singleRotate(gp!, !last));
ggp.setChild(dir2, singleRotate(gp, !last));
} else {
ggp.setChild(dir2, doubleRotate(gp!, !last));
ggp.setChild(dir2, doubleRotate(gp, !last));
}
}
const cmp = this.comparator(node.data!, data);
const cmp = this.#comparator(node.data, data);
// stop if found
if (cmp === 0) {
@ -123,24 +128,24 @@ class RBTree<T> {
}
// update root
this.root = head.right;
this.#root = head.right;
}
// make root black
this.root!.red = false;
this.#root!.red = false;
return ret;
}
// returns true if removed, false if not found
/** Returns `true` if removed, `false` if not found. */
remove(data: T): boolean {
if (this.root === null) {
if (this.#root === null) {
return false;
}
const head = new RBNode((null as unknown) as T); // fake tree root
let node = head;
node.right = this.root;
node.right = this.#root;
let p = null; // parent
let gp = null; // grand parent
let found = null; // found item
@ -154,7 +159,7 @@ class RBTree<T> {
p = node;
node = node.getChild(dir)!;
const cmp = this.comparator(data, node.data);
const cmp = this.#comparator(data, node.data);
dir = cmp > 0;
@ -181,7 +186,8 @@ class RBTree<T> {
sibling.red = true;
node.red = true;
} else {
const dir2 = gp!.right === p;
assert(gp);
const dir2 = gp.right === p;
if (isRed(sibling.getChild(last))) {
gp!.setChild(dir2, doubleRotate(p, last));
@ -190,11 +196,14 @@ class RBTree<T> {
}
// ensure correct coloring
const gpc = gp!.getChild(dir2)!;
const gpc = gp.getChild(dir2);
assert(gpc);
gpc.red = true;
node.red = true;
gpc.left!.red = false;
gpc.right!.red = false;
assert(gpc.left);
gpc.left.red = false;
assert(gpc.right);
gpc.right.red = false;
}
}
}
@ -204,13 +213,14 @@ class RBTree<T> {
// replace and remove if found
if (found !== null) {
found.data = node.data;
p!.setChild(p!.right === node, node.getChild(node.left === null));
assert(p);
p.setChild(p.right === node, node.getChild(node.left === null));
}
// update root and make it black
this.root = head.right;
if (this.root !== null) {
this.root.red = false;
this.#root = head.right;
if (this.#root !== null) {
this.#root.red = false;
}
return found !== null;
@ -222,7 +232,8 @@ function isRed<T>(node: RBNode<T> | null): boolean {
}
function singleRotate<T>(root: RBNode<T>, dir: boolean | number): RBNode<T> {
const save = root.getChild(!dir)!;
const save = root.getChild(!dir);
assert(save);
root.setChild(!dir, save.getChild(dir));
save.setChild(dir, root);
@ -237,5 +248,3 @@ function doubleRotate<T>(root: RBNode<T>, dir: boolean | number): RBNode<T> {
root.setChild(!dir, singleRotate(root.getChild(!dir)!, !dir));
return singleRotate(root, dir);
}
export { RBTree };

View File

@ -17,20 +17,20 @@ const helpMsg = [
"_ Get last evaluation result",
"_error Get last thrown error",
"exit Exit the REPL",
"help Print this help message"
"help Print this help message",
].join("\n");
const replCommands = {
exit: {
get(): void {
exit(0);
}
},
},
help: {
get(): string {
return helpMsg;
}
}
},
},
};
// Error messages that allow users to continue input
@ -42,7 +42,7 @@ const recoverableErrorMessages = [
"Missing initializer in const declaration", // const a
"Missing catch or finally after try", // try {}
"missing ) after argument list", // console.log(1
"Unterminated template literal" // `template
"Unterminated template literal", // `template
// TODO(kevinkassimo): need a parser to handling errors such as:
// "Missing } in template expression" // `${ or `${ a 123 }`
];
@ -105,10 +105,10 @@ export async function replLoop(): Promise<void> {
value: value,
writable: true,
enumerable: true,
configurable: true
configurable: true,
});
console.log("Last evaluation result is no longer saved to _.");
}
},
});
// Configure globalThis._error to give the last thrown error.
@ -120,10 +120,10 @@ export async function replLoop(): Promise<void> {
value: value,
writable: true,
enumerable: true,
configurable: true
configurable: true,
});
console.log("Last thrown error is no longer saved to _error.");
}
},
});
while (true) {

View File

@ -17,7 +17,7 @@ import {
writable,
windowOrWorkerGlobalScopeMethods,
windowOrWorkerGlobalScopeProperties,
eventTargetProperties
eventTargetProperties,
} from "./globals.ts";
import { internalObject } from "./internals.ts";
import { setSignals } from "./signals.ts";
@ -63,7 +63,7 @@ export const mainRuntimeGlobalProperties = {
onload: writable(undefined),
onunload: writable(undefined),
close: writable(windowClose),
closed: getterOnly(() => windowIsClosing)
closed: getterOnly(() => windowIsClosing),
};
let hasBootstrapped = false;
@ -102,7 +102,7 @@ export function bootstrapMainRuntime(): void {
Object.defineProperties(Deno, {
pid: readOnly(s.pid),
noColor: readOnly(s.noColor),
args: readOnly(Object.freeze(s.args))
args: readOnly(Object.freeze(s.args)),
});
// Setup `Deno` global - we're actually overriding already
// existing global `Deno` with `Deno` namespace from "./deno.ts".

View File

@ -14,7 +14,7 @@ import {
nonEnumerable,
windowOrWorkerGlobalScopeMethods,
windowOrWorkerGlobalScopeProperties,
eventTargetProperties
eventTargetProperties,
} from "./globals.ts";
import * as webWorkerOps from "./ops/web_worker.ts";
import { LocationImpl } from "./web/location.ts";
@ -85,7 +85,7 @@ export const workerRuntimeGlobalProperties = {
// TODO: should be readonly?
close: nonEnumerable(close),
postMessage: writable(postMessage),
workerMessageRecvCallback: nonEnumerable(workerMessageRecvCallback)
workerMessageRecvCallback: nonEnumerable(workerMessageRecvCallback),
};
export function bootstrapWorkerRuntime(name: string): void {

View File

@ -34,7 +34,7 @@ enum LinuxSignal {
SIGWINCH = 28,
SIGIO = 29,
SIGPWR = 30,
SIGSYS = 31
SIGSYS = 31,
}
// From `kill -l`
@ -69,7 +69,7 @@ enum MacOSSignal {
SIGWINCH = 28,
SIGINFO = 29,
SIGUSR1 = 30,
SIGUSR2 = 31
SIGUSR2 = 31,
}
export const Signal: { [key: string]: number } = {};
@ -122,39 +122,40 @@ export const signals = {
},
windowChange(): SignalStream {
return signal(Signal.SIGWINCH);
}
},
};
export class SignalStream
implements AsyncIterableIterator<void>, PromiseLike<void> {
private rid: number;
private pollingPromise: Promise<boolean> = Promise.resolve(false);
private disposed = false;
#disposed = false;
#pollingPromise: Promise<boolean> = Promise.resolve(false);
#rid: number;
constructor(signo: number) {
this.rid = bindSignal(signo).rid;
this.loop();
this.#rid = bindSignal(signo).rid;
this.#loop();
}
private async pollSignal(): Promise<boolean> {
const res = await pollSignal(this.rid);
#pollSignal = async (): Promise<boolean> => {
const res = await pollSignal(this.#rid);
return res.done;
}
};
private async loop(): Promise<void> {
#loop = async (): Promise<void> => {
do {
this.pollingPromise = this.pollSignal();
} while (!(await this.pollingPromise) && !this.disposed);
}
this.#pollingPromise = this.#pollSignal();
} while (!(await this.#pollingPromise) && !this.#disposed);
};
then<T, S>(
f: (v: void) => T | Promise<T>,
g?: (v: Error) => S | Promise<S>
): Promise<T | S> {
return this.pollingPromise.then((_): void => {}).then(f, g);
return this.#pollingPromise.then(() => {}).then(f, g);
}
async next(): Promise<IteratorResult<void>> {
return { done: await this.pollingPromise, value: undefined };
return { done: await this.#pollingPromise, value: undefined };
}
[Symbol.asyncIterator](): AsyncIterableIterator<void> {
@ -162,10 +163,10 @@ export class SignalStream
}
dispose(): void {
if (this.disposed) {
if (this.#disposed) {
throw new Error("The stream has already been disposed.");
}
this.disposed = true;
unbindSignal(this.rid);
this.#disposed = true;
unbindSignal(this.#rid);
}
}

View File

@ -4,5 +4,5 @@ import { customInspect } from "./web/console.ts";
export const symbols = {
internal: internalSymbol,
customInspect
customInspect,
};

View File

@ -11,7 +11,7 @@ import { assert } from "./util.ts";
const RED_FAILED = red("FAILED");
const GREEN_OK = green("ok");
const YELLOW_IGNORED = yellow("ignored");
const disabledConsole = new Console((_x: string, _isErr?: boolean): void => {});
const disabledConsole = new Console((): void => {});
function formatDuration(time = 0): string {
const timeStr = `(${time}ms)`;
@ -140,7 +140,7 @@ export interface RunTestsOptions {
enum TestStatus {
Passed = "passed",
Failed = "failed",
Ignored = "ignored"
Ignored = "ignored",
}
interface TestResult {
@ -154,7 +154,7 @@ export enum TestEvent {
Start = "start",
TestStart = "testStart",
TestEnd = "testEnd",
End = "end"
End = "end",
}
interface TestEventStart {
@ -188,7 +188,7 @@ class TestApi {
ignored: 0,
measured: 0,
passed: 0,
failed: 0
failed: 0,
};
constructor(
@ -205,7 +205,7 @@ class TestApi {
> {
yield {
kind: TestEvent.Start,
tests: this.testsToRun.length
tests: this.testsToRun.length,
};
const results: TestResult[] = [];
@ -243,7 +243,7 @@ class TestApi {
kind: TestEvent.End,
stats: this.stats,
results,
duration
duration,
};
}
}
@ -283,33 +283,15 @@ interface TestReporter {
}
export class ConsoleTestReporter implements TestReporter {
private encoder: TextEncoder;
constructor() {
this.encoder = new TextEncoder();
}
private log(msg: string, noNewLine = false): Promise<void> {
if (!noNewLine) {
msg += "\n";
}
// Using `stdout` here because it doesn't force new lines
// compared to `console.log`; `core.print` on the other hand
// is line-buffered and doesn't output message without newline
stdout.writeSync(this.encoder.encode(msg));
return Promise.resolve();
}
start(event: TestEventStart): Promise<void> {
this.log(`running ${event.tests} tests`);
ConsoleTestReporter.log(`running ${event.tests} tests`);
return Promise.resolve();
}
testStart(event: TestEventTestStart): Promise<void> {
const { name } = event;
this.log(`test ${name} ... `, true);
ConsoleTestReporter.log(`test ${name} ... `, true);
return Promise.resolve();
}
@ -318,13 +300,19 @@ export class ConsoleTestReporter implements TestReporter {
switch (result.status) {
case TestStatus.Passed:
this.log(`${GREEN_OK} ${formatDuration(result.duration)}`);
ConsoleTestReporter.log(
`${GREEN_OK} ${formatDuration(result.duration)}`
);
break;
case TestStatus.Failed:
this.log(`${RED_FAILED} ${formatDuration(result.duration)}`);
ConsoleTestReporter.log(
`${RED_FAILED} ${formatDuration(result.duration)}`
);
break;
case TestStatus.Ignored:
this.log(`${YELLOW_IGNORED} ${formatDuration(result.duration)}`);
ConsoleTestReporter.log(
`${YELLOW_IGNORED} ${formatDuration(result.duration)}`
);
break;
}
@ -334,25 +322,25 @@ export class ConsoleTestReporter implements TestReporter {
end(event: TestEventEnd): Promise<void> {
const { stats, duration, results } = event;
// Attempting to match the output of Rust's test runner.
const failedTests = results.filter(r => r.error);
const failedTests = results.filter((r) => r.error);
if (failedTests.length > 0) {
this.log(`\nfailures:\n`);
ConsoleTestReporter.log(`\nfailures:\n`);
for (const result of failedTests) {
this.log(`${result.name}`);
this.log(`${stringifyArgs([result.error!])}`);
this.log("");
ConsoleTestReporter.log(`${result.name}`);
ConsoleTestReporter.log(`${stringifyArgs([result.error!])}`);
ConsoleTestReporter.log("");
}
this.log(`failures:\n`);
ConsoleTestReporter.log(`failures:\n`);
for (const result of failedTests) {
this.log(`\t${result.name}`);
ConsoleTestReporter.log(`\t${result.name}`);
}
}
this.log(
ConsoleTestReporter.log(
`\ntest result: ${stats.failed ? RED_FAILED : GREEN_OK}. ` +
`${stats.passed} passed; ${stats.failed} failed; ` +
`${stats.ignored} ignored; ${stats.measured} measured; ` +
@ -362,6 +350,20 @@ export class ConsoleTestReporter implements TestReporter {
return Promise.resolve();
}
static encoder = new TextEncoder();
static log(msg: string, noNewLine = false): Promise<void> {
if (!noNewLine) {
msg += "\n";
}
// Using `stdout` here because it doesn't force new lines
// compared to `console.log`; `core.print` on the other hand
// is line-buffered and doesn't output message without newline
stdout.writeSync(ConsoleTestReporter.encoder.encode(msg));
return Promise.resolve();
}
}
export async function runTests({
@ -370,7 +372,7 @@ export async function runTests({
only = undefined,
skip = undefined,
disableLog = false,
reporter = undefined
reporter = undefined,
}: RunTestsOptions = {}): Promise<{
results: TestResult[];
stats: TestStats;

View File

@ -38,7 +38,7 @@ unitTest(function blobShouldNotThrowError(): void {
try {
const options1: object = {
ending: "utf8",
hasOwnProperty: "hasOwnProperty"
hasOwnProperty: "hasOwnProperty",
};
const options2: object = Object.create(null);
new Blob(["Hello World"], options1);
@ -52,7 +52,7 @@ unitTest(function blobShouldNotThrowError(): void {
unitTest(function nativeEndLine(): void {
const options: object = {
ending: "native"
ending: "native",
};
const blob = new Blob(["Hello\nWorld"], options);

View File

@ -5,7 +5,7 @@ import { unitTest, assertEquals, assert } from "./test_util.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildBody(body: any): Body {
const stub = new Request("", {
body: body
body: body,
});
return stub as Body;
}
@ -19,7 +19,7 @@ const intArrays = [
Uint32Array,
Uint8ClampedArray,
Float32Array,
Float64Array
Float64Array,
];
unitTest(async function arrayBufferFromByteArrays(): Promise<void> {
const buffer = new TextEncoder().encode("ahoyhoy8").buffer;

View File

@ -7,7 +7,7 @@ import {
assertEquals,
assert,
assertStrContains,
unitTest
unitTest,
} from "./test_util.ts";
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;

View File

@ -22,7 +22,7 @@ unitTest(
unitTest(
{
ignore: Deno.build.os === "win",
perms: { read: true, write: true }
perms: { read: true, write: true },
},
function chmodSyncSymlinkSuccess(): void {
const enc = new TextEncoder();
@ -94,7 +94,7 @@ unitTest(
unitTest(
{
ignore: Deno.build.os === "win",
perms: { read: true, write: true }
perms: { read: true, write: true },
},
async function chmodSymlinkSuccess(): Promise<void> {
const enc = new TextEncoder();

View File

@ -7,11 +7,11 @@ if (Deno.build.os !== "win") {
// get the user ID and group ID of the current process
const uidProc = Deno.run({
stdout: "piped",
cmd: ["python", "-c", "import os; print(os.getuid())"]
cmd: ["python", "-c", "import os; print(os.getuid())"],
});
const gidProc = Deno.run({
stdout: "piped",
cmd: ["python", "-c", "import os; print(os.getgid())"]
cmd: ["python", "-c", "import os; print(os.getgid())"],
});
assertEquals((await uidProc.status()).code, 0);

View File

@ -6,14 +6,14 @@ import { assert, assertEquals, unitTest } from "./test_util.ts";
const {
inspect,
writeSync,
stdout
stdout,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = Deno as any;
const customInspect = Deno.symbols.customInspect;
const {
Console,
stringifyArgs
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal];
@ -37,7 +37,7 @@ unitTest(function consoleHasRightInstance(): void {
});
unitTest(function consoleTestAssertShouldNotThrowError(): void {
mockConsole(console => {
mockConsole((console) => {
console.assert(true);
let hasThrown = undefined;
try {
@ -92,7 +92,7 @@ unitTest(function consoleTestStringifyCircular(): void {
arrowFunc: () => {},
extendedClass: new Extended(),
nFunc: new Function(),
extendedCstr: Extended
extendedCstr: Extended,
};
const circularObj = {
@ -105,7 +105,7 @@ unitTest(function consoleTestStringifyCircular(): void {
nested: nestedObj,
emptyObj: {},
arr: [1, "s", false, null, nestedObj],
baseClass: new Base()
baseClass: new Base(),
};
nestedObj.o = circularObj;
@ -154,7 +154,7 @@ unitTest(function consoleTestStringifyCircular(): void {
stringify(
new Map([
[1, "one"],
[2, "two"]
[2, "two"],
])
),
`Map { 1 => "one", 2 => "two" }`
@ -192,7 +192,6 @@ unitTest(function consoleTestStringifyCircular(): void {
assertEquals(
stringify(console),
`{
printFunc: [Function],
log: [Function],
debug: [Function],
info: [Function],
@ -261,8 +260,8 @@ unitTest(function consoleTestStringifyLargeObject(): void {
g: 10,
asd: 2,
asda: 3,
x: { a: "asd", x: 3 }
}
x: { a: "asd", x: 3 },
},
};
assertEquals(
stringify(obj),
@ -394,14 +393,14 @@ unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier(): void {
unitTest(function consoleTestCallToStringOnLabel(): void {
const methods = ["count", "countReset", "time", "timeLog", "timeEnd"];
mockConsole(console => {
mockConsole((console) => {
for (const method of methods) {
let hasCalled = false;
// @ts-ignore
console[method]({
toString(): void {
hasCalled = true;
}
},
});
assertEquals(hasCalled, true);
}
@ -446,7 +445,7 @@ unitTest(function consoleTestClear(): void {
// Test bound this issue
unitTest(function consoleDetachedLog(): void {
mockConsole(console => {
mockConsole((console) => {
const log = console.log;
const dir = console.dir;
const dirxml = console.dirxml;
@ -635,7 +634,7 @@ unitTest(function consoleTable(): void {
console.table(
new Map([
[1, "one"],
[2, "two"]
[2, "two"],
])
);
assertEquals(
@ -655,7 +654,7 @@ unitTest(function consoleTable(): void {
b: { c: { d: 10 }, e: [1, 2, [5, 6]] },
f: "test",
g: new Set([1, 2, 3, "test"]),
h: new Map([[1, "one"]])
h: new Map([[1, "one"]]),
});
assertEquals(
out.toString(),
@ -677,7 +676,7 @@ unitTest(function consoleTable(): void {
"test",
false,
{ a: 10 },
["test", { b: 20, c: "test" }]
["test", { b: 20, c: "test" }],
]);
assertEquals(
out.toString(),
@ -745,7 +744,7 @@ unitTest(function consoleTable(): void {
// console.log(Error) test
unitTest(function consoleLogShouldNotThrowError(): void {
mockConsole(console => {
mockConsole((console) => {
let result = 0;
try {
console.log(new Error("foo"));

View File

@ -7,7 +7,7 @@ unitTest(function customEventInitializedWithDetail(): void {
const customEventInit = {
bubbles: true,
cancelable: true,
detail
detail,
} as CustomEventInit;
const event = new CustomEvent(type, customEventInit);

View File

@ -3,7 +3,7 @@ import {
assertEquals,
assertMatch,
unitTest,
unreachable
unreachable,
} from "./test_util.ts";
const readErrorStackPattern = new RegExp(

View File

@ -5,7 +5,7 @@ import { unitTest, assert, assertEquals } from "./test_util.ts";
function setup() {
const dataSymbol = Symbol("data symbol");
class Base {
private [dataSymbol] = new Map<string, number>();
[dataSymbol] = new Map<string, number>();
constructor(
data: Array<[string, number]> | IterableIterator<[string, number]>
@ -21,7 +21,7 @@ function setup() {
// This is using an internal API we don't want published as types, so having
// to cast to any to "trick" TypeScript
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol)
DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol),
};
}
@ -30,7 +30,7 @@ unitTest(function testDomIterable(): void {
const fixture: Array<[string, number]> = [
["foo", 1],
["bar", 2]
["bar", 2],
];
const domIterable = new DomIterable(fixture);

View File

@ -76,7 +76,7 @@ function getMockCallSite(
},
getPromiseIndex(): null {
return null;
}
},
};
}
@ -90,7 +90,7 @@ unitTest(function prepareStackTrace(): void {
structuredStackTrace: CallSite[]
) => string = MockError.prepareStackTrace;
const result = prepareStackTrace(new Error("foo"), [
getMockCallSite("CLI_SNAPSHOT.js", 23, 0)
getMockCallSite("CLI_SNAPSHOT.js", 23, 0),
]);
assert(result.startsWith("Error: foo\n"));
assert(result.includes(".ts:"), "should remap to something in 'js/'");
@ -100,7 +100,7 @@ unitTest(function applySourceMap(): void {
const result = Deno.applySourceMap({
filename: "CLI_SNAPSHOT.js",
line: 23,
column: 0
column: 0,
});
assert(result.filename.endsWith(".ts"));
assert(result.line != null);

View File

@ -114,7 +114,7 @@ unitTest(function dispatchEventShouldNotThrowError(): void {
const target = new EventTarget();
const event = new Event("hasOwnProperty", {
bubbles: true,
cancelable: false
cancelable: false,
});
const listener = (): void => {};
target.addEventListener("hasOwnProperty", listener);
@ -130,7 +130,7 @@ unitTest(function eventTargetThisShouldDefaultToWindow(): void {
const {
addEventListener,
dispatchEvent,
removeEventListener
removeEventListener,
} = EventTarget.prototype;
let n = 1;
const event = new Event("hello");
@ -164,7 +164,7 @@ unitTest(function eventTargetShouldAcceptEventListenerObject(): void {
handleEvent(e: Event): void {
assertEquals(e, event);
++callCount;
}
},
};
target.addEventListener("foo", listener);
@ -213,7 +213,7 @@ unitTest(
handleEvent(e: Event): void {
assertEquals(e, event);
++callCount;
}
},
};
target.addEventListener("foo", listener);

View File

@ -5,7 +5,7 @@ import {
assertEquals,
assertStrContains,
assertThrows,
fail
fail,
} from "./test_util.ts";
unitTest({ perms: { net: true } }, async function fetchProtocolError(): Promise<
@ -174,7 +174,7 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function fetchWithRedirection(): Promise<void> {
const response = await fetch("http://localhost:4546/"); // will redirect to http://localhost:4545/
@ -188,7 +188,7 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function fetchWithRelativeRedirection(): Promise<void> {
const response = await fetch("http://localhost:4545/cli/tests"); // will redirect to /cli/tests/
@ -204,7 +204,7 @@ unitTest(
// FIXME(bartlomieju):
// The feature below is not implemented, but the test should work after implementation
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function fetchWithInfRedirection(): Promise<void> {
const response = await fetch("http://localhost:4549/cli/tests"); // will redirect to the same place
@ -218,7 +218,7 @@ unitTest(
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: data
body: data,
});
const text = await response.text();
assertEquals(text, data);
@ -232,7 +232,7 @@ unitTest(
const data = "Hello World";
const req = new Request("http://localhost:4545/echo_server", {
method: "POST",
body: data
body: data,
});
const response = await fetch(req);
const text = await response.text();
@ -246,7 +246,7 @@ unitTest(
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: new TextEncoder().encode(data)
body: new TextEncoder().encode(data),
});
const text = await response.text();
assertEquals(text, data);
@ -260,7 +260,7 @@ unitTest(
const params = new URLSearchParams(data);
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: params
body: params,
});
const text = await response.text();
assertEquals(text, data);
@ -277,11 +277,11 @@ unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise<
> {
const data = "const a = 1";
const blob = new Blob([data], {
type: "text/javascript"
type: "text/javascript",
});
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: blob
body: blob,
});
const text = await response.text();
assertEquals(text, data);
@ -295,7 +295,7 @@ unitTest(
form.append("field", "value");
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: form
body: form,
});
const resultForm = await response.formData();
assertEquals(form.get("field"), resultForm.get("field"));
@ -308,7 +308,7 @@ unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise<
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
body: new TextEncoder().encode(data)
body: new TextEncoder().encode(data),
});
assertEquals(response.headers.get("user-agent"), `Deno/${Deno.version.deno}`);
await response.text();
@ -337,7 +337,7 @@ function bufferServer(addr: string): Deno.Buffer {
const [hostname, port] = addr.split(":");
const listener = Deno.listen({
hostname,
port: Number(port)
port: Number(port),
}) as Deno.Listener;
const buf = new Deno.Buffer();
listener.accept().then(async (conn: Deno.Conn) => {
@ -364,7 +364,7 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function fetchRequest(): Promise<void> {
const addr = "127.0.0.1:4501";
@ -373,8 +373,8 @@ unitTest(
method: "POST",
headers: [
["Hello", "World"],
["Foo", "Bar"]
]
["Foo", "Bar"],
],
});
assertEquals(response.status, 404);
assertEquals(response.headers.get("Content-Length"), "2");
@ -384,7 +384,7 @@ unitTest(
"POST /blah HTTP/1.1\r\n",
"hello: World\r\n",
"foo: Bar\r\n",
`host: ${addr}\r\n\r\n`
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
}
@ -394,7 +394,7 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function fetchPostBodyString(): Promise<void> {
const addr = "127.0.0.1:4502";
@ -404,9 +404,9 @@ unitTest(
method: "POST",
headers: [
["Hello", "World"],
["Foo", "Bar"]
["Foo", "Bar"],
],
body
body,
});
assertEquals(response.status, 404);
assertEquals(response.headers.get("Content-Length"), "2");
@ -418,7 +418,7 @@ unitTest(
"foo: Bar\r\n",
`host: ${addr}\r\n`,
`content-length: ${body.length}\r\n\r\n`,
body
body,
].join("");
assertEquals(actual, expected);
}
@ -428,7 +428,7 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function fetchPostBodyTypedArray(): Promise<void> {
const addr = "127.0.0.1:4503";
@ -439,9 +439,9 @@ unitTest(
method: "POST",
headers: [
["Hello", "World"],
["Foo", "Bar"]
["Foo", "Bar"],
],
body
body,
});
assertEquals(response.status, 404);
assertEquals(response.headers.get("Content-Length"), "2");
@ -453,7 +453,7 @@ unitTest(
"foo: Bar\r\n",
`host: ${addr}\r\n`,
`content-length: ${body.byteLength}\r\n\r\n`,
bodyStr
bodyStr,
].join("");
assertEquals(actual, expected);
}
@ -461,11 +461,11 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function fetchWithManualRedirection(): Promise<void> {
const response = await fetch("http://localhost:4546/", {
redirect: "manual"
redirect: "manual",
}); // will redirect to http://localhost:4545/
assertEquals(response.status, 0);
assertEquals(response.statusText, "");
@ -484,11 +484,11 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function fetchWithErrorRedirection(): Promise<void> {
const response = await fetch("http://localhost:4546/", {
redirect: "error"
redirect: "error",
}); // will redirect to http://localhost:4545/
assertEquals(response.status, 0);
assertEquals(response.statusText, "");

View File

@ -58,7 +58,7 @@ unitTest(function fileVariousFileBits(): void {
new Blob(),
new Uint8Array([0x50, 0x41]),
new Uint16Array([0x5353]),
new Uint32Array([0x53534150])
new Uint32Array([0x53534150]),
],
16
);

View File

@ -3,7 +3,7 @@ import {
unitTest,
assert,
assertEquals,
assertStrContains
assertStrContains,
} from "./test_util.ts";
unitTest(function filesStdioFileDescriptors(): void {
@ -46,15 +46,17 @@ unitTest(async function readerToAsyncIterator(): Promise<void> {
const encoder = new TextEncoder();
class TestReader implements Deno.Reader {
private offset = 0;
private buf = new Uint8Array(encoder.encode(this.s));
#offset = 0;
#buf: Uint8Array;
constructor(private readonly s: string) {}
constructor(s: string) {
this.#buf = new Uint8Array(encoder.encode(s));
}
read(p: Uint8Array): Promise<number | Deno.EOF> {
const n = Math.min(p.byteLength, this.buf.byteLength - this.offset);
p.set(this.buf.slice(this.offset, this.offset + n));
this.offset += n;
const n = Math.min(p.byteLength, this.#buf.byteLength - this.#offset);
p.set(this.#buf.slice(this.#offset, this.#offset + n));
this.#offset += n;
if (n === 0) {
return Promise.resolve(Deno.EOF);
@ -76,14 +78,14 @@ unitTest(async function readerToAsyncIterator(): Promise<void> {
unitTest(
{
perms: { read: true, write: true }
perms: { read: true, write: true },
},
function openSyncMode(): void {
const path = Deno.makeTempDirSync() + "/test_openSync.txt";
const file = Deno.openSync(path, {
write: true,
createNew: true,
mode: 0o626
mode: 0o626,
});
file.close();
const pathInfo = Deno.statSync(path);
@ -95,14 +97,14 @@ unitTest(
unitTest(
{
perms: { read: true, write: true }
perms: { read: true, write: true },
},
async function openMode(): Promise<void> {
const path = (await Deno.makeTempDir()) + "/test_open.txt";
const file = await Deno.open(path, {
write: true,
createNew: true,
mode: 0o626
mode: 0o626,
});
file.close();
const pathInfo = Deno.statSync(path);
@ -198,7 +200,7 @@ unitTest(
const w = {
write: true,
truncate: true,
create: true
create: true,
};
const file = await Deno.open(filename, w);

View File

@ -88,7 +88,7 @@ unitTest(function formDataSetEmptyBlobSuccess(): void {
unitTest(function formDataParamsForEachSuccess(): void {
const init = [
["a", "54"],
["b", "true"]
["b", "true"],
];
const formData = new FormData();
for (const [name, value] of init) {
@ -110,7 +110,7 @@ unitTest(function formDataParamsArgumentsCheck(): void {
"getAll",
"get",
"has",
"forEach"
"forEach",
] as const;
const methodRequireTwoParams = ["append", "set"] as const;

View File

@ -11,8 +11,8 @@ unitTest(function formatDiagnosticBasic() {
scriptResourceName: "foo.ts",
startColumn: 1,
endColumn: 2,
code: 4000
}
code: 4000,
},
];
const out = Deno.formatDiagnostics(fixture);
assert(out.includes("Example error"));

View File

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertEquals } from "./test_util.ts";
const {
stringifyArgs
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal];
@ -29,7 +29,7 @@ const headerDict: Record<string, string> = {
name3: "value3",
// @ts-ignore
name4: undefined,
"Content-Type": "value4"
"Content-Type": "value4",
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const headerSeq: any[] = [];
@ -142,7 +142,7 @@ const headerEntriesDict: Record<string, string> = {
name: "value3",
"content-Type": "value4",
"Content-Typ": "value5",
"Content-Types": "value6"
"Content-Types": "value6",
};
unitTest(function headerForEachSuccess(): void {
@ -346,7 +346,7 @@ unitTest(function customInspectReturnsCorrectHeadersFormat(): void {
);
const multiParamHeader = new Headers([
["Content-Type", "application/json"],
["Content-Length", "1337"]
["Content-Length", "1337"],
]);
assertEquals(
stringify(multiParamHeader),

View File

@ -3,7 +3,7 @@ import { unitTest, assert } from "./test_util.ts";
unitTest(function internalsExists(): void {
const {
stringifyArgs
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.symbols.internal];
assert(!!stringifyArgs);

View File

@ -3,7 +3,7 @@ import {
unitTest,
assert,
assertEquals,
createResolvable
createResolvable,
} from "./test_util.ts";
unitTest({ perms: { net: true } }, function netTcpListenClose(): void {
@ -18,13 +18,13 @@ unitTest(
{
perms: { net: true },
// TODO:
ignore: Deno.build.os === "win"
ignore: Deno.build.os === "win",
},
function netUdpListenClose(): void {
const socket = Deno.listen({
hostname: "127.0.0.1",
port: 4500,
transport: "udp"
transport: "udp",
});
assert(socket.addr.transport === "udp");
assertEquals(socket.addr.hostname, "127.0.0.1");
@ -39,7 +39,7 @@ unitTest(
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
address: filePath,
transport: "unix"
transport: "unix",
});
assert(socket.addr.transport === "unix");
assertEquals(socket.addr.address, filePath);
@ -53,7 +53,7 @@ unitTest(
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
address: filePath,
transport: "unixpacket"
transport: "unixpacket",
});
assert(socket.addr.transport === "unixpacket");
assertEquals(socket.addr.address, filePath);
@ -63,7 +63,7 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function netTcpCloseWhileAccept(): Promise<void> {
const listener = Deno.listen({ port: 4501 });
@ -87,7 +87,7 @@ unitTest(
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({
address: filePath,
transport: "unix"
transport: "unix",
});
const p = listener.accept();
listener.close();
@ -337,7 +337,7 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function netListenAsyncIterator(): Promise<void> {
const addr = { hostname: "127.0.0.1", port: 4500 };
@ -372,14 +372,14 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function netCloseReadSuccess() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
const closeReadDeferred = createResolvable();
listener.accept().then(async conn => {
listener.accept().then(async (conn) => {
await closeReadDeferred;
await conn.write(new Uint8Array([1, 2, 3]));
const buf = new Uint8Array(1024);
@ -409,13 +409,13 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function netDoubleCloseRead() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async conn => {
listener.accept().then(async (conn) => {
await conn.write(new Uint8Array([1, 2, 3]));
await closeDeferred;
conn.close();
@ -441,13 +441,13 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function netCloseWriteSuccess() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async conn => {
listener.accept().then(async (conn) => {
await conn.write(new Uint8Array([1, 2, 3]));
await closeDeferred;
conn.close();
@ -480,13 +480,13 @@ unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true }
perms: { net: true },
},
async function netDoubleCloseWrite() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async conn => {
listener.accept().then(async (conn) => {
await closeDeferred;
conn.close();
});
@ -509,7 +509,7 @@ unitTest(
unitTest(
{
perms: { net: true }
perms: { net: true },
},
async function netHangsOnClose() {
let acceptedConn: Deno.Conn;

View File

@ -4,7 +4,7 @@ import {
assertEquals,
assertNotEquals,
assertThrows,
unitTest
unitTest,
} from "./test_util.ts";
unitTest({ perms: { env: true } }, function envSuccess(): void {
@ -67,7 +67,7 @@ unitTest(
const proc = Deno.run({
cmd: [Deno.execPath(), "eval", src],
env: inputEnv,
stdout: "piped"
stdout: "piped",
});
const status = await proc.status();
assertEquals(status.success, true);
@ -134,121 +134,121 @@ unitTest({ perms: { env: true } }, function getDir(): void {
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "cache",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "executable",
runtime: [
{ os: "mac", shouldHaveValue: false },
{ os: "win", shouldHaveValue: false },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "data",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "data_local",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "audio",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "desktop",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "document",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "download",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "font",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: false },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "picture",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "public",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "template",
runtime: [
{ os: "mac", shouldHaveValue: false },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
{ os: "linux", shouldHaveValue: false },
],
},
{
kind: "tmp",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: true }
]
{ os: "linux", shouldHaveValue: true },
],
},
{
kind: "video",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
{ os: "linux", shouldHaveValue: false }
]
}
{ os: "linux", shouldHaveValue: false },
],
},
];
for (const s of scenes) {

View File

@ -3,7 +3,7 @@ import {
assert,
assertEquals,
assertStrContains,
unitTest
unitTest,
} from "./test_util.ts";
const { kill, run, readFile, open, makeTempDir, writeFile } = Deno;
@ -22,7 +22,7 @@ unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
const p = run({
cmd: ["python", "-c", "print('hello world')"],
stdout: "piped",
stderr: "null"
stderr: "null",
});
const status = await p.status();
assertEquals(status.success, true);
@ -36,7 +36,7 @@ unitTest(
{ perms: { run: true } },
async function runCommandFailedWithCode(): Promise<void> {
const p = run({
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"]
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"],
});
const status = await p.status();
assertEquals(status.success, false);
@ -50,11 +50,11 @@ unitTest(
{
// No signals on windows.
ignore: Deno.build.os === "win",
perms: { run: true }
perms: { run: true },
},
async function runCommandFailedWithSignal(): Promise<void> {
const p = run({
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"]
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"],
});
const status = await p.status();
assertEquals(status.success, false);
@ -102,7 +102,7 @@ while True:
Deno.writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
const p = run({
cwd,
cmd: ["python", `${pyProgramFile}.py`]
cmd: ["python", `${pyProgramFile}.py`],
});
// Write the expected exit code *after* starting python.
@ -123,7 +123,7 @@ unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
> {
const p = run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: "piped"
stdin: "piped",
});
assert(p.stdin);
assert(!p.stdout);
@ -147,7 +147,7 @@ unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
> {
const p = run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped"
stdout: "piped",
});
assert(!p.stdin);
assert(!p.stderr);
@ -176,7 +176,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
> {
const p = run({
cmd: ["python", "-c", "import sys; sys.stderr.write('hello')"],
stderr: "piped"
stderr: "piped",
});
assert(!p.stdin);
assert(!p.stdout);
@ -203,7 +203,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
const p = run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped"
stdout: "piped",
});
const output = await p.output();
const s = new TextDecoder().decode(output);
@ -216,7 +216,7 @@ unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
> {
const p = run({
cmd: ["python", "-c", "import sys; sys.stderr.write('error')"],
stderr: "piped"
stderr: "piped",
});
const error = await p.stderrOutput();
const s = new TextDecoder().decode(error);
@ -235,10 +235,10 @@ unitTest(
cmd: [
"python",
"-c",
"import sys; sys.stderr.write('error\\n'); sys.stdout.write('output\\n');"
"import sys; sys.stderr.write('error\\n'); sys.stdout.write('output\\n');",
],
stdout: file.rid,
stderr: file.rid
stderr: file.rid,
});
await p.status();
@ -265,7 +265,7 @@ unitTest(
const p = run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: file.rid
stdin: file.rid,
});
const status = await p.status();
@ -280,13 +280,13 @@ unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
cmd: [
"python",
"-c",
"import os, sys; sys.stdout.write(os.environ.get('FOO', '') + os.environ.get('BAR', ''))"
"import os, sys; sys.stdout.write(os.environ.get('FOO', '') + os.environ.get('BAR', ''))",
],
env: {
FOO: "0123",
BAR: "4567"
BAR: "4567",
},
stdout: "piped"
stdout: "piped",
});
const output = await p.output();
const s = new TextDecoder().decode(output);
@ -299,9 +299,9 @@ unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
cmd: [
"python",
"-c",
"from time import sleep; import sys; sleep(10000); sys.stderr.write('error')"
"from time import sleep; import sys; sleep(10000); sys.stderr.write('error')",
],
stderr: "piped"
stderr: "piped",
});
assert(!p.stdin);
assert(!p.stdout);
@ -343,7 +343,7 @@ if (Deno.build.os !== "win") {
void
> {
const p = run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"]
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assertEquals(Deno.Signal.SIGINT, 2);
@ -361,7 +361,7 @@ if (Deno.build.os !== "win") {
unitTest({ perms: { run: true } }, function killFailed(): void {
const p = run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"]
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assert(!p.stdin);
assert(!p.stdout);

View File

@ -15,7 +15,7 @@ unitTest({ perms: { read: true } }, function realpathSyncSuccess(): void {
unitTest(
{
ignore: Deno.build.os === "win",
perms: { read: true, write: true }
perms: { read: true, write: true },
},
function realpathSyncSymlink(): void {
const testDir = Deno.makeTempDirSync();
@ -67,7 +67,7 @@ unitTest({ perms: { read: true } }, async function realpathSuccess(): Promise<
unitTest(
{
ignore: Deno.build.os === "win",
perms: { read: true, write: true }
perms: { read: true, write: true },
},
async function realpathSymlink(): Promise<void> {
const testDir = Deno.makeTempDirSync();

View File

@ -6,8 +6,8 @@ unitTest(function fromInit(): void {
body: "ahoyhoy",
method: "POST",
headers: {
"test-header": "value"
}
"test-header": "value",
},
});
// @ts-ignore
@ -34,7 +34,7 @@ unitTest(async function cloneRequestBodyStream(): Promise<void> {
// hack to get a stream
const stream = new Request("", { body: "a test body" }).body;
const r1 = new Request("https://example.com", {
body: stream
body: stream,
});
const r2 = r1.clone();

View File

@ -4,7 +4,7 @@ import {
assert,
assertEquals,
assertThrows,
createResolvable
createResolvable,
} from "./test_util.ts";
function defer(n: number): Promise<void> {

View File

@ -10,7 +10,7 @@ export {
assertStrictEq,
assertStrContains,
unreachable,
fail
fail,
} from "../../../std/testing/asserts.ts";
export { readLines } from "../../../std/io/bufio.ts";
export { parse as parseArgs } from "../../../std/flags/mod.ts";
@ -28,7 +28,7 @@ export interface Permissions {
export function fmtPerms(perms: Permissions): string {
const p = Object.keys(perms)
.filter((e): boolean => perms[e as keyof Permissions] === true)
.map(key => `--allow-${key}`);
.map((key) => `--allow-${key}`);
if (p.length) {
return p.join(" ");
@ -48,7 +48,7 @@ export async function getProcessPermissions(): Promise<Permissions> {
net: await isGranted("net"),
env: await isGranted("env"),
plugin: await isGranted("plugin"),
hrtime: await isGranted("hrtime")
hrtime: await isGranted("hrtime"),
};
}
@ -108,7 +108,7 @@ function normalizeTestPermissions(perms: UnitTestPermissions): Permissions {
run: !!perms.run,
env: !!perms.env,
plugin: !!perms.plugin,
hrtime: !!perms.hrtime
hrtime: !!perms.hrtime,
};
}
@ -170,7 +170,7 @@ export function unitTest(
name,
fn,
ignore: !!options.ignore,
perms: normalizedPerms
perms: normalizedPerms,
};
REGISTERED_UNIT_TESTS.push(unitTestDefinition);
@ -194,17 +194,19 @@ export function createResolvable<T>(): Resolvable<T> {
return Object.assign(promise, methods!) as Resolvable<T>;
}
export class SocketReporter implements Deno.TestReporter {
private encoder: TextEncoder;
const encoder = new TextEncoder();
constructor(private conn: Deno.Conn) {
this.encoder = new TextEncoder();
export class SocketReporter implements Deno.TestReporter {
#conn: Deno.Conn;
constructor(conn: Deno.Conn) {
this.#conn = conn;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async write(msg: any): Promise<void> {
const encodedMsg = this.encoder.encode(JSON.stringify(msg) + "\n");
await Deno.writeAll(this.conn, encodedMsg);
const encodedMsg = encoder.encode(JSON.stringify(msg) + "\n");
await Deno.writeAll(this.#conn, encodedMsg);
}
async start(msg: Deno.TestEventStart): Promise<void> {
@ -229,9 +231,9 @@ export class SocketReporter implements Deno.TestReporter {
}
async end(msg: Deno.TestEventEnd): Promise<void> {
const encodedMsg = this.encoder.encode(JSON.stringify(msg));
await Deno.writeAll(this.conn, encodedMsg);
this.conn.closeWrite();
const encodedMsg = encoder.encode(JSON.stringify(msg));
await Deno.writeAll(this.#conn, encodedMsg);
this.#conn.closeWrite();
}
}
@ -245,7 +247,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
hrtime: false
hrtime: false,
},
normalizeTestPermissions({ read: true })
)
@ -260,7 +262,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
hrtime: false
hrtime: false,
},
normalizeTestPermissions({})
)
@ -275,7 +277,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
hrtime: true
hrtime: true,
},
normalizeTestPermissions({ read: true })
),
@ -291,7 +293,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
hrtime: false
hrtime: false,
},
normalizeTestPermissions({ read: true })
),
@ -307,7 +309,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
hrtime: true
hrtime: true,
},
{
read: true,
@ -316,7 +318,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
hrtime: true
hrtime: true,
}
)
);
@ -330,9 +332,9 @@ unitTest(
{ perms: { read: true } },
function assertAllUnitTestFilesImported(): void {
const directoryTestFiles = Deno.readdirSync("./cli/js/tests/")
.map(k => k.name)
.map((k) => k.name)
.filter(
file =>
(file) =>
file!.endsWith(".ts") &&
!file!.endsWith("unit_tests.ts") &&
!file!.endsWith("test_util.ts") &&
@ -344,12 +346,12 @@ unitTest(
const importLines = new TextDecoder("utf-8")
.decode(unitTestsFile)
.split("\n")
.filter(line => line.startsWith("import"));
.filter((line) => line.startsWith("import"));
const importedTestFiles = importLines.map(
relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)![1]
(relativeFilePath) => relativeFilePath.match(/\/([^\/]+)";/)![1]
);
directoryTestFiles.forEach(dirFile => {
directoryTestFiles.forEach((dirFile) => {
if (!importedTestFiles.includes(dirFile!)) {
throw new Error(
"cil/js/tests/unit_tests.ts is missing import of test file: cli/js/" +

View File

@ -18,7 +18,7 @@ unitTest(function nameOfTestCaseCantBeEmpty(): void {
() => {
Deno.test({
name: "",
fn: () => {}
fn: () => {},
});
},
TypeError,
@ -29,7 +29,7 @@ unitTest(function nameOfTestCaseCantBeEmpty(): void {
unitTest(function testFnCantBeAnonymous(): void {
assertThrows(
() => {
Deno.test(function() {});
Deno.test(function () {});
},
TypeError,
"The test function can't be anonymous"

View File

@ -21,7 +21,7 @@ unitTest(function atobWithAsciiWhitespace(): void {
"aGVsbG8gd29ybGQ=\n",
"aGVsbG\t8gd29ybGQ=",
`aGVsbG\t8g
d29ybGQ=`
d29ybGQ=`,
];
for (const encoded of encodedList) {

View File

@ -4,7 +4,7 @@ import {
createResolvable,
assert,
assertEquals,
assertNotEquals
assertNotEquals,
} from "./test_util.ts";
function deferred(): {
@ -23,7 +23,7 @@ function deferred(): {
return {
promise,
resolve: resolve!,
reject: reject!
reject: reject!,
};
}
@ -180,7 +180,7 @@ unitTest(async function timeoutCallbackThis(): Promise<void> {
foo(): void {
assertEquals(this, window);
resolve();
}
},
};
setTimeout(obj.foo, 1);
await promise;
@ -198,7 +198,7 @@ unitTest(async function timeoutBindThis(): Promise<void> {
[],
"foo",
(): void => {},
Object.prototype
Object.prototype,
];
for (const thisArg of thisCheckPassed) {
@ -240,7 +240,7 @@ unitTest(function clearTimeoutShouldConvertToNumber(): void {
valueOf(): number {
called = true;
return 1;
}
},
};
clearTimeout((obj as unknown) as number);
assert(called);

View File

@ -3,7 +3,7 @@ import {
assert,
assertEquals,
createResolvable,
unitTest
unitTest,
} from "./test_util.ts";
import { BufWriter, BufReader } from "../../../std/io/bufio.ts";
import { TextProtoReader } from "../../../std/textproto/mod.ts";
@ -28,7 +28,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> {
await Deno.connectTLS({
hostname: "github.com",
port: 443,
certFile: "cli/tests/tls/RootCA.crt"
certFile: "cli/tests/tls/RootCA.crt",
});
} catch (e) {
err = e;
@ -45,13 +45,13 @@ unitTest(
hostname: "localhost",
port: 4500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key"
keyFile: "cli/tests/tls/localhost.key",
};
try {
Deno.listenTLS({
...options,
certFile: "./non/existent/file"
certFile: "./non/existent/file",
});
} catch (e) {
err = e;
@ -61,7 +61,7 @@ unitTest(
try {
Deno.listenTLS({
...options,
keyFile: "./non/existent/file"
keyFile: "./non/existent/file",
});
} catch (e) {
err = e;
@ -77,7 +77,7 @@ unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void {
hostname: "localhost",
port: 4500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key"
keyFile: "cli/tests/tls/localhost.key",
});
} catch (e) {
err = e;
@ -88,7 +88,7 @@ unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void {
unitTest(
{
perms: { read: true, write: true, net: true }
perms: { read: true, write: true, net: true },
},
function listenTLSEmptyKeyFile(): void {
let err;
@ -96,19 +96,19 @@ unitTest(
hostname: "localhost",
port: 4500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key"
keyFile: "cli/tests/tls/localhost.key",
};
const testDir = Deno.makeTempDirSync();
const keyFilename = testDir + "/key.pem";
Deno.writeFileSync(keyFilename, new Uint8Array([]), {
mode: 0o666
mode: 0o666,
});
try {
Deno.listenTLS({
...options,
keyFile: keyFilename
keyFile: keyFilename,
});
} catch (e) {
err = e;
@ -125,19 +125,19 @@ unitTest(
hostname: "localhost",
port: 4500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key"
keyFile: "cli/tests/tls/localhost.key",
};
const testDir = Deno.makeTempDirSync();
const certFilename = testDir + "/cert.crt";
Deno.writeFileSync(certFilename, new Uint8Array([]), {
mode: 0o666
mode: 0o666,
});
try {
Deno.listenTLS({
...options,
certFile: certFilename
certFile: certFilename,
});
} catch (e) {
err = e;
@ -157,7 +157,7 @@ unitTest(
hostname,
port,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key"
keyFile: "cli/tests/tls/localhost.key",
});
const response = encoder.encode(
@ -180,7 +180,7 @@ unitTest(
const conn = await Deno.connectTLS({
hostname,
port,
certFile: "cli/tests/tls/RootCA.pem"
certFile: "cli/tests/tls/RootCA.pem",
});
assert(conn.rid > 0);
const w = new BufWriter(conn);

View File

@ -3,7 +3,7 @@ import { unitTest, assertEquals } from "./test_util.ts";
unitTest(
{
ignore: Deno.build.os === "win"
ignore: Deno.build.os === "win",
},
function umaskSuccess(): void {
const prevMask = Deno.umask(0o020);

View File

@ -8,7 +8,7 @@ import {
registerUnitTests,
SocketReporter,
fmtPerms,
parseArgs
parseArgs,
} from "./test_util.ts";
interface PermissionSetTestResult {
@ -27,7 +27,7 @@ const PERMISSIONS: Deno.PermissionName[] = [
"env",
"run",
"plugin",
"hrtime"
"hrtime",
];
/**
@ -69,7 +69,7 @@ async function workerRunnerMain(
failFast: false,
exitOnFail: false,
reporter: socketReporter,
only: filter
only: filter,
});
}
@ -93,7 +93,7 @@ function spawnWorkerRunner(
"cli/js/tests/unit_test_runner.ts",
"--worker",
`--addr=${addr}`,
`--perms=${permStr}`
`--perms=${permStr}`,
];
if (filter) {
@ -107,7 +107,7 @@ function spawnWorkerRunner(
cmd,
stdin: ioMode,
stdout: ioMode,
stderr: ioMode
stderr: ioMode,
});
return p;
@ -177,7 +177,7 @@ async function runTestsForPermissionSet(
permsStr: permsFmt,
duration: endEvent.duration,
stats: endEvent.stats,
results: endEvent.results
results: endEvent.results,
};
}
@ -223,7 +223,7 @@ async function masterRunnerMain(
kind: Deno.TestEvent.End,
stats,
duration,
results
results,
});
testsPassed = testsPassed && testResult.passed;
}
@ -288,7 +288,7 @@ function assertOrHelp(expr: unknown): asserts expr {
async function main(): Promise<void> {
const args = parseArgs(Deno.args, {
boolean: ["master", "worker", "verbose"],
"--": true
"--": true,
});
if (args.help) {
@ -315,7 +315,7 @@ async function main(): Promise<void> {
await Deno.runTests({
failFast: false,
exitOnFail: true,
only: filter
only: filter,
});
}

View File

@ -13,7 +13,7 @@ unitTest(function urlSearchParamsInitString(): void {
unitTest(function urlSearchParamsInitIterable(): void {
const init = [
["a", "54"],
["b", "true"]
["b", "true"],
];
const searchParams = new URLSearchParams(init);
assertEquals(searchParams.toString(), "a=54&b=true");
@ -94,7 +94,7 @@ unitTest(function urlSearchParamsSortSuccess(): void {
unitTest(function urlSearchParamsForEachSuccess(): void {
const init = [
["a", "54"],
["b", "true"]
["b", "true"],
];
const searchParams = new URLSearchParams(init);
let callNum = 0;
@ -225,7 +225,7 @@ unitTest(function urlSearchParamsDeletingAppendedMultiple(): void {
// ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js#L176-L182
unitTest(function urlSearchParamsCustomSymbolIterator(): void {
const params = new URLSearchParams();
params[Symbol.iterator] = function*(): IterableIterator<[string, string]> {
params[Symbol.iterator] = function* (): IterableIterator<[string, string]> {
yield ["a", "b"];
};
const params1 = new URLSearchParams((params as unknown) as string[][]);
@ -236,7 +236,7 @@ unitTest(
function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
const params = {};
// @ts-ignore
params[Symbol.iterator] = function*(): IterableIterator<[number, number]> {
params[Symbol.iterator] = function* (): IterableIterator<[number, number]> {
yield [1, 2];
};
const params1 = new URLSearchParams((params as unknown) as string[][]);

View File

@ -98,6 +98,12 @@ unitTest(function urlModifyHref(): void {
assertEquals(url.hash, "#qux");
});
unitTest(function urlNormalize(): void {
const url = new URL("http://example.com");
assertEquals(url.pathname, "/");
assertEquals(url.href, "http://example.com/");
});
unitTest(function urlModifyPathname(): void {
const url = new URL("http://foo.bar/baz%qat/qux%quux");
assertEquals(url.pathname, "/baz%qat/qux%quux");
@ -183,7 +189,7 @@ unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void {
unitTest(
{
// FIXME(bartlomieju)
ignore: true
ignore: true,
},
function customInspectFunction(): void {
const url = new URL("http://example.com/?");

View File

@ -15,7 +15,7 @@ unitTest(
const testDir = Deno.makeTempDirSync();
const filename = testDir + "/file.txt";
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
mode: 0o666
mode: 0o666,
});
const atime = 1000;
@ -115,7 +115,7 @@ unitTest(
const testDir = Deno.makeTempDirSync();
const filename = testDir + "/file.txt";
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
mode: 0o666
mode: 0o666,
});
const atime = 1000;

View File

@ -15,13 +15,13 @@ export async function connectTLS({
port,
hostname = "127.0.0.1",
transport = "tcp",
certFile = undefined
certFile = undefined,
}: ConnectTLSOptions): Promise<Conn> {
const res = await tlsOps.connectTLS({
port,
hostname,
transport,
certFile
certFile,
});
return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!);
}
@ -46,14 +46,14 @@ export function listenTLS({
certFile,
keyFile,
hostname = "0.0.0.0",
transport = "tcp"
transport = "tcp",
}: ListenTLSOptions): Listener {
const res = tlsOps.listenTLS({
port,
certFile,
keyFile,
hostname,
transport
transport,
});
return new TLSListenerImpl(res.rid, res.localAddr);
}

View File

@ -67,6 +67,6 @@ export function immutableDefine(
Object.defineProperty(o, p, {
value,
configurable: false,
writable: false
writable: false,
});
}

View File

@ -8,7 +8,7 @@ interface Version {
export const version: Version = {
deno: "",
v8: "",
typescript: ""
typescript: "",
};
export function setVersions(

View File

@ -124,12 +124,8 @@ function processBlobParts(
return bytes;
}
// A WeakMap holding blob to byte array mapping.
// Ensures it does not impact garbage collection.
export const blobBytesWeakMap = new WeakMap<domTypes.Blob, Uint8Array>();
export class DenoBlob implements domTypes.Blob {
private readonly [bytesSymbol]: Uint8Array;
[bytesSymbol]: Uint8Array;
readonly size: number = 0;
readonly type: string = "";
@ -165,14 +161,11 @@ export class DenoBlob implements domTypes.Blob {
this[bytesSymbol] = bytes;
this.size = bytes.byteLength;
this.type = normalizedType;
// Register bytes for internal private use.
blobBytesWeakMap.set(this, bytes);
}
slice(start?: number, end?: number, contentType?: string): DenoBlob {
return new DenoBlob([this[bytesSymbol].slice(start, end)], {
type: contentType || this.type
type: contentType || this.type,
});
}
}

View File

@ -124,7 +124,7 @@ export const BodyUsedError =
"Failed to execute 'clone' on 'Body': body is already used";
export class Body implements domTypes.Body {
protected _stream: domTypes.ReadableStream | null;
protected _stream: domTypes.ReadableStream<string | ArrayBuffer> | null;
constructor(protected _bodySource: BodySource, readonly contentType: string) {
validateBodyType(this, _bodySource);
@ -148,8 +148,8 @@ export class Body implements domTypes.Body {
start(controller: ReadableStreamController): void {
controller.enqueue(bodySource);
controller.close();
}
});
},
}) as domTypes.ReadableStream<ArrayBuffer | string>;
}
return this._stream;
}
@ -247,7 +247,7 @@ export class Body implements domTypes.Body {
if (dispositionParams.has("filename")) {
const filename = dispositionParams.get("filename")!;
const blob = new DenoBlob([enc.encode(octets)], {
type: partContentType
type: partContentType,
});
// TODO: based on spec
// https://xhr.spec.whatwg.org/#dom-formdata-append

View File

@ -174,7 +174,7 @@ function createArrayString(
displayName: "",
delims: ["[", "]"],
entryHandler: (el, ctx, level, maxLevel): string =>
stringifyWithQuotes(el, ctx, level + 1, maxLevel)
stringifyWithQuotes(el, ctx, level + 1, maxLevel),
};
return createIterableString(value, ctx, level, maxLevel, printConfig);
}
@ -191,7 +191,7 @@ function createTypedArrayString(
displayName: typedArrayName,
delims: ["[", "]"],
entryHandler: (el, ctx, level, maxLevel): string =>
stringifyWithQuotes(el, ctx, level + 1, maxLevel)
stringifyWithQuotes(el, ctx, level + 1, maxLevel),
};
return createIterableString(value, ctx, level, maxLevel, printConfig);
}
@ -207,7 +207,7 @@ function createSetString(
displayName: "Set",
delims: ["{", "}"],
entryHandler: (el, ctx, level, maxLevel): string =>
stringifyWithQuotes(el, ctx, level + 1, maxLevel)
stringifyWithQuotes(el, ctx, level + 1, maxLevel),
};
return createIterableString(value, ctx, level, maxLevel, printConfig);
}
@ -230,7 +230,7 @@ function createMapString(
level + 1,
maxLevel
)} => ${stringifyWithQuotes(val, ctx, level + 1, maxLevel)}`;
}
},
};
return createIterableString(value, ctx, level, maxLevel, printConfig);
}
@ -494,10 +494,12 @@ const timerMap = new Map<string, number>();
const isConsoleInstance = Symbol("isConsoleInstance");
export class Console {
#printFunc: PrintFunc;
indentLevel: number;
[isConsoleInstance] = false;
constructor(private printFunc: PrintFunc) {
constructor(printFunc: PrintFunc) {
this.#printFunc = printFunc;
this.indentLevel = 0;
this[isConsoleInstance] = true;
@ -511,9 +513,9 @@ export class Console {
}
log = (...args: unknown[]): void => {
this.printFunc(
this.#printFunc(
stringifyArgs(args, {
indentLevel: this.indentLevel
indentLevel: this.indentLevel,
}) + "\n",
false
);
@ -523,15 +525,15 @@ export class Console {
info = this.log;
dir = (obj: unknown, options: InspectOptions = {}): void => {
this.printFunc(stringifyArgs([obj], options) + "\n", false);
this.#printFunc(stringifyArgs([obj], options) + "\n", false);
};
dirxml = this.dir;
warn = (...args: unknown[]): void => {
this.printFunc(
this.#printFunc(
stringifyArgs(args, {
indentLevel: this.indentLevel
indentLevel: this.indentLevel,
}) + "\n",
true
);
@ -604,7 +606,7 @@ export class Console {
this.log(cliTable(header, body));
const createColumn = (value: unknown, shift?: number): string[] => [
...(shift ? [...new Array(shift)].map((): string => "") : []),
stringifyValue(value)
stringifyValue(value),
];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -660,8 +662,8 @@ export class Console {
indexKey,
...(properties || [
...headerKeys,
!isMap && values.length > 0 && valuesKey
])
!isMap && values.length > 0 && valuesKey,
]),
].filter(Boolean) as string[];
const body = [indexKeys, ...bodyValues, values];
@ -733,7 +735,7 @@ export class Console {
const message = stringifyArgs(args, { indentLevel: 0 });
const err = {
name: "Trace",
message
message,
};
// @ts-ignore
Error.captureStackTrace(err, this.trace);

View File

@ -19,7 +19,7 @@ const tableChars = {
rightMiddle: "┤",
left: "│ ",
right: " │",
middle: " │ "
middle: " │ ",
};
const colorRegExp = /\u001b\[\d\d?m/g;

View File

@ -1,32 +1,31 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types.ts";
import * as event from "./event.ts";
import { getPrivateValue, requiredArguments } from "./util.ts";
// WeakMaps are recommended for private attributes (see MDN link below)
// https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/Guides/Contributor_s_Guide/Private_Properties#Using_WeakMaps
export const customEventAttributes = new WeakMap();
import { requiredArguments } from "./util.ts";
export class CustomEvent extends event.Event implements domTypes.CustomEvent {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
#detail: any;
constructor(
type: string,
customEventInitDict: domTypes.CustomEventInit = {}
) {
requiredArguments("CustomEvent", arguments.length, 1);
super(type, customEventInitDict);
requiredArguments("CustomEvent", arguments.length, 1);
const { detail = null } = customEventInitDict;
customEventAttributes.set(this, { detail });
this.#detail = detail;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get detail(): any {
return getPrivateValue(this, customEventAttributes, "detail");
return this.#detail;
}
initCustomEvent(
type: string,
bubbles?: boolean,
cancelable?: boolean,
_type: string,
_bubbles?: boolean,
_cancelable?: boolean,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
detail?: any
): void {
@ -34,7 +33,7 @@ export class CustomEvent extends event.Event implements domTypes.CustomEvent {
return;
}
customEventAttributes.set(this, { detail });
this.#detail = detail;
}
get [Symbol.toStringTag](): string {

View File

@ -72,7 +72,7 @@ export function DomIterableMixin<K, V, TBase extends Constructor>(
// we want the Base class name to be the name of the class.
Object.defineProperty(DomIterable, "name", {
value: Base.name,
configurable: true
configurable: true,
});
return DomIterable;

View File

@ -68,7 +68,7 @@ interface AbortSignalEventMap {
export enum NodeType {
ELEMENT_NODE = 1,
TEXT_NODE = 3,
DOCUMENT_FRAGMENT_NODE = 11
DOCUMENT_FRAGMENT_NODE = 11,
}
export const eventTargetHost: unique symbol = Symbol();
@ -153,7 +153,7 @@ export enum EventPhase {
NONE = 0,
CAPTURING_PHASE = 1,
AT_TARGET = 2,
BUBBLING_PHASE = 3
BUBBLING_PHASE = 3,
}
export interface EventPath {
@ -280,7 +280,7 @@ export interface Blob {
}
export interface Body {
readonly body: ReadableStream | null;
readonly body: ReadableStream<Uint8Array> | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
@ -289,11 +289,78 @@ export interface Body {
text(): Promise<string>;
}
export interface ReadableStream {
export interface ReadableStreamReadDoneResult<T> {
done: true;
value?: T;
}
export interface ReadableStreamReadValueResult<T> {
done: false;
value: T;
}
export type ReadableStreamReadResult<T> =
| ReadableStreamReadValueResult<T>
| ReadableStreamReadDoneResult<T>;
export interface ReadableStreamDefaultReader<R = any> {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void;
}
export interface PipeOptions {
preventAbort?: boolean;
preventCancel?: boolean;
preventClose?: boolean;
signal?: AbortSignal;
}
export interface ReadableStream<R = any> {
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
getReader(): ReadableStreamReader;
tee(): ReadableStream[];
getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
getReader(): ReadableStreamDefaultReader<R>;
/* disabled for now
pipeThrough<T>(
{
writable,
readable
}: {
writable: WritableStream<R>;
readable: ReadableStream<T>;
},
options?: PipeOptions
): ReadableStream<T>;
pipeTo(dest: WritableStream<R>, options?: PipeOptions): Promise<void>;
*/
tee(): [ReadableStream<R>, ReadableStream<R>];
}
export interface ReadableStreamBYOBReader {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
read<T extends ArrayBufferView>(
view: T
): Promise<ReadableStreamReadResult<T>>;
releaseLock(): void;
}
export interface WritableStream<W = any> {
readonly locked: boolean;
abort(reason?: any): Promise<void>;
getWriter(): WritableStreamDefaultWriter<W>;
}
export interface WritableStreamDefaultWriter<W = any> {
readonly closed: Promise<void>;
readonly desiredSize: number | null;
readonly ready: Promise<void>;
abort(reason?: any): Promise<void>;
close(): Promise<void>;
releaseLock(): void;
write(chunk: W): Promise<void>;
}
export interface UnderlyingSource<R = any> {
@ -311,9 +378,9 @@ export interface UnderlyingByteSource {
type: "bytes";
}
export interface ReadableStreamReader {
cancel(reason?: any): Promise<void>;
read(): Promise<any>;
export interface ReadableStreamReader<R = any> {
cancel(reason: any): Promise<void>;
read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void;
}
@ -530,12 +597,20 @@ export interface Response extends Body {
clone(): Response;
}
export interface DOMStringList {
readonly length: number;
contains(string: string): boolean;
item(index: number): string | null;
[index: number]: string;
}
export interface Location {
readonly ancestorOrigins: string[];
readonly ancestorOrigins: DOMStringList;
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
pathname: string;
port: string;
@ -543,6 +618,72 @@ export interface Location {
search: string;
assign(url: string): void;
reload(): void;
reload(forcedReload: boolean): void;
replace(url: string): void;
}
export interface URL {
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
}
export interface URLSearchParams {
/**
* Appends a specified key/value pair as a new search parameter.
*/
append(name: string, value: string): void;
/**
* Deletes the given search parameter, and its associated value, from the list of all search parameters.
*/
delete(name: string): void;
/**
* Returns the first value associated to the given search parameter.
*/
get(name: string): string | null;
/**
* Returns all the values association with a given search parameter.
*/
getAll(name: string): string[];
/**
* Returns a Boolean indicating if such a search parameter exists.
*/
has(name: string): boolean;
/**
* Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
*/
set(name: string, value: string): void;
sort(): void;
/**
* Returns a string containing a query string suitable for use in a URL. Does not include the question mark.
*/
toString(): string;
forEach(
callbackfn: (value: string, key: string, parent: URLSearchParams) => void,
thisArg?: any
): void;
[Symbol.iterator](): IterableIterator<[string, string]>;
/**
* Returns an array of key, value pairs for every entry in the search params.
*/
entries(): IterableIterator<[string, string]>;
/**
* Returns a list of keys in the search params.
*/
keys(): IterableIterator<string>;
/**
* Returns a list of values in the search params.
*/
values(): IterableIterator<string>;
}

View File

@ -2,6 +2,23 @@
// Utility functions for DOM nodes
import * as domTypes from "./dom_types.ts";
export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
Object.defineProperties(arr, {
contains: {
value(searchElement: string): boolean {
return arr.includes(searchElement);
},
enumerable: true,
},
item: {
value(idx: number): string | null {
return idx in arr ? arr[idx] : null;
},
},
});
return (arr as unknown) as domTypes.DOMStringList;
}
export function isNode(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(nodeImpl && "nodeType" in nodeImpl);
}

View File

@ -39,11 +39,11 @@ export class Event implements domTypes.Event {
isTrusted: false,
relatedTarget: null,
target: null,
timeStamp: Date.now()
timeStamp: Date.now(),
});
Reflect.defineProperty(this, "isTrusted", {
enumerable: true,
get: isTrusted
get: isTrusted,
});
}
@ -90,7 +90,7 @@ export class Event implements domTypes.Event {
isTrusted: this.isTrusted,
relatedTarget: this.relatedTarget,
target: this.target,
timeStamp: this.timeStamp
timeStamp: this.timeStamp,
});
}
@ -121,7 +121,7 @@ export class Event implements domTypes.Event {
isTrusted: this.isTrusted,
relatedTarget: this.relatedTarget,
target: this.target,
timeStamp: this.timeStamp
timeStamp: this.timeStamp,
});
}
@ -156,7 +156,7 @@ export class Event implements domTypes.Event {
isTrusted: this.isTrusted,
relatedTarget: value,
target: this.target,
timeStamp: this.timeStamp
timeStamp: this.timeStamp,
});
}
@ -175,7 +175,7 @@ export class Event implements domTypes.Event {
isTrusted: this.isTrusted,
relatedTarget: this.relatedTarget,
target: value,
timeStamp: this.timeStamp
timeStamp: this.timeStamp,
});
}
@ -200,8 +200,8 @@ export class Event implements domTypes.Event {
rootOfClosedTree: false,
slotInClosedTree: false,
target: null,
touchTargetList: []
}
touchTargetList: [],
},
];
let currentTargetIndex = 0;
@ -242,7 +242,7 @@ export class Event implements domTypes.Event {
rootOfClosedTree: false,
slotInClosedTree: false,
target: null,
touchTargetList: []
touchTargetList: [],
});
}
@ -277,7 +277,7 @@ export class Event implements domTypes.Event {
rootOfClosedTree: false,
slotInClosedTree: false,
target: null,
touchTargetList: []
touchTargetList: [],
});
}
@ -314,7 +314,7 @@ Reflect.defineProperty(Event.prototype, "cancelable", { enumerable: true });
Reflect.defineProperty(Event.prototype, "composed", { enumerable: true });
Reflect.defineProperty(Event.prototype, "currentTarget", { enumerable: true });
Reflect.defineProperty(Event.prototype, "defaultPrevented", {
enumerable: true
enumerable: true,
});
Reflect.defineProperty(Event.prototype, "dispatched", { enumerable: true });
Reflect.defineProperty(Event.prototype, "eventPhase", { enumerable: true });

View File

@ -7,7 +7,7 @@ import {
isShadowRoot,
isShadowInclusiveAncestor,
isSlotable,
retarget
retarget,
} from "./dom_util.ts";
// https://dom.spec.whatwg.org/#get-the-parent
@ -70,7 +70,7 @@ export class EventTarget implements domTypes.EventTarget {
listeners[type].push({
callback,
options: normalizedOptions
options: normalizedOptions,
});
}
@ -438,7 +438,7 @@ const eventTargetHelpers = {
const returnValue: domTypes.AddEventListenerOptions = {
capture: Boolean(options),
once: false,
passive: false
passive: false,
};
return returnValue;
@ -452,7 +452,7 @@ const eventTargetHelpers = {
): domTypes.EventListenerOptions {
if (typeof options === "boolean" || typeof options === "undefined") {
const returnValue: domTypes.EventListenerOptions = {
capture: Boolean(options)
capture: Boolean(options),
};
return returnValue;
@ -481,17 +481,17 @@ const eventTargetHelpers = {
relatedTarget,
touchTargetList: touchTargets,
rootOfClosedTree,
slotInClosedTree
slotInClosedTree,
});
}
},
};
Reflect.defineProperty(EventTarget.prototype, "addEventListener", {
enumerable: true
enumerable: true,
});
Reflect.defineProperty(EventTarget.prototype, "removeEventListener", {
enumerable: true
enumerable: true,
});
Reflect.defineProperty(EventTarget.prototype, "dispatchEvent", {
enumerable: true
enumerable: true,
});

View File

@ -32,53 +32,58 @@ function hasHeaderValueOf(s: string, value: string): boolean {
return new RegExp(`^${value}[\t\s]*;?`).test(s);
}
class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
private _bodyUsed = false;
private _bodyPromise: null | Promise<ArrayBuffer> = null;
private _data: ArrayBuffer | null = null;
class Body
implements domTypes.Body, domTypes.ReadableStream<Uint8Array>, io.ReadCloser {
#bodyUsed = false;
#bodyPromise: Promise<ArrayBuffer> | null = null;
#data: ArrayBuffer | null = null;
#rid: number;
readonly locked: boolean = false; // TODO
readonly body: null | Body = this;
readonly body: domTypes.ReadableStream<Uint8Array>;
constructor(private rid: number, readonly contentType: string) {}
constructor(rid: number, readonly contentType: string) {
this.#rid = rid;
this.body = this;
}
private async _bodyBuffer(): Promise<ArrayBuffer> {
assert(this._bodyPromise == null);
#bodyBuffer = async (): Promise<ArrayBuffer> => {
assert(this.#bodyPromise == null);
const buf = new Buffer();
try {
const nread = await buf.readFrom(this);
const ui8 = buf.bytes();
assert(ui8.byteLength === nread);
this._data = ui8.buffer.slice(
this.#data = ui8.buffer.slice(
ui8.byteOffset,
ui8.byteOffset + nread
) as ArrayBuffer;
assert(this._data.byteLength === nread);
assert(this.#data.byteLength === nread);
} finally {
this.close();
}
return this._data;
}
return this.#data;
};
// eslint-disable-next-line require-await
async arrayBuffer(): Promise<ArrayBuffer> {
// If we've already bufferred the response, just return it.
if (this._data != null) {
return this._data;
if (this.#data != null) {
return this.#data;
}
// If there is no _bodyPromise yet, start it.
if (this._bodyPromise == null) {
this._bodyPromise = this._bodyBuffer();
if (this.#bodyPromise == null) {
this.#bodyPromise = this.#bodyBuffer();
}
return this._bodyPromise;
return this.#bodyPromise;
}
async blob(): Promise<domTypes.Blob> {
const arrayBuffer = await this.arrayBuffer();
return new DenoBlob([arrayBuffer], {
type: this.contentType
type: this.contentType,
});
}
@ -164,7 +169,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
if (dispositionParams.has("filename")) {
const filename = dispositionParams.get("filename")!;
const blob = new DenoBlob([enc.encode(octets)], {
type: partContentType
type: partContentType,
});
// TODO: based on spec
// https://xhr.spec.whatwg.org/#dom-formdata-append
@ -220,12 +225,12 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
}
read(p: Uint8Array): Promise<number | io.EOF> {
this._bodyUsed = true;
return read(this.rid, p);
this.#bodyUsed = true;
return read(this.#rid, p);
}
close(): Promise<void> {
close(this.rid);
close(this.#rid);
return Promise.resolve();
}
@ -233,7 +238,11 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
return notImplemented();
}
getReader(): domTypes.ReadableStreamReader {
getReader(options: { mode: "byob" }): domTypes.ReadableStreamBYOBReader;
getReader(): domTypes.ReadableStreamDefaultReader<Uint8Array>;
getReader():
| domTypes.ReadableStreamBYOBReader
| domTypes.ReadableStreamDefaultReader<Uint8Array> {
return notImplemented();
}
@ -246,7 +255,24 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
}
get bodyUsed(): boolean {
return this._bodyUsed;
return this.#bodyUsed;
}
pipeThrough<T>(
_: {
writable: domTypes.WritableStream<Uint8Array>;
readable: domTypes.ReadableStream<T>;
},
_options?: domTypes.PipeOptions
): domTypes.ReadableStream<T> {
return notImplemented();
}
pipeTo(
_dest: domTypes.WritableStream<Uint8Array>,
_options?: domTypes.PipeOptions
): Promise<void> {
return notImplemented();
}
}
@ -255,7 +281,7 @@ export class Response implements domTypes.Response {
readonly redirected: boolean;
headers: domTypes.Headers;
readonly trailer: Promise<domTypes.Headers>;
readonly body: null | Body;
readonly body: Body | null;
constructor(
readonly url: string,
@ -308,7 +334,7 @@ export class Response implements domTypes.Response {
"Content-Type",
"Expires",
"Last-Modified",
"Pragma"
"Pragma",
].map((c: string) => c.toLowerCase());
for (const h of this.headers) {
/* Technically this is still not standards compliant because we are
@ -337,35 +363,36 @@ export class Response implements domTypes.Response {
this.redirected = redirected_;
}
private bodyViewable(): boolean {
#bodyViewable = (): boolean => {
if (
this.type == "error" ||
this.type == "opaque" ||
this.type == "opaqueredirect" ||
this.body == undefined
)
) {
return true;
}
return false;
}
};
arrayBuffer(): Promise<ArrayBuffer> {
/* You have to do the null check here and not in the function because
* otherwise TS complains about this.body potentially being null */
if (this.bodyViewable() || this.body == null) {
if (this.#bodyViewable() || this.body == null) {
return Promise.reject(new Error("Response body is null"));
}
return this.body.arrayBuffer();
}
blob(): Promise<domTypes.Blob> {
if (this.bodyViewable() || this.body == null) {
if (this.#bodyViewable() || this.body == null) {
return Promise.reject(new Error("Response body is null"));
}
return this.body.blob();
}
formData(): Promise<domTypes.FormData> {
if (this.bodyViewable() || this.body == null) {
if (this.#bodyViewable() || this.body == null) {
return Promise.reject(new Error("Response body is null"));
}
return this.body.formData();
@ -373,14 +400,14 @@ export class Response implements domTypes.Response {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
json(): Promise<any> {
if (this.bodyViewable() || this.body == null) {
if (this.#bodyViewable() || this.body == null) {
return Promise.reject(new Error("Response body is null"));
}
return this.body.json();
}
text(): Promise<string> {
if (this.bodyViewable() || this.body == null) {
if (this.#bodyViewable() || this.body == null) {
return Promise.reject(new Error("Response body is null"));
}
return this.body.text();
@ -453,7 +480,7 @@ function sendFetchReq(
const args = {
method,
url,
headers: headerArray
headers: headerArray,
};
return opFetch(args, body);
@ -527,8 +554,9 @@ export async function fetch(
}
part += "\r\n";
if (fieldValue instanceof DomFileImpl) {
part += `Content-Type: ${fieldValue.type ||
"application/octet-stream"}\r\n`;
part += `Content-Type: ${
fieldValue.type || "application/octet-stream"
}\r\n`;
}
part += "\r\n";
if (fieldValue instanceof DomFileImpl) {

View File

@ -8,7 +8,7 @@ import { requiredArguments } from "./util.ts";
const dataSymbol = Symbol("data");
class FormDataBase {
private [dataSymbol]: Array<[string, domTypes.FormDataEntryValue]> = [];
[dataSymbol]: Array<[string, domTypes.FormDataEntryValue]> = [];
append(name: string, value: string): void;
append(name: string, value: blob.DenoBlob, filename?: string): void;
@ -17,7 +17,7 @@ class FormDataBase {
name = String(name);
if (value instanceof blob.DenoBlob) {
const dfile = new domFile.DomFileImpl([value], filename || name, {
type: value.type
type: value.type,
});
this[dataSymbol].push([name, dfile]);
} else {
@ -84,7 +84,7 @@ class FormDataBase {
if (!found) {
if (value instanceof blob.DenoBlob) {
const dfile = new domFile.DomFileImpl([value], filename || name, {
type: value.type
type: value.type,
});
this[dataSymbol][i][1] = dfile;
} else {
@ -103,7 +103,7 @@ class FormDataBase {
if (!found) {
if (value instanceof blob.DenoBlob) {
const dfile = new domFile.DomFileImpl([value], filename || name, {
type: value.type
type: value.type,
});
this[dataSymbol].push([name, dfile]);
} else {

View File

@ -17,32 +17,32 @@ function isHeaders(value: any): value is domTypes.Headers {
const headerMap = Symbol("header map");
// TODO: headerGuard? Investigate if it is needed
// node-fetch did not implement this but it is in the spec
function normalizeParams(name: string, value?: string): string[] {
name = String(name).toLowerCase();
value = String(value).trim();
return [name, value];
}
// The following name/value validations are copied from
// https://github.com/bitinn/node-fetch/blob/master/src/headers.js
// Copyright (c) 2016 David Frank. MIT License.
function validateName(name: string): void {
if (invalidTokenRegex.test(name) || name === "") {
throw new TypeError(`${name} is not a legal HTTP header name`);
}
}
function validateValue(value: string): void {
if (invalidHeaderCharRegex.test(value)) {
throw new TypeError(`${value} is not a legal HTTP header value`);
}
}
// ref: https://fetch.spec.whatwg.org/#dom-headers
class HeadersBase {
private [headerMap]: Map<string, string>;
// TODO: headerGuard? Investigate if it is needed
// node-fetch did not implement this but it is in the spec
private _normalizeParams(name: string, value?: string): string[] {
name = String(name).toLowerCase();
value = String(value).trim();
return [name, value];
}
// The following name/value validations are copied from
// https://github.com/bitinn/node-fetch/blob/master/src/headers.js
// Copyright (c) 2016 David Frank. MIT License.
private _validateName(name: string): void {
if (invalidTokenRegex.test(name) || name === "") {
throw new TypeError(`${name} is not a legal HTTP header name`);
}
}
private _validateValue(value: string): void {
if (invalidHeaderCharRegex.test(value)) {
throw new TypeError(`${value} is not a legal HTTP header value`);
}
}
[headerMap]: Map<string, string>;
constructor(init?: domTypes.HeadersInit) {
if (init === null) {
@ -64,9 +64,9 @@ class HeadersBase {
2
);
const [name, value] = this._normalizeParams(tuple[0], tuple[1]);
this._validateName(name);
this._validateValue(value);
const [name, value] = normalizeParams(tuple[0], tuple[1]);
validateName(name);
validateValue(value);
const existingValue = this[headerMap].get(name);
this[headerMap].set(
name,
@ -77,9 +77,9 @@ class HeadersBase {
const names = Object.keys(init);
for (const rawName of names) {
const rawValue = init[rawName];
const [name, value] = this._normalizeParams(rawName, rawValue);
this._validateName(name);
this._validateValue(value);
const [name, value] = normalizeParams(rawName, rawValue);
validateName(name);
validateValue(value);
this[headerMap].set(name, value);
}
}
@ -101,9 +101,9 @@ class HeadersBase {
// ref: https://fetch.spec.whatwg.org/#concept-headers-append
append(name: string, value: string): void {
requiredArguments("Headers.append", arguments.length, 2);
const [newname, newvalue] = this._normalizeParams(name, value);
this._validateName(newname);
this._validateValue(newvalue);
const [newname, newvalue] = normalizeParams(name, value);
validateName(newname);
validateValue(newvalue);
const v = this[headerMap].get(newname);
const str = v ? `${v}, ${newvalue}` : newvalue;
this[headerMap].set(newname, str);
@ -111,31 +111,31 @@ class HeadersBase {
delete(name: string): void {
requiredArguments("Headers.delete", arguments.length, 1);
const [newname] = this._normalizeParams(name);
this._validateName(newname);
const [newname] = normalizeParams(name);
validateName(newname);
this[headerMap].delete(newname);
}
get(name: string): string | null {
requiredArguments("Headers.get", arguments.length, 1);
const [newname] = this._normalizeParams(name);
this._validateName(newname);
const [newname] = normalizeParams(name);
validateName(newname);
const value = this[headerMap].get(newname);
return value || null;
}
has(name: string): boolean {
requiredArguments("Headers.has", arguments.length, 1);
const [newname] = this._normalizeParams(name);
this._validateName(newname);
const [newname] = normalizeParams(name);
validateName(newname);
return this[headerMap].has(newname);
}
set(name: string, value: string): void {
requiredArguments("Headers.set", arguments.length, 2);
const [newname, newvalue] = this._normalizeParams(name, value);
this._validateName(newname);
this._validateValue(newvalue);
const [newname, newvalue] = normalizeParams(name, value);
validateName(newname);
validateValue(newvalue);
this[headerMap].set(newname, newvalue);
}

View File

@ -1,12 +1,15 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { URL } from "./url.ts";
import { notImplemented } from "../util.ts";
import { Location } from "./dom_types.ts";
import { DOMStringList, Location } from "./dom_types.ts";
import { getDOMStringList } from "./dom_util.ts";
export class LocationImpl implements Location {
#url: URL;
constructor(url: string) {
const u = new URL(url);
this.url = u;
this.#url = u;
this.hash = u.hash;
this.host = u.host;
this.href = u.href;
@ -18,13 +21,11 @@ export class LocationImpl implements Location {
this.search = u.search;
}
private url: URL;
toString(): string {
return this.url.toString();
return this.#url.toString();
}
readonly ancestorOrigins: string[] = [];
readonly ancestorOrigins: DOMStringList = getDOMStringList([]);
hash: string;
host: string;
hostname: string;
@ -45,6 +46,8 @@ export class LocationImpl implements Location {
}
}
/** Sets the `window.location` at runtime.
* @internal */
export function setLocation(url: string): void {
globalThis.location = new LocationImpl(url);
Object.freeze(globalThis.location);

View File

@ -136,7 +136,7 @@ export class Request extends body.Body implements domTypes.Request {
body: body2,
method: this.method,
headers: new Headers(headersList),
credentials: this.credentials
credentials: this.credentials,
});
return cloned;
}

View File

@ -148,7 +148,7 @@ export class ReadableByteStreamController
bytesFilled: 0,
elementSize: 1,
ctor: Uint8Array,
readerType: "default"
readerType: "default",
};
this[rs.pendingPullIntos_].push(pullIntoDescriptor);
}

View File

@ -10,7 +10,7 @@ import {
QueuingStrategy,
QueuingStrategySizeCallback,
UnderlyingSource,
UnderlyingByteSource
UnderlyingByteSource,
} from "../dom_types.ts";
// ReadableStreamDefaultController
@ -345,7 +345,7 @@ export function readableStreamCancel<OutputType>(
const sourceCancelPromise = stream[readableStreamController_][cancelSteps_](
reason
);
return sourceCancelPromise.then(_ => undefined);
return sourceCancelPromise.then((_) => undefined);
}
export function readableStreamClose<OutputType>(
@ -558,13 +558,13 @@ export function setUpReadableStreamDefaultController<OutputType>(
const startResult = startAlgorithm();
Promise.resolve(startResult).then(
_ => {
(_) => {
controller[started_] = true;
// Assert: controller.[[pulling]] is false.
// Assert: controller.[[pullAgain]] is false.
readableStreamDefaultControllerCallPullIfNeeded(controller);
},
error => {
(error) => {
readableStreamDefaultControllerError(controller, error);
}
);
@ -678,14 +678,14 @@ export function readableStreamDefaultControllerCallPullIfNeeded<OutputType>(
controller[pulling_] = true;
controller[pullAlgorithm_](controller).then(
_ => {
(_) => {
controller[pulling_] = false;
if (controller[pullAgain_]) {
controller[pullAgain_] = false;
readableStreamDefaultControllerCallPullIfNeeded(controller);
}
},
error => {
(error) => {
readableStreamDefaultControllerError(controller, error);
}
);
@ -768,13 +768,13 @@ export function setUpReadableByteStreamController(
// Let startResult be the result of performing startAlgorithm.
const startResult = startAlgorithm();
Promise.resolve(startResult).then(
_ => {
(_) => {
controller[started_] = true;
// Assert: controller.[[pulling]] is false.
// Assert: controller.[[pullAgain]] is false.
readableByteStreamControllerCallPullIfNeeded(controller);
},
error => {
(error) => {
readableByteStreamControllerError(controller, error);
}
);
@ -811,14 +811,14 @@ export function readableByteStreamControllerCallPullIfNeeded(
// Assert: controller.[[pullAgain]] is false.
controller[pulling_] = true;
controller[pullAlgorithm_](controller).then(
_ => {
(_) => {
controller[pulling_] = false;
if (controller[pullAgain_]) {
controller[pullAgain_] = false;
readableByteStreamControllerCallPullIfNeeded(controller);
}
},
error => {
(error) => {
readableByteStreamControllerError(controller, error);
}
);
@ -1122,7 +1122,7 @@ export function readableByteStreamControllerPullInto(
bytesFilled: 0,
elementSize,
ctor,
readerType: "byob"
readerType: "byob",
};
if (controller[pendingPullIntos_].length > 0) {

Some files were not shown because too many files have changed in this diff Show More