diff options
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/10_dispatch_json.js | 84 | ||||
-rw-r--r-- | cli/tsc/99_main_compiler.js | 20 |
2 files changed, 5 insertions, 99 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); diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 80f7b2233..e5abbd144 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -17,9 +17,8 @@ delete Object.prototype.__proto__; ((window) => { - const core = Deno.core; + const core = window.Deno.core; const { assert, log, notImplemented } = window.__bootstrap.util; - const dispatchJson = window.__bootstrap.dispatchJson; const util = window.__bootstrap.util; const errorStack = window.__bootstrap.errorStack; const errors = window.__bootstrap.errors.errors; @@ -78,7 +77,7 @@ delete Object.prototype.__proto__; } function opNow() { - const res = dispatchJson.sendSync("op_now"); + const res = core.jsonOpSync("op_now"); return res.seconds * 1e3 + res.subsecNanos / 1e6; } @@ -1252,7 +1251,7 @@ delete Object.prototype.__proto__; } function opCompilerRespond(msg) { - dispatchJson.sendSync("op_compiler_respond", msg); + core.jsonOpSync("op_compiler_respond", msg); } async function tsCompilerOnMessage(msg) { @@ -1292,21 +1291,12 @@ delete Object.prototype.__proto__; } } - // TODO(bartlomieju): temporary solution, must be fixed when moving - // dispatches to separate crates - function initOps() { - const opsMap = core.ops(); - for (const [_name, opId] of Object.entries(opsMap)) { - core.setAsyncHandler(opId, dispatchJson.asyncMsgFromRust); - } - } - function runtimeStart(source) { - initOps(); + core.ops(); // First we send an empty `Start` message to let the privileged side know we // are ready. The response should be a `StartRes` message containing the CLI // args and other info. - const s = dispatchJson.sendSync("op_start"); + const s = core.jsonOpSync("op_start"); util.setLogDebug(s.debugFlag, source); errorStack.setPrepareStackTrace(Error); return s; |