diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-02-25 09:14:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 09:14:27 -0500 |
commit | 91b606aaae23bcb790b55adc5fe70a182a37d564 (patch) | |
tree | 16b56a21ffcb3991569eda984fbd14073bdbd3ae /cli/js/compiler_util.ts | |
parent | 805992b14a65a6dbfb857dea6d9b657477de043d (diff) |
Clean up how we use opIds (#4118)
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r-- | cli/js/compiler_util.ts | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts index 6da38ab3b..8a043d7d1 100644 --- a/cli/js/compiler_util.ts +++ b/cli/js/compiler_util.ts @@ -6,7 +6,6 @@ import { buildBundle } from "./compiler_bundler.ts"; import { ConfigureResponse, Host } from "./compiler_host.ts"; import { SourceFile } from "./compiler_sourcefile.ts"; import { sendSync } from "./dispatch_json.ts"; -import * as dispatch from "./dispatch.ts"; import { TextDecoder, TextEncoder } from "./text_encoding.ts"; import { core } from "./core.ts"; import * as util from "./util.ts"; @@ -71,7 +70,7 @@ function cache( if (emittedFileName.endsWith(".map")) { // Source Map - sendSync(dispatch.OP_CACHE, { + sendSync("op_cache", { extension: ".map", moduleId, contents @@ -81,7 +80,7 @@ function cache( emittedFileName.endsWith(".json") ) { // Compiled JavaScript - sendSync(dispatch.OP_CACHE, { + sendSync("op_cache", { extension: ".js", moduleId, contents @@ -91,30 +90,15 @@ function cache( } } -let OP_FETCH_ASSET: number; const encoder = new TextEncoder(); const decoder = new TextDecoder(); /** Retrieve an asset from Rust. */ export function getAsset(name: string): string { - // this path should only be called for assets that are lazily loaded at - // runtime - if (dispatch.OP_FETCH_ASSET) { - util.log("compiler_util::getAsset", name); - return sendSync(dispatch.OP_FETCH_ASSET, { name }).sourceCode; - } - - // this path should only be taken during snapshotting - if (!OP_FETCH_ASSET) { - const ops = core.ops(); - const opFetchAsset = ops["fetch_asset"]; - assert(opFetchAsset, "OP_FETCH_ASSET is not registered"); - OP_FETCH_ASSET = opFetchAsset; - } - + const opId = core.ops()["op_fetch_asset"]; // We really don't want to depend on JSON dispatch during snapshotting, so // this op exchanges strings with Rust as raw byte arrays. - const sourceCodeBytes = core.dispatch(OP_FETCH_ASSET, encoder.encode(name)); + const sourceCodeBytes = core.dispatch(opId, encoder.encode(name)); return decoder.decode(sourceCodeBytes!); } |