summaryrefslogtreecommitdiff
path: root/cli/js/compiler_util.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-01-22 23:58:13 +0100
committerGitHub <noreply@github.com>2020-01-22 23:58:13 +0100
commit63293a90e1503aa9c18ce5f89ebc6d5c066f09bf (patch)
treecef7439565c558bede48bff6cf8cc527689808a9 /cli/js/compiler_util.ts
parentbd9561f4de8f940ce6ed8b5eedfa84161a749c54 (diff)
refactor: snapshotting (#3753)
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r--cli/js/compiler_util.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts
index bff3bcd51..fbb30d67d 100644
--- a/cli/js/compiler_util.ts
+++ b/cli/js/compiler_util.ts
@@ -7,7 +7,8 @@ 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 { TextEncoder } from "./text_encoding.ts";
+import { TextDecoder, TextEncoder } from "./text_encoding.ts";
+import { core } from "./core.ts";
import * as util from "./util.ts";
import { assert } from "./util.ts";
import { writeFileSync } from "./write_file.ts";
@@ -89,12 +90,27 @@ function cache(
assert(false, `Trying to cache unhandled file type "${emittedFileName}"`);
}
}
-
-const encoder = new TextEncoder();
+/**
+ * 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.
+ */
+export function getAsset(name: string): string {
+ const encoder = new TextEncoder();
+ const decoder = new TextDecoder();
+ const sourceCodeBytes = core.dispatch(
+ dispatch.OP_FETCH_ASSET,
+ encoder.encode(name)
+ );
+ return decoder.decode(sourceCodeBytes!);
+}
/** Generates a `writeFile` function which can be passed to the compiler `Host`
* to use when emitting files. */
export function createWriteFile(state: WriteFileState): WriteFileCallback {
+ const encoder = new TextEncoder();
if (state.type === CompilerRequestType.Compile) {
return function writeFile(
fileName: string,