mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
Update to TypeScript 3.7 (#3275)
and update to prettier 1.19 Also, update `assert()` and remove not null assertions where possibly in `cli`. Closes #3273
This commit is contained in:
parent
279191ad94
commit
9837d324a7
80 changed files with 980 additions and 1153 deletions
|
@ -72,41 +72,35 @@ function concatenate(...arrays: Uint8Array[]): ArrayBuffer {
|
|||
}
|
||||
|
||||
function bufferFromStream(stream: ReadableStreamReader): Promise<ArrayBuffer> {
|
||||
return new Promise(
|
||||
(resolve, reject): void => {
|
||||
const parts: Uint8Array[] = [];
|
||||
const encoder = new TextEncoder();
|
||||
// recurse
|
||||
(function pump(): void {
|
||||
stream
|
||||
.read()
|
||||
.then(
|
||||
({ done, value }): void => {
|
||||
if (done) {
|
||||
return resolve(concatenate(...parts));
|
||||
}
|
||||
return new Promise((resolve, reject): void => {
|
||||
const parts: Uint8Array[] = [];
|
||||
const encoder = new TextEncoder();
|
||||
// recurse
|
||||
(function pump(): void {
|
||||
stream
|
||||
.read()
|
||||
.then(({ done, value }): void => {
|
||||
if (done) {
|
||||
return resolve(concatenate(...parts));
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
parts.push(encoder.encode(value));
|
||||
} else if (value instanceof ArrayBuffer) {
|
||||
parts.push(new Uint8Array(value));
|
||||
} else if (!value) {
|
||||
// noop for undefined
|
||||
} else {
|
||||
reject("unhandled type on stream read");
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
parts.push(encoder.encode(value));
|
||||
} else if (value instanceof ArrayBuffer) {
|
||||
parts.push(new Uint8Array(value));
|
||||
} else if (!value) {
|
||||
// noop for undefined
|
||||
} else {
|
||||
reject("unhandled type on stream read");
|
||||
}
|
||||
|
||||
return pump();
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err): void => {
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
})();
|
||||
}
|
||||
);
|
||||
return pump();
|
||||
})
|
||||
.catch((err): void => {
|
||||
reject(err);
|
||||
});
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
function getHeaderValueParams(value: string): Map<string, string> {
|
||||
|
@ -275,19 +269,17 @@ export class Body implements domTypes.Body {
|
|||
body
|
||||
.trim()
|
||||
.split("&")
|
||||
.forEach(
|
||||
(bytes): void => {
|
||||
if (bytes) {
|
||||
const split = bytes.split("=");
|
||||
const name = split.shift()!.replace(/\+/g, " ");
|
||||
const value = split.join("=").replace(/\+/g, " ");
|
||||
formData.append(
|
||||
decodeURIComponent(name),
|
||||
decodeURIComponent(value)
|
||||
);
|
||||
}
|
||||
.forEach((bytes): void => {
|
||||
if (bytes) {
|
||||
const split = bytes.split("=");
|
||||
const name = split.shift()!.replace(/\+/g, " ");
|
||||
const value = split.join("=").replace(/\+/g, " ");
|
||||
formData.append(
|
||||
decodeURIComponent(name),
|
||||
decodeURIComponent(value)
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
throw new TypeError("Invalid form urlencoded format");
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ type CompilerRequest = {
|
|||
| {
|
||||
type: CompilerRequestType.Bundle;
|
||||
outFile?: string;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
interface ConfigureResponse {
|
||||
ignoredOptions?: string[];
|
||||
|
@ -186,11 +187,7 @@ class SourceFile {
|
|||
throw new Error("SourceFile has already been processed.");
|
||||
}
|
||||
assert(this.sourceCode != null);
|
||||
const preProcessedFileInfo = ts.preProcessFile(
|
||||
this.sourceCode!,
|
||||
true,
|
||||
true
|
||||
);
|
||||
const preProcessedFileInfo = ts.preProcessFile(this.sourceCode, true, true);
|
||||
this.processed = true;
|
||||
const files = (this.importedFiles = [] as Array<[string, string]>);
|
||||
|
||||
|
@ -511,10 +508,10 @@ class Host implements ts.CompilerHost {
|
|||
? this._getAsset(fileName)
|
||||
: SourceFile.get(fileName);
|
||||
assert(sourceFile != null);
|
||||
if (!sourceFile!.tsSourceFile) {
|
||||
sourceFile!.tsSourceFile = ts.createSourceFile(
|
||||
if (!sourceFile.tsSourceFile) {
|
||||
sourceFile.tsSourceFile = ts.createSourceFile(
|
||||
fileName,
|
||||
sourceFile!.sourceCode,
|
||||
sourceFile.sourceCode,
|
||||
languageVersion
|
||||
);
|
||||
}
|
||||
|
@ -577,7 +574,7 @@ class Host implements ts.CompilerHost {
|
|||
emitBundle(this._rootNames, this._outFile, data, sourceFiles!);
|
||||
} else {
|
||||
assert(sourceFiles.length == 1);
|
||||
const url = sourceFiles![0].fileName;
|
||||
const url = sourceFiles[0].fileName;
|
||||
const sourceFile = SourceFile.get(url);
|
||||
|
||||
if (sourceFile) {
|
||||
|
@ -635,9 +632,9 @@ window.compilerMain = function compilerMain(): void {
|
|||
// This will recursively analyse all the code for other imports, 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])
|
||||
)).map(info => info.url);
|
||||
const resolvedRootModules = (
|
||||
await processImports(rootNames.map(rootName => [rootName, rootName]))
|
||||
).map(info => info.url);
|
||||
|
||||
const host = new Host(
|
||||
request.type,
|
||||
|
@ -669,8 +666,9 @@ window.compilerMain = function compilerMain(): void {
|
|||
const options = host.getCompilationSettings();
|
||||
const program = ts.createProgram(rootNames, options, host);
|
||||
|
||||
diagnostics = ts.getPreEmitDiagnostics(program).filter(
|
||||
({ code }): boolean => {
|
||||
diagnostics = ts
|
||||
.getPreEmitDiagnostics(program)
|
||||
.filter(({ code }): boolean => {
|
||||
// TS1103: 'for-await-of' statement is only allowed within an async
|
||||
// function or async generator.
|
||||
if (code === 1103) return false;
|
||||
|
@ -692,8 +690,7 @@ window.compilerMain = function compilerMain(): void {
|
|||
// so we will ignore complaints about this compiler setting.
|
||||
if (code === 5070) return false;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// We will only proceed with the emit if there are no diagnostics.
|
||||
if (diagnostics && diagnostics.length === 0) {
|
||||
|
|
|
@ -292,20 +292,18 @@ function createRawObjectString(
|
|||
shouldShowClassName = true;
|
||||
}
|
||||
const keys = Object.keys(value);
|
||||
const entries: string[] = keys.map(
|
||||
(key): string => {
|
||||
if (keys.length > OBJ_ABBREVIATE_SIZE) {
|
||||
return key;
|
||||
} else {
|
||||
return `${key}: ${stringifyWithQuotes(
|
||||
value[key],
|
||||
ctx,
|
||||
level + 1,
|
||||
maxLevel
|
||||
)}`;
|
||||
}
|
||||
const entries: string[] = keys.map((key): string => {
|
||||
if (keys.length > OBJ_ABBREVIATE_SIZE) {
|
||||
return key;
|
||||
} else {
|
||||
return `${key}: ${stringifyWithQuotes(
|
||||
value[key],
|
||||
ctx,
|
||||
level + 1,
|
||||
maxLevel
|
||||
)}`;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
ctx.delete(value);
|
||||
|
||||
|
@ -640,43 +638,39 @@ export class Console {
|
|||
let idx = 0;
|
||||
resultData = {};
|
||||
|
||||
data.forEach(
|
||||
(v: unknown, k: unknown): void => {
|
||||
resultData[idx] = { Key: k, Values: v };
|
||||
idx++;
|
||||
}
|
||||
);
|
||||
data.forEach((v: unknown, k: unknown): void => {
|
||||
resultData[idx] = { Key: k, Values: v };
|
||||
idx++;
|
||||
});
|
||||
} else {
|
||||
resultData = data!;
|
||||
}
|
||||
|
||||
Object.keys(resultData).forEach(
|
||||
(k, idx): void => {
|
||||
const value: unknown = resultData[k]!;
|
||||
Object.keys(resultData).forEach((k, idx): void => {
|
||||
const value: unknown = resultData[k]!;
|
||||
|
||||
if (value !== null && typeof value === "object") {
|
||||
Object.entries(value as { [key: string]: unknown }).forEach(
|
||||
([k, v]): void => {
|
||||
if (properties && !properties.includes(k)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (objectValues[k]) {
|
||||
objectValues[k].push(stringifyValue(v));
|
||||
} else {
|
||||
objectValues[k] = createColumn(v, idx);
|
||||
}
|
||||
if (value !== null && typeof value === "object") {
|
||||
Object.entries(value as { [key: string]: unknown }).forEach(
|
||||
([k, v]): void => {
|
||||
if (properties && !properties.includes(k)) {
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
values.push("");
|
||||
} else {
|
||||
values.push(stringifyValue(value));
|
||||
}
|
||||
if (objectValues[k]) {
|
||||
objectValues[k].push(stringifyValue(v));
|
||||
} else {
|
||||
objectValues[k] = createColumn(v, idx);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
indexKeys.push(k);
|
||||
values.push("");
|
||||
} else {
|
||||
values.push(stringifyValue(value));
|
||||
}
|
||||
);
|
||||
|
||||
indexKeys.push(k);
|
||||
});
|
||||
|
||||
const headerKeys = Object.keys(objectValues);
|
||||
const bodyValues = Object.values(objectValues);
|
||||
|
|
|
@ -72,8 +72,8 @@ export function cliTable(head: string[], columns: string[][]): string {
|
|||
}
|
||||
}
|
||||
|
||||
const divider = columnWidths.map(
|
||||
(i: number): string => tableChars.middleMiddle.repeat(i + 2)
|
||||
const divider = columnWidths.map((i: number): string =>
|
||||
tableChars.middleMiddle.repeat(i + 2)
|
||||
);
|
||||
|
||||
let result =
|
||||
|
|
|
@ -121,7 +121,12 @@ test(function consoleTestStringifyCircular(): void {
|
|||
);
|
||||
assertEquals(stringify(new Set([1, 2, 3])), "Set { 1, 2, 3 }");
|
||||
assertEquals(
|
||||
stringify(new Map([[1, "one"], [2, "two"]])),
|
||||
stringify(
|
||||
new Map([
|
||||
[1, "one"],
|
||||
[2, "two"]
|
||||
])
|
||||
),
|
||||
`Map { 1 => "one", 2 => "two" }`
|
||||
);
|
||||
assertEquals(stringify(new WeakSet()), "WeakSet { [items unknown] }");
|
||||
|
@ -130,12 +135,18 @@ test(function consoleTestStringifyCircular(): void {
|
|||
assertEquals(stringify(null), "null");
|
||||
assertEquals(stringify(undefined), "undefined");
|
||||
assertEquals(stringify(new Extended()), "Extended { a: 1, b: 2 }");
|
||||
assertEquals(stringify(function f(): void {}), "[Function: f]");
|
||||
assertEquals(
|
||||
stringify(function f(): void {}),
|
||||
"[Function: f]"
|
||||
);
|
||||
assertEquals(
|
||||
stringify(async function af(): Promise<void> {}),
|
||||
"[AsyncFunction: af]"
|
||||
);
|
||||
assertEquals(stringify(function* gf() {}), "[GeneratorFunction: gf]");
|
||||
assertEquals(
|
||||
stringify(function* gf() {}),
|
||||
"[GeneratorFunction: gf]"
|
||||
);
|
||||
assertEquals(
|
||||
stringify(async function* agf() {}),
|
||||
"[AsyncGeneratorFunction: agf]"
|
||||
|
@ -410,50 +421,47 @@ function mockConsole(f: ConsoleExamineFunc): void {
|
|||
|
||||
// console.group test
|
||||
test(function consoleGroup(): void {
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.group("1");
|
||||
console.log("2");
|
||||
console.group("3");
|
||||
console.log("4");
|
||||
console.groupEnd();
|
||||
console.groupEnd();
|
||||
console.log("5");
|
||||
console.log("6");
|
||||
mockConsole((console, out): void => {
|
||||
console.group("1");
|
||||
console.log("2");
|
||||
console.group("3");
|
||||
console.log("4");
|
||||
console.groupEnd();
|
||||
console.groupEnd();
|
||||
console.log("5");
|
||||
console.log("6");
|
||||
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`1
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// console.group with console.warn test
|
||||
test(function consoleGroupWarn(): void {
|
||||
mockConsole(
|
||||
(console, _out, _err, both): void => {
|
||||
console.warn("1");
|
||||
console.group();
|
||||
console.warn("2");
|
||||
console.group();
|
||||
console.warn("3");
|
||||
console.groupEnd();
|
||||
console.warn("4");
|
||||
console.groupEnd();
|
||||
console.warn("5");
|
||||
mockConsole((console, _out, _err, both): void => {
|
||||
console.warn("1");
|
||||
console.group();
|
||||
console.warn("2");
|
||||
console.group();
|
||||
console.warn("3");
|
||||
console.groupEnd();
|
||||
console.warn("4");
|
||||
console.groupEnd();
|
||||
console.warn("5");
|
||||
|
||||
console.warn("6");
|
||||
console.warn("7");
|
||||
assertEquals(
|
||||
both.toString(),
|
||||
`1
|
||||
console.warn("6");
|
||||
console.warn("7");
|
||||
assertEquals(
|
||||
both.toString(),
|
||||
`1
|
||||
2
|
||||
3
|
||||
4
|
||||
|
@ -461,49 +469,43 @@ test(function consoleGroupWarn(): void {
|
|||
6
|
||||
7
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// console.table test
|
||||
test(function consoleTable(): void {
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table({ a: "test", b: 1 });
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────────┐
|
||||
mockConsole((console, out): void => {
|
||||
console.table({ a: "test", b: 1 });
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────────┐
|
||||
│ (index) │ Values │
|
||||
├─────────┼────────┤
|
||||
│ a │ "test" │
|
||||
│ b │ 1 │
|
||||
└─────────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table({ a: { b: 10 }, b: { b: 20, c: 30 } }, ["c"]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table({ a: { b: 10 }, b: { b: 20, c: 30 } }, ["c"]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────┐
|
||||
│ (index) │ c │
|
||||
├─────────┼────┤
|
||||
│ a │ │
|
||||
│ b │ 30 │
|
||||
└─────────┴────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table([1, 2, [3, [4]], [5, 6], [[7], [8]]]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬───────┬───────┬────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table([1, 2, [3, [4]], [5, 6], [[7], [8]]]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬───────┬───────┬────────┐
|
||||
│ (index) │ 0 │ 1 │ Values │
|
||||
├─────────┼───────┼───────┼────────┤
|
||||
│ 0 │ │ │ 1 │
|
||||
|
@ -513,15 +515,13 @@ test(function consoleTable(): void {
|
|||
│ 4 │ [ 7 ] │ [ 8 ] │ │
|
||||
└─────────┴───────┴───────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table(new Set([1, 2, 3, "test"]));
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┬────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table(new Set([1, 2, 3, "test"]));
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┬────────┐
|
||||
│ (iteration index) │ Values │
|
||||
├───────────────────┼────────┤
|
||||
│ 0 │ 1 │
|
||||
|
@ -530,36 +530,37 @@ test(function consoleTable(): void {
|
|||
│ 3 │ "test" │
|
||||
└───────────────────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table(new Map([[1, "one"], [2, "two"]]));
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┬─────┬────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table(
|
||||
new Map([
|
||||
[1, "one"],
|
||||
[2, "two"]
|
||||
])
|
||||
);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┬─────┬────────┐
|
||||
│ (iteration index) │ Key │ Values │
|
||||
├───────────────────┼─────┼────────┤
|
||||
│ 0 │ 1 │ "one" │
|
||||
│ 1 │ 2 │ "two" │
|
||||
└───────────────────┴─────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table({
|
||||
a: true,
|
||||
b: { c: { d: 10 }, e: [1, 2, [5, 6]] },
|
||||
f: "test",
|
||||
g: new Set([1, 2, 3, "test"]),
|
||||
h: new Map([[1, "one"]])
|
||||
});
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬───────────┬───────────────────┬────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table({
|
||||
a: true,
|
||||
b: { c: { d: 10 }, e: [1, 2, [5, 6]] },
|
||||
f: "test",
|
||||
g: new Set([1, 2, 3, "test"]),
|
||||
h: new Map([[1, "one"]])
|
||||
});
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬───────────┬───────────────────┬────────┐
|
||||
│ (index) │ c │ e │ Values │
|
||||
├─────────┼───────────┼───────────────────┼────────┤
|
||||
│ a │ │ │ true │
|
||||
|
@ -569,21 +570,19 @@ test(function consoleTable(): void {
|
|||
│ h │ │ │ │
|
||||
└─────────┴───────────┴───────────────────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table([
|
||||
1,
|
||||
"test",
|
||||
false,
|
||||
{ a: 10 },
|
||||
["test", { b: 20, c: "test" }]
|
||||
]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────────┬──────────────────────┬────┬────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table([
|
||||
1,
|
||||
"test",
|
||||
false,
|
||||
{ a: 10 },
|
||||
["test", { b: 20, c: "test" }]
|
||||
]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┬────────┬──────────────────────┬────┬────────┐
|
||||
│ (index) │ 0 │ 1 │ a │ Values │
|
||||
├─────────┼────────┼──────────────────────┼────┼────────┤
|
||||
│ 0 │ │ │ │ 1 │
|
||||
|
@ -593,67 +592,56 @@ test(function consoleTable(): void {
|
|||
│ 4 │ "test" │ { b: 20, c: "test" } │ │ │
|
||||
└─────────┴────────┴──────────────────────┴────┴────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table([]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table([]);
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┐
|
||||
│ (index) │
|
||||
├─────────┤
|
||||
└─────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table({});
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table({});
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌─────────┐
|
||||
│ (index) │
|
||||
├─────────┤
|
||||
└─────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table(new Set());
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table(new Set());
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┐
|
||||
│ (iteration index) │
|
||||
├───────────────────┤
|
||||
└───────────────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table(new Map());
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┐
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table(new Map());
|
||||
assertEquals(
|
||||
out.toString(),
|
||||
`┌───────────────────┐
|
||||
│ (iteration index) │
|
||||
├───────────────────┤
|
||||
└───────────────────┘
|
||||
`
|
||||
);
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.table("test");
|
||||
assertEquals(out.toString(), "test\n");
|
||||
}
|
||||
);
|
||||
);
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.table("test");
|
||||
assertEquals(out.toString(), "test\n");
|
||||
});
|
||||
});
|
||||
|
||||
// console.log(Error) test
|
||||
|
@ -668,52 +656,40 @@ test(function consoleLogShouldNotThrowError(): void {
|
|||
assertEquals(result, 1);
|
||||
|
||||
// output errors to the console should not include "Uncaught"
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.log(new Error("foo"));
|
||||
assertEquals(out.toString().includes("Uncaught"), false);
|
||||
}
|
||||
);
|
||||
mockConsole((console, out): void => {
|
||||
console.log(new Error("foo"));
|
||||
assertEquals(out.toString().includes("Uncaught"), false);
|
||||
});
|
||||
});
|
||||
|
||||
// console.dir test
|
||||
test(function consoleDir(): void {
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.dir("DIR");
|
||||
assertEquals(out.toString(), "DIR\n");
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.dir("DIR", { indentLevel: 2 });
|
||||
assertEquals(out.toString(), " DIR\n");
|
||||
}
|
||||
);
|
||||
mockConsole((console, out): void => {
|
||||
console.dir("DIR");
|
||||
assertEquals(out.toString(), "DIR\n");
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.dir("DIR", { indentLevel: 2 });
|
||||
assertEquals(out.toString(), " DIR\n");
|
||||
});
|
||||
});
|
||||
|
||||
// console.dir test
|
||||
test(function consoleDirXml(): void {
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.dirxml("DIRXML");
|
||||
assertEquals(out.toString(), "DIRXML\n");
|
||||
}
|
||||
);
|
||||
mockConsole(
|
||||
(console, out): void => {
|
||||
console.dirxml("DIRXML", { indentLevel: 2 });
|
||||
assertEquals(out.toString(), " DIRXML\n");
|
||||
}
|
||||
);
|
||||
mockConsole((console, out): void => {
|
||||
console.dirxml("DIRXML");
|
||||
assertEquals(out.toString(), "DIRXML\n");
|
||||
});
|
||||
mockConsole((console, out): void => {
|
||||
console.dirxml("DIRXML", { indentLevel: 2 });
|
||||
assertEquals(out.toString(), " DIRXML\n");
|
||||
});
|
||||
});
|
||||
|
||||
// console.trace test
|
||||
test(function consoleTrace(): void {
|
||||
mockConsole(
|
||||
(console, _out, err): void => {
|
||||
console.trace("%s", "custom message");
|
||||
assert(err.toString().includes("Trace: custom message"));
|
||||
}
|
||||
);
|
||||
mockConsole((console, _out, err): void => {
|
||||
console.trace("%s", "custom message");
|
||||
assert(err.toString().includes("Trace: custom message"));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -87,9 +87,7 @@ function fromDiagnosticCategory(
|
|||
return DiagnosticCategory.Warning;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unexpected DiagnosticCategory: "${category}"/"${
|
||||
ts.DiagnosticCategory[category]
|
||||
}"`
|
||||
`Unexpected DiagnosticCategory: "${category}"/"${ts.DiagnosticCategory[category]}"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ function unwrapResponse(res: JsonResponse): Ok {
|
|||
throw new DenoError(res.err!.kind, res.err!.message);
|
||||
}
|
||||
util.assert(res.ok != null);
|
||||
return res.ok!;
|
||||
return res.ok;
|
||||
}
|
||||
|
||||
export function asyncMsgFromRust(opId: number, resUi8: Uint8Array): void {
|
||||
|
@ -50,7 +50,7 @@ export function asyncMsgFromRust(opId: number, resUi8: Uint8Array): void {
|
|||
const promise = promiseTable.get(res.promiseId!);
|
||||
util.assert(promise != null);
|
||||
promiseTable.delete(res.promiseId!);
|
||||
promise!.resolve(res);
|
||||
promise.resolve(res);
|
||||
}
|
||||
|
||||
export function sendSync(
|
||||
|
|
|
@ -18,11 +18,9 @@ const openErrorStackPattern = new RegExp(
|
|||
testPerm({ read: true }, async function sendAsyncStackTrace(): Promise<void> {
|
||||
await Deno.open("nonexistent.txt")
|
||||
.then(unreachable)
|
||||
.catch(
|
||||
(error): void => {
|
||||
assertMatch(error.stack, openErrorStackPattern);
|
||||
}
|
||||
);
|
||||
.catch((error): void => {
|
||||
assertMatch(error.stack, openErrorStackPattern);
|
||||
});
|
||||
});
|
||||
|
||||
test(async function malformedJsonControlBuffer(): Promise<void> {
|
||||
|
|
|
@ -79,7 +79,8 @@ export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
|
|||
const { promiseId } = record;
|
||||
const promise = promiseTableMin.get(promiseId);
|
||||
promiseTableMin.delete(promiseId);
|
||||
promise!.resolve(record);
|
||||
util.assert(promise);
|
||||
promise.resolve(record);
|
||||
}
|
||||
|
||||
export async function sendAsyncMinimal(
|
||||
|
|
|
@ -18,11 +18,9 @@ test(async function sendAsyncStackTrace(): Promise<void> {
|
|||
const buf = new Uint8Array(10);
|
||||
await Deno.read(10, "nonexistent.txt", buf)
|
||||
.then(unreachable)
|
||||
.catch(
|
||||
(error): void => {
|
||||
assertMatch(error.stack, readErrorStackPattern);
|
||||
}
|
||||
);
|
||||
.catch((error): void => {
|
||||
assertMatch(error.stack, readErrorStackPattern);
|
||||
});
|
||||
});
|
||||
test(async function malformedMinimalControlBuffer(): Promise<void> {
|
||||
// @ts-ignore
|
||||
|
|
|
@ -27,7 +27,7 @@ export const eventTargetHasActivationBehavior: unique symbol = Symbol();
|
|||
export class EventTarget implements domTypes.EventTarget {
|
||||
public [domTypes.eventTargetHost]: domTypes.EventTarget | null = null;
|
||||
public [domTypes.eventTargetListeners]: {
|
||||
[type in string]: domTypes.EventListener[]
|
||||
[type in string]: domTypes.EventListener[];
|
||||
} = {};
|
||||
public [domTypes.eventTargetMode] = "";
|
||||
public [domTypes.eventTargetNodeType]: domTypes.NodeType =
|
||||
|
@ -417,9 +417,7 @@ const eventTargetHelpers = {
|
|||
}
|
||||
|
||||
try {
|
||||
if (listener.callback) {
|
||||
listener.handleEvent(eventImpl);
|
||||
}
|
||||
listener.handleEvent(eventImpl);
|
||||
} catch (error) {
|
||||
throw new DenoError(ErrorKind.Interrupted, error.message);
|
||||
}
|
||||
|
|
|
@ -188,19 +188,17 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
|
|||
body
|
||||
.trim()
|
||||
.split("&")
|
||||
.forEach(
|
||||
(bytes): void => {
|
||||
if (bytes) {
|
||||
const split = bytes.split("=");
|
||||
const name = split.shift()!.replace(/\+/g, " ");
|
||||
const value = split.join("=").replace(/\+/g, " ");
|
||||
formData.append(
|
||||
decodeURIComponent(name),
|
||||
decodeURIComponent(value)
|
||||
);
|
||||
}
|
||||
.forEach((bytes): void => {
|
||||
if (bytes) {
|
||||
const split = bytes.split("=");
|
||||
const name = split.shift()!.replace(/\+/g, " ");
|
||||
const value = split.join("=").replace(/\+/g, " ");
|
||||
formData.append(
|
||||
decodeURIComponent(name),
|
||||
decodeURIComponent(value)
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
throw new TypeError("Invalid form urlencoded format");
|
||||
}
|
||||
|
|
|
@ -60,12 +60,10 @@ testPerm({ net: true }, async function fetchBlob(): Promise<void> {
|
|||
testPerm({ net: true }, async function fetchBodyUsed(): Promise<void> {
|
||||
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
|
||||
assertEquals(response.bodyUsed, false);
|
||||
assertThrows(
|
||||
(): void => {
|
||||
// Assigning to read-only property throws in the strict mode.
|
||||
response.bodyUsed = true;
|
||||
}
|
||||
);
|
||||
assertThrows((): void => {
|
||||
// Assigning to read-only property throws in the strict mode.
|
||||
response.bodyUsed = true;
|
||||
});
|
||||
await response.blob();
|
||||
assertEquals(response.bodyUsed, true);
|
||||
});
|
||||
|
|
|
@ -82,20 +82,21 @@ test(function formDataSetEmptyBlobSuccess(): void {
|
|||
});
|
||||
|
||||
test(function formDataParamsForEachSuccess(): void {
|
||||
const init = [["a", "54"], ["b", "true"]];
|
||||
const init = [
|
||||
["a", "54"],
|
||||
["b", "true"]
|
||||
];
|
||||
const formData = new FormData();
|
||||
for (const [name, value] of init) {
|
||||
formData.append(name, value);
|
||||
}
|
||||
let callNum = 0;
|
||||
formData.forEach(
|
||||
(value, key, parent): void => {
|
||||
assertEquals(formData, parent);
|
||||
assertEquals(value, init[callNum][1]);
|
||||
assertEquals(key, init[callNum][0]);
|
||||
callNum++;
|
||||
}
|
||||
);
|
||||
formData.forEach((value, key, parent): void => {
|
||||
assertEquals(formData, parent);
|
||||
assertEquals(value, init[callNum][1]);
|
||||
assertEquals(key, init[callNum][0]);
|
||||
callNum++;
|
||||
});
|
||||
assertEquals(callNum, init.length);
|
||||
});
|
||||
|
||||
|
@ -104,73 +105,69 @@ test(function formDataParamsArgumentsCheck(): void {
|
|||
|
||||
const methodRequireTwoParams = ["append", "set"];
|
||||
|
||||
methodRequireOneParam.forEach(
|
||||
(method): void => {
|
||||
const formData = new FormData();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
try {
|
||||
formData[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
methodRequireOneParam.forEach((method): void => {
|
||||
const formData = new FormData();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
try {
|
||||
formData[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 1 argument, but only 0 present`
|
||||
);
|
||||
}
|
||||
);
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 1 argument, but only 0 present`
|
||||
);
|
||||
});
|
||||
|
||||
methodRequireTwoParams.forEach(
|
||||
(method: string): void => {
|
||||
const formData = new FormData();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
methodRequireTwoParams.forEach((method: string): void => {
|
||||
const formData = new FormData();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
|
||||
try {
|
||||
formData[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
try {
|
||||
formData[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 2 arguments, but only 0 present`
|
||||
);
|
||||
|
||||
hasThrown = 0;
|
||||
errMsg = "";
|
||||
try {
|
||||
formData[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 2 arguments, but only 1 present`
|
||||
);
|
||||
}
|
||||
);
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 2 arguments, but only 0 present`
|
||||
);
|
||||
|
||||
hasThrown = 0;
|
||||
errMsg = "";
|
||||
try {
|
||||
formData[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`FormData.${method} requires at least 2 arguments, but only 1 present`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test(function toStringShouldBeWebCompatibility(): void {
|
||||
|
|
|
@ -162,25 +162,19 @@ window.removeEventListener =
|
|||
eventTarget.EventTarget.prototype.removeEventListener;
|
||||
|
||||
// Registers the handler for window.onload function.
|
||||
window.addEventListener(
|
||||
"load",
|
||||
(e: domTypes.Event): void => {
|
||||
const onload = window.onload;
|
||||
if (typeof onload === "function") {
|
||||
onload(e);
|
||||
}
|
||||
window.addEventListener("load", (e: domTypes.Event): void => {
|
||||
const onload = window.onload;
|
||||
if (typeof onload === "function") {
|
||||
onload(e);
|
||||
}
|
||||
);
|
||||
});
|
||||
// Registers the handler for window.onunload function.
|
||||
window.addEventListener(
|
||||
"unload",
|
||||
(e: domTypes.Event): void => {
|
||||
const onunload = window.onunload;
|
||||
if (typeof onunload === "function") {
|
||||
onunload(e);
|
||||
}
|
||||
window.addEventListener("unload", (e: domTypes.Event): void => {
|
||||
const onunload = window.onunload;
|
||||
if (typeof onunload === "function") {
|
||||
onunload(e);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// below are interfaces that are available in TypeScript but
|
||||
// have different signatures
|
||||
|
|
|
@ -81,22 +81,18 @@ test(async function windowQueueMicrotask(): Promise<void> {
|
|||
let resolve1: () => void | undefined;
|
||||
let resolve2: () => void | undefined;
|
||||
let microtaskDone = false;
|
||||
const p1 = new Promise(
|
||||
(res): void => {
|
||||
resolve1 = (): void => {
|
||||
microtaskDone = true;
|
||||
res();
|
||||
};
|
||||
}
|
||||
);
|
||||
const p2 = new Promise(
|
||||
(res): void => {
|
||||
resolve2 = (): void => {
|
||||
assert(microtaskDone);
|
||||
res();
|
||||
};
|
||||
}
|
||||
);
|
||||
const p1 = new Promise((res): void => {
|
||||
resolve1 = (): void => {
|
||||
microtaskDone = true;
|
||||
res();
|
||||
};
|
||||
});
|
||||
const p2 = new Promise((res): void => {
|
||||
resolve2 = (): void => {
|
||||
assert(microtaskDone);
|
||||
res();
|
||||
};
|
||||
});
|
||||
window.queueMicrotask(resolve1!);
|
||||
setTimeout(resolve2!, 0);
|
||||
await p1;
|
||||
|
|
|
@ -145,21 +145,17 @@ const headerEntriesDict = {
|
|||
test(function headerForEachSuccess(): void {
|
||||
const headers = new Headers(headerEntriesDict);
|
||||
const keys = Object.keys(headerEntriesDict);
|
||||
keys.forEach(
|
||||
(key): void => {
|
||||
const value = headerEntriesDict[key];
|
||||
const newkey = key.toLowerCase();
|
||||
headerEntriesDict[newkey] = value;
|
||||
}
|
||||
);
|
||||
keys.forEach((key): void => {
|
||||
const value = headerEntriesDict[key];
|
||||
const newkey = key.toLowerCase();
|
||||
headerEntriesDict[newkey] = value;
|
||||
});
|
||||
let callNum = 0;
|
||||
headers.forEach(
|
||||
(value, key, container): void => {
|
||||
assertEquals(headers, container);
|
||||
assertEquals(value, headerEntriesDict[key]);
|
||||
callNum++;
|
||||
}
|
||||
);
|
||||
headers.forEach((value, key, container): void => {
|
||||
assertEquals(headers, container);
|
||||
assertEquals(value, headerEntriesDict[key]);
|
||||
callNum++;
|
||||
});
|
||||
assertEquals(callNum, keys.length);
|
||||
});
|
||||
|
||||
|
@ -260,73 +256,69 @@ test(function headerParamsArgumentsCheck(): void {
|
|||
|
||||
const methodRequireTwoParams = ["append", "set"];
|
||||
|
||||
methodRequireOneParam.forEach(
|
||||
(method): void => {
|
||||
const headers = new Headers();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
try {
|
||||
headers[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
methodRequireOneParam.forEach((method): void => {
|
||||
const headers = new Headers();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
try {
|
||||
headers[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 1 argument, but only 0 present`
|
||||
);
|
||||
}
|
||||
);
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 1 argument, but only 0 present`
|
||||
);
|
||||
});
|
||||
|
||||
methodRequireTwoParams.forEach(
|
||||
(method): void => {
|
||||
const headers = new Headers();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
methodRequireTwoParams.forEach((method): void => {
|
||||
const headers = new Headers();
|
||||
let hasThrown = 0;
|
||||
let errMsg = "";
|
||||
|
||||
try {
|
||||
headers[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
try {
|
||||
headers[method]();
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 2 arguments, but only 0 present`
|
||||
);
|
||||
|
||||
hasThrown = 0;
|
||||
errMsg = "";
|
||||
try {
|
||||
headers[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 2 arguments, but only 1 present`
|
||||
);
|
||||
}
|
||||
);
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 2 arguments, but only 0 present`
|
||||
);
|
||||
|
||||
hasThrown = 0;
|
||||
errMsg = "";
|
||||
try {
|
||||
headers[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
errMsg = err.message;
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
assertEquals(
|
||||
errMsg,
|
||||
`Headers.${method} requires at least 2 arguments, but only 1 present`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test(function toStringShouldBeWebCompatibility(): void {
|
||||
|
|
2
cli/js/lib.deno_runtime.d.ts
vendored
2
cli/js/lib.deno_runtime.d.ts
vendored
|
@ -2268,7 +2268,7 @@ declare namespace eventTarget {
|
|||
export class EventTarget implements domTypes.EventTarget {
|
||||
[domTypes.eventTargetHost]: domTypes.EventTarget | null;
|
||||
[domTypes.eventTargetListeners]: {
|
||||
[type in string]: domTypes.EventListener[]
|
||||
[type in string]: domTypes.EventListener[];
|
||||
};
|
||||
[domTypes.eventTargetMode]: string;
|
||||
[domTypes.eventTargetNodeType]: domTypes.NodeType;
|
||||
|
|
|
@ -28,7 +28,10 @@ function setup() {
|
|||
test(function testDomIterable(): void {
|
||||
const { DomIterable, Base } = setup();
|
||||
|
||||
const fixture: Array<[string, number]> = [["foo", 1], ["bar", 2]];
|
||||
const fixture: Array<[string, number]> = [
|
||||
["foo", 1],
|
||||
["bar", 2]
|
||||
];
|
||||
|
||||
const domIterable = new DomIterable(fixture);
|
||||
|
||||
|
|
|
@ -39,10 +39,8 @@ testPerm({ read: true }, async function resourcesFile(): Promise<void> {
|
|||
Object.keys(resourcesAfter).length,
|
||||
Object.keys(resourcesBefore).length + 1
|
||||
);
|
||||
const newRid = Object.keys(resourcesAfter).find(
|
||||
(rid): boolean => {
|
||||
return !resourcesBefore.hasOwnProperty(rid);
|
||||
}
|
||||
);
|
||||
const newRid = Object.keys(resourcesAfter).find((rid): boolean => {
|
||||
return !resourcesBefore.hasOwnProperty(rid);
|
||||
});
|
||||
assertEquals(resourcesAfter[newRid], "fsFile");
|
||||
});
|
||||
|
|
|
@ -295,14 +295,18 @@ export function readableStreamTee<OutputType>(
|
|||
.then(({ value, done }) => {
|
||||
if (done && !closedOrErrored) {
|
||||
if (!canceled1) {
|
||||
rs.readableStreamDefaultControllerClose(branch1![
|
||||
rs.readableStreamController_
|
||||
] as ReadableStreamDefaultController<OutputType>);
|
||||
rs.readableStreamDefaultControllerClose(
|
||||
branch1![
|
||||
rs.readableStreamController_
|
||||
] as ReadableStreamDefaultController<OutputType>
|
||||
);
|
||||
}
|
||||
if (!canceled2) {
|
||||
rs.readableStreamDefaultControllerClose(branch2![
|
||||
rs.readableStreamController_
|
||||
] as ReadableStreamDefaultController<OutputType>);
|
||||
rs.readableStreamDefaultControllerClose(
|
||||
branch2![
|
||||
rs.readableStreamController_
|
||||
] as ReadableStreamDefaultController<OutputType>
|
||||
);
|
||||
}
|
||||
closedOrErrored = true;
|
||||
}
|
||||
|
|
|
@ -9,12 +9,10 @@ function deferred(): {
|
|||
} {
|
||||
let resolve;
|
||||
let reject;
|
||||
const promise = new Promise(
|
||||
(res, rej): void => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
}
|
||||
);
|
||||
const promise = new Promise((res, rej): void => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
return {
|
||||
promise,
|
||||
resolve,
|
||||
|
|
|
@ -185,9 +185,6 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise<
|
|||
const tpr = new TextProtoReader(r);
|
||||
const statusLine = await tpr.readLine();
|
||||
assert(statusLine !== Deno.EOF, `line must be read: ${String(statusLine)}`);
|
||||
if (statusLine === Deno.EOF) {
|
||||
return;
|
||||
}
|
||||
const m = statusLine.match(/^(.+?) (.+?) (.+?)$/);
|
||||
assert(m !== null, "must be matched");
|
||||
const [_, proto, status, ok] = m;
|
||||
|
@ -196,9 +193,6 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise<
|
|||
assertEquals(ok, "OK");
|
||||
const headers = await tpr.readMIMEHeader();
|
||||
assert(headers !== Deno.EOF);
|
||||
if (headers === Deno.EOF) {
|
||||
return;
|
||||
}
|
||||
const contentLength = parseInt(headers.get("content-length"));
|
||||
const bodyBuf = new Uint8Array(contentLength);
|
||||
await r.readFull(bodyBuf);
|
||||
|
|
|
@ -15,17 +15,15 @@ interface TestResult {
|
|||
|
||||
function permsToCliFlags(perms: Permissions): string[] {
|
||||
return Object.keys(perms)
|
||||
.map(
|
||||
(key): string => {
|
||||
if (!perms[key]) return "";
|
||||
.map((key): string => {
|
||||
if (!perms[key]) return "";
|
||||
|
||||
const cliFlag = key.replace(
|
||||
/\.?([A-Z])/g,
|
||||
(x, y): string => `-${y.toLowerCase()}`
|
||||
);
|
||||
return `--allow-${cliFlag}`;
|
||||
}
|
||||
)
|
||||
const cliFlag = key.replace(
|
||||
/\.?([A-Z])/g,
|
||||
(x, y): string => `-${y.toLowerCase()}`
|
||||
);
|
||||
return `--allow-${cliFlag}`;
|
||||
})
|
||||
.filter((e): boolean => e.length > 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,7 @@ const patterns = {
|
|||
};
|
||||
|
||||
const urlRegExp = new RegExp(
|
||||
`^${patterns.protocol}?${patterns.authority}?${patterns.path}${
|
||||
patterns.query
|
||||
}?${patterns.hash}?`
|
||||
`^${patterns.protocol}?${patterns.authority}?${patterns.path}${patterns.query}?${patterns.hash}?`
|
||||
);
|
||||
|
||||
const authorityRegExp = new RegExp(
|
||||
|
@ -70,11 +68,9 @@ function parse(url: string): URLParts | undefined {
|
|||
// Based on https://github.com/kelektiv/node-uuid
|
||||
// TODO(kevinkassimo): Use deno_std version once possible.
|
||||
function generateUUID(): string {
|
||||
return "00000000-0000-4000-8000-000000000000".replace(
|
||||
/[0]/g,
|
||||
(): string =>
|
||||
// random integer from 0 to 15 as a hex digit.
|
||||
(getRandomValues(new Uint8Array(1))[0] % 16).toString(16)
|
||||
return "00000000-0000-4000-8000-000000000000".replace(/[0]/g, (): string =>
|
||||
// random integer from 0 to 15 as a hex digit.
|
||||
(getRandomValues(new Uint8Array(1))[0] % 16).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -232,9 +228,7 @@ export class URL {
|
|||
if (this.host || this.protocol === "file:") {
|
||||
slash = "//";
|
||||
}
|
||||
return `${this.protocol}${slash}${authentication}${this.host}${
|
||||
this.pathname
|
||||
}${this.search}${this.hash}`;
|
||||
return `${this.protocol}${slash}${authentication}${this.host}${this.pathname}${this.search}${this.hash}`;
|
||||
}
|
||||
|
||||
set href(value: string) {
|
||||
|
|
|
@ -168,8 +168,8 @@ export class URLSearchParams {
|
|||
* searchParams.sort();
|
||||
*/
|
||||
sort(): void {
|
||||
this.params = this.params.sort(
|
||||
(a, b): number => (a[0] === b[0] ? 0 : a[0] > b[0] ? 1 : -1)
|
||||
this.params = this.params.sort((a, b): number =>
|
||||
a[0] === b[0] ? 0 : a[0] > b[0] ? 1 : -1
|
||||
);
|
||||
this.updateSteps();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ test(function urlSearchParamsInitString(): void {
|
|||
});
|
||||
|
||||
test(function urlSearchParamsInitIterable(): void {
|
||||
const init = [["a", "54"], ["b", "true"]];
|
||||
const init = [
|
||||
["a", "54"],
|
||||
["b", "true"]
|
||||
];
|
||||
const searchParams = new URLSearchParams(init);
|
||||
assertEquals(searchParams.toString(), "a=54&b=true");
|
||||
});
|
||||
|
@ -89,17 +92,18 @@ test(function urlSearchParamsSortSuccess(): void {
|
|||
});
|
||||
|
||||
test(function urlSearchParamsForEachSuccess(): void {
|
||||
const init = [["a", "54"], ["b", "true"]];
|
||||
const init = [
|
||||
["a", "54"],
|
||||
["b", "true"]
|
||||
];
|
||||
const searchParams = new URLSearchParams(init);
|
||||
let callNum = 0;
|
||||
searchParams.forEach(
|
||||
(value, key, parent): void => {
|
||||
assertEquals(searchParams, parent);
|
||||
assertEquals(value, init[callNum][1]);
|
||||
assertEquals(key, init[callNum][0]);
|
||||
callNum++;
|
||||
}
|
||||
);
|
||||
searchParams.forEach((value, key, parent): void => {
|
||||
assertEquals(searchParams, parent);
|
||||
assertEquals(value, init[callNum][1]);
|
||||
assertEquals(key, init[callNum][0]);
|
||||
callNum++;
|
||||
});
|
||||
assertEquals(callNum, init.length);
|
||||
});
|
||||
|
||||
|
@ -167,8 +171,9 @@ test(function urlSearchParamsAppendArgumentsCheck(): void {
|
|||
|
||||
const methodRequireTwoParams = ["append", "set"];
|
||||
|
||||
methodRequireOneParam.concat(methodRequireTwoParams).forEach(
|
||||
(method: string): void => {
|
||||
methodRequireOneParam
|
||||
.concat(methodRequireTwoParams)
|
||||
.forEach((method: string): void => {
|
||||
const searchParams = new URLSearchParams();
|
||||
let hasThrown = 0;
|
||||
try {
|
||||
|
@ -182,26 +187,23 @@ test(function urlSearchParamsAppendArgumentsCheck(): void {
|
|||
}
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
methodRequireTwoParams.forEach(
|
||||
(method: string): void => {
|
||||
const searchParams = new URLSearchParams();
|
||||
let hasThrown = 0;
|
||||
try {
|
||||
searchParams[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
methodRequireTwoParams.forEach((method: string): void => {
|
||||
const searchParams = new URLSearchParams();
|
||||
let hasThrown = 0;
|
||||
try {
|
||||
searchParams[method]("foo");
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
assertEquals(hasThrown, 2);
|
||||
}
|
||||
);
|
||||
assertEquals(hasThrown, 2);
|
||||
});
|
||||
});
|
||||
|
||||
// ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js
|
||||
|
|
|
@ -26,7 +26,7 @@ export function log(...args: unknown[]): void {
|
|||
}
|
||||
|
||||
// @internal
|
||||
export function assert(cond: boolean, msg = "assert"): void {
|
||||
export function assert(cond: unknown, msg = "assert"): asserts cond {
|
||||
if (!cond) {
|
||||
throw Error(msg);
|
||||
}
|
||||
|
@ -74,11 +74,9 @@ export type Resolvable<T> = Promise<T> & ResolvableMethods<T>;
|
|||
// @internal
|
||||
export function createResolvable<T>(): Resolvable<T> {
|
||||
let methods: ResolvableMethods<T>;
|
||||
const promise = new Promise<T>(
|
||||
(resolve, reject): void => {
|
||||
methods = { resolve, reject };
|
||||
}
|
||||
);
|
||||
const promise = new Promise<T>((resolve, reject): void => {
|
||||
methods = { resolve, reject };
|
||||
});
|
||||
// TypeScript doesn't know that the Promise callback occurs synchronously
|
||||
// therefore use of not null assertion (`!`)
|
||||
return Object.assign(promise, methods!) as Resolvable<T>;
|
||||
|
@ -97,12 +95,9 @@ export function unreachable(): never {
|
|||
// @internal
|
||||
export function hexdump(u8: Uint8Array): string {
|
||||
return Array.prototype.map
|
||||
.call(
|
||||
u8,
|
||||
(x: number): string => {
|
||||
return ("00" + x.toString(16)).slice(-2);
|
||||
}
|
||||
)
|
||||
.call(u8, (x: number): string => {
|
||||
return ("00" + x.toString(16)).slice(-2);
|
||||
})
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
|
|
|
@ -160,11 +160,9 @@ export class WorkerImpl implements Worker {
|
|||
);
|
||||
this.run();
|
||||
this.isClosedPromise = hostGetWorkerClosed(this.id);
|
||||
this.isClosedPromise.then(
|
||||
(): void => {
|
||||
this.isClosing = true;
|
||||
}
|
||||
);
|
||||
this.isClosedPromise.then((): void => {
|
||||
this.isClosing = true;
|
||||
});
|
||||
}
|
||||
|
||||
get closed(): Promise<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue