summaryrefslogtreecommitdiff
path: root/cli/js/compiler_util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r--cli/js/compiler_util.ts22
1 files changed, 13 insertions, 9 deletions
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts
index b58d8da43..a28e2d109 100644
--- a/cli/js/compiler_util.ts
+++ b/cli/js/compiler_util.ts
@@ -92,15 +92,19 @@ function cache(
}
let OP_FETCH_ASSET: number;
+const encoder = new TextEncoder();
+const decoder = new TextDecoder();
-/**
- * This op is called only during snapshotting.
- *
- * We really don't want to depend on JSON dispatch
- * during snapshotting, so this op exchanges strings with Rust
- * as raw byte arrays.
- */
+/** 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"];
@@ -108,8 +112,8 @@ export function getAsset(name: string): string {
OP_FETCH_ASSET = opFetchAsset;
}
- const encoder = new TextEncoder();
- const decoder = new TextDecoder();
+ // 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));
return decoder.decode(sourceCodeBytes!);
}