summaryrefslogtreecommitdiff
path: root/std/wasi/snapshot_preview1_test_runner.ts
blob: 39f32db57ef576920801791e410b418afdb4f067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import Context from "./snapshot_preview1.ts";

const options = JSON.parse(Deno.args[0]);
const pathname = Deno.args[1];
const binary = await Deno.readFile(pathname);
const module = await WebAssembly.compile(binary);

const context = new Context({
  env: options.env,
  args: [pathname].concat(options.args),
  preopens: options.preopens,
});

const instance = new WebAssembly.Instance(module, {
  "wasi_snapshot_preview1": context.exports,
});

const memory = instance.exports.memory as WebAssembly.Memory;
context.memory = memory;

const start = instance.exports._start as CallableFunction;
start();