1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00
denoland-deno/std/wasi/snapshot_preview1_test_runner.ts

23 lines
676 B
TypeScript

// 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();