summaryrefslogtreecommitdiff
path: root/std/wasi
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-10-03 21:52:34 +0800
committerGitHub <noreply@github.com>2020-10-03 15:52:34 +0200
commite8b93674eda5e337587d596f23745c81511e1f0a (patch)
treeb9f42bec9f076a7db84afbe2e1b51966103b9606 /std/wasi
parentae1ed2d16687413381fc7e6b55dca9b1676855f6 (diff)
docs(std/wasi): fix usage example (#7808)
The usage example is a bit out of date and not compatible with the stricter definition of the WebAssembly namespace. This fixes that and makes it a bit cleaner.
Diffstat (limited to 'std/wasi')
-rw-r--r--std/wasi/README.md24
1 files changed, 16 insertions, 8 deletions
diff --git a/std/wasi/README.md b/std/wasi/README.md
index 580e7ddd0..1a2fc4c72 100644
--- a/std/wasi/README.md
+++ b/std/wasi/README.md
@@ -59,23 +59,31 @@ import Context from "https://deno.land/std/wasi/snapshot_preview1.ts";
const context = new Context({
args: Deno.args,
- env: Deno.env,
+ env: Deno.env.toObject(),
});
const binary = await Deno.readFile("path/to/your/module.wasm");
const module = await WebAssembly.compile(binary);
const instance = await WebAssembly.instantiate(module, {
- wasi_snapshot_preview1: context.exports,
+ "wasi_snapshot_preview1": context.exports,
});
-context.memory = context.exports.memory;
+const {
+ _start: start,
+ _initialize: initialize,
+ memory,
+} = instance.exports;
-if (module.exports._start) {
- instance.exports._start();
-} else if (module.exports._initialize) {
- instance.exports._initialize();
+context.memory = memory as WebAssembly.Memory;
+
+if (start instanceof Function) {
+ start();
+} else if (initialize instanceof Function) {
+ initialize();
} else {
- throw new Error("No entry point found");
+ throw new Error(
+ "No '_start' or '_initialize' entry point found in WebAssembly module, make sure to compile with wasm32-wasi as the target.",
+ );
}
```