diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-09-16 22:22:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 22:22:43 +0200 |
commit | 6c4da0e429eb47dae6a220c5576a39f137615bb8 (patch) | |
tree | a8715428caea00105acc9a10fcd0f356085d3fa7 /cli/tsc/10_dispatch_json.js | |
parent | 104aebdfb5d01f7482bacef6d58c2ce16da44334 (diff) |
refactor: remove dispatch_json.js from cli/rt and cli/tsc (#7521)
Instead use Deno.core.jsonOpSync and Deno.core.jsonOpAsync
Diffstat (limited to 'cli/tsc/10_dispatch_json.js')
-rw-r--r-- | cli/tsc/10_dispatch_json.js | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/cli/tsc/10_dispatch_json.js b/cli/tsc/10_dispatch_json.js deleted file mode 100644 index 7989f5568..000000000 --- a/cli/tsc/10_dispatch_json.js +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -((window) => { - const core = window.Deno.core; - const util = window.__bootstrap.util; - - // Using an object without a prototype because `Map` was causing GC problems. - const promiseTable = Object.create(null); - let _nextPromiseId = 1; - - function nextPromiseId() { - return _nextPromiseId++; - } - - function decode(ui8) { - return JSON.parse(core.decode(ui8)); - } - - function encode(args) { - return core.encode(JSON.stringify(args)); - } - - function unwrapResponse(res) { - if (res.err != null) { - throw new (core.getErrorClass(res.err.className))(res.err.message); - } - util.assert(res.ok != null); - return res.ok; - } - - function asyncMsgFromRust(resUi8) { - const res = decode(resUi8); - util.assert(res.promiseId != null); - - const promise = promiseTable[res.promiseId]; - util.assert(promise != null); - delete promiseTable[res.promiseId]; - promise.resolve(res); - } - - function sendSync( - opName, - args = {}, - ...zeroCopy - ) { - util.log("sendSync", opName); - const argsUi8 = encode(args); - const resUi8 = core.dispatchByName(opName, argsUi8, ...zeroCopy); - util.assert(resUi8 != null); - const res = decode(resUi8); - util.assert(res.promiseId == null); - return unwrapResponse(res); - } - - async function sendAsync( - opName, - args = {}, - ...zeroCopy - ) { - util.log("sendAsync", opName); - const promiseId = nextPromiseId(); - args = Object.assign(args, { promiseId }); - const promise = util.createResolvable(); - const argsUi8 = encode(args); - const buf = core.dispatchByName(opName, argsUi8, ...zeroCopy); - if (buf != null) { - // Sync result. - const res = decode(buf); - promise.resolve(res); - } else { - // Async result. - promiseTable[promiseId] = promise; - } - - const res = await promise; - return unwrapResponse(res); - } - - window.__bootstrap.dispatchJson = { - asyncMsgFromRust, - sendSync, - sendAsync, - }; -})(this); |