summaryrefslogtreecommitdiff
path: root/cli/js/compiler_util.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-01-28 03:12:25 +0100
committerRyan Dahl <ry@tinyclouds.org>2020-01-27 21:12:25 -0500
commitac10d79d231d3b66b918764b9706597321850687 (patch)
tree6a781c58075ee0c68091e71d2ffd2bb898dc9dfd /cli/js/compiler_util.ts
parentf604becaba0c747fdf8dd9d0d744c7bd19322e41 (diff)
refactor: isomorphic snapshot for CLI (#3728)
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r--cli/js/compiler_util.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts
index fbb30d67d..f541ea46f 100644
--- a/cli/js/compiler_util.ts
+++ b/cli/js/compiler_util.ts
@@ -90,6 +90,9 @@ function cache(
assert(false, `Trying to cache unhandled file type "${emittedFileName}"`);
}
}
+
+let OP_FETCH_ASSET: number;
+
/**
* This op is called only during snapshotting.
*
@@ -98,12 +101,16 @@ function cache(
* as raw byte arrays.
*/
export function getAsset(name: string): string {
+ 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 encoder = new TextEncoder();
const decoder = new TextDecoder();
- const sourceCodeBytes = core.dispatch(
- dispatch.OP_FETCH_ASSET,
- encoder.encode(name)
- );
+ const sourceCodeBytes = core.dispatch(OP_FETCH_ASSET, encoder.encode(name));
return decoder.decode(sourceCodeBytes!);
}