clean up code in cli/js (#6611)

This commit is contained in:
Stanislav 2020-07-07 04:45:39 +03:00 committed by GitHub
parent ab4c574f52
commit 158ae0bfe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
89 changed files with 395 additions and 354 deletions

View file

@ -1,4 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as util from "../util.ts";
import { core } from "../core.ts";
import { ErrorKind, getErrorClass } from "../errors.ts";
@ -18,9 +19,10 @@ interface JsonResponse {
}
// Using an object without a prototype because `Map` was causing GC problems.
const promiseTable: {
[key: number]: util.Resolvable<JsonResponse>;
} = Object.create(null);
const promiseTable: Record<
number,
util.Resolvable<JsonResponse>
> = Object.create(null);
let _nextPromiseId = 1;
function nextPromiseId(): number {
@ -28,13 +30,11 @@ function nextPromiseId(): number {
}
function decode(ui8: Uint8Array): JsonResponse {
const s = core.decode(ui8);
return JSON.parse(s) as JsonResponse;
return JSON.parse(core.decode(ui8));
}
function encode(args: object): Uint8Array {
const s = JSON.stringify(args);
return core.encode(s);
return core.encode(JSON.stringify(args));
}
function unwrapResponse(res: JsonResponse): Ok {
@ -80,7 +80,7 @@ export async function sendAsync(
const promise = util.createResolvable<Ok>();
const argsUi8 = encode(args);
const buf = core.dispatchByName(opName, argsUi8, ...zeroCopy);
if (buf) {
if (buf != null) {
// Sync result.
const res = decode(buf);
promise.resolve(res);