WebAssembly global. You can load a .wasm file, compile it, and call its exported functions — all from ordinary JavaScript with no native extensions required. WASI support is built in, which means you can run programs compiled from C, Rust, or Go as WebAssembly inside Ant.
Load and run a WASM module
The most common pattern isWebAssembly.instantiate(bytes, imports). You pass the raw bytes of a .wasm file and an optional imports object, and Ant returns a compiled instance whose exports you can call directly.
examples/wasm/index.mjs from the Ant repository. It reads a .wasm file from the command line, instantiates it with WASI enabled, and calls _start() — the conventional entry point for WASI programs.
Run it with:
WASI enables WASM modules to access system capabilities — standard I/O, command-line arguments, and more — in a sandboxed, portable way. Pass
{ wasi: { args } } in the imports object to enable it.WebAssembly API reference
Ant exposes the full standardWebAssembly global. The most useful entry points are below.
WebAssembly.instantiate
bytes can be a Uint8Array, ArrayBuffer, or any typed array containing the raw .wasm binary. Returns a promise that resolves to an object with both the compiled module and a ready-to-call instance.
WebAssembly.compile
WebAssembly.Module without instantiating it. Use this when you want to compile once and instantiate multiple times with different import objects.
new WebAssembly.Instance
WebAssembly.Module. This blocks the current thread and is suitable when you hold a pre-compiled module and want a quick, synchronous setup.
WebAssembly.validate
true if bytes is a valid WASM binary, false otherwise. Use this to check user-supplied files before attempting to compile or instantiate them.
Working with WASM exports
Once you have aninstance, its exports object contains all the functions and memory the module exposes. The exact shape depends on the module.
- WASI program
- Library module
- Compile once, run many
WASI programs compiled from C, Rust, or Go typically export
_start, which is equivalent to main().Minimal inline WASM
You can construct a WASM module from aUint8Array without touching the filesystem. The bytes must form a valid WASM binary. Every WASM binary starts with the 4-byte magic \0asm followed by the 4-byte version 1. After that, sections describe types, functions, exports, and code.