diff options
author | Stanislav <62983943+stanislavstrelnikov@users.noreply.github.com> | 2020-07-07 04:45:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 21:45:39 -0400 |
commit | 158ae0bfe900d2bac3076390c4fe3d2b54d94fe5 (patch) | |
tree | 209e4b5682e2a899041767c49428e34329e48084 /cli/js/ops/dispatch_json.ts | |
parent | ab4c574f5202f607ceb6068f56b3cc8aed1bbbaf (diff) |
clean up code in cli/js (#6611)
Diffstat (limited to 'cli/js/ops/dispatch_json.ts')
-rw-r--r-- | cli/js/ops/dispatch_json.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cli/js/ops/dispatch_json.ts b/cli/js/ops/dispatch_json.ts index 6a91f6a4f..cf6f5c095 100644 --- a/cli/js/ops/dispatch_json.ts +++ b/cli/js/ops/dispatch_json.ts @@ -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); |