Skip to main content
The wasm utility is a command-line WebAssembly runtime that can parse, validate, instantiate, and execute WebAssembly modules. It supports WASI (WebAssembly System Interface) for system interactions and provides integration with JavaScript functions.

Usage

Basic syntax

Command-line options

Module operations

Execution options

WASI support

WASI is not available on Windows builds.

JavaScript integration

Argument value format

The --arg option accepts values in the following formats:

Scalar values

Vector values (v128)

Hexadecimal format:
Component format:
When using vector component format, all values must have the same type. Mixed types will result in an error.

Smaller integer types

JavaScript export format

The --export-js option uses this format:

Examples

Supported types

  • i32 - 32-bit integer
  • i64 - 64-bit integer
  • f32 - 32-bit float
  • f64 - 64-bit float
  • v128 - 128-bit vector

Examples

Parse and print a module

Instantiate and execute a function

Execute with arguments

WASI module execution

Map host directories to WASI

When no mapping is specified (e.g., /home/user/data), the directory is mapped to the same path in the WASI filesystem.

Export JavaScript functions

Debug compiled bytecode

Export no-op stubs for testing

Output format

Module structure

When using --print, the utility displays:
  • Module sections
  • Function signatures
  • Import/export declarations
  • Memory and table definitions

Compiled bytecode

When using --print-compiled, displays:
  • Function addresses
  • Stack usage hints
  • Instruction sequences
  • Register assignments

Function return values

Execution results are printed to stderr:

WASI implementation

Supported WASI functions

The WASI implementation supports:
  • Command-line argument access
  • Environment variable access
  • File system operations via preopened directories
  • Standard input/output/error

Exit codes

WASI modules can exit with custom exit codes:
If a WASM trap contains exit:N, the utility returns the negated exit code. For example, exit:0 returns 0, and exit:1 returns -1.

Error handling

Parse errors

Runtime traps

Advanced features

Module linking

You can link multiple WASM modules to resolve imports:
Modules are linked in order, and exports from earlier modules can satisfy imports in later modules.

Bytecode inspection

Inspect compiled bytecode for specific functions:
Output includes:
  • Instruction pointer
  • Register allocations
  • Source/destination mappings

JavaScript callbacks

WASM modules can call back into JavaScript:
The JavaScript function is compiled and executed when the WASM module calls the import.

Platform support

Linux/macOS: Full support including WASI. Windows: Basic WASM support without WASI functionality.

Implementation details

WebAssembly engine

The utility uses LibWasm, Ladybird’s WebAssembly implementation:
  • Full WebAssembly 1.0 support
  • Bytecode interpreter
  • Register allocation optimization
  • Module validation

JavaScript integration

JavaScript exports are compiled using LibJS and executed through the bytecode interpreter. Type conversions are automatic:
  • WASM integers → JS numbers
  • WASM floats → JS numbers
  • WASM v128 → JS BigInt
  • js - JavaScript interpreter (can execute WASM-generated JS glue code)
  • test262-runner - Test runner that may include WASM-related tests

Source code

Source file: Utilities/wasm.cpp