Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(std/wasi): fix usage example #7808

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions std/wasi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
);
}
```

Expand Down