TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/LadybirdBrowser/ladybird/llms.txt
Use this file to discover all available pages before exploring further.
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
| Option | Description |
|---|---|
-p, --print | Print the parsed WebAssembly module |
--print-compiled | Print the compiled module bytecode |
-f, --print-function <address> | Print specific function bytecode by address |
-i, --instantiate | Instantiate the module (resolve imports and initialize) |
Execution options
| Option | Description |
|---|---|
-e, --execute <name> | Execute the named exported function (implies -i) |
--arg <value> | Supply arguments to the function (see value format below) |
-l, --link <file> | Link with additional WASM modules to resolve imports |
--export-noop | Export no-op stub functions for all imports |
WASI support
| Option | Description |
|---|---|
-w, --wasi | Enable WASI (WebAssembly System Interface) |
--wasi-map-dir <path[:path]> | Map host directory to WASI filesystem |
<args> | Positional arguments passed to WASI module |
WASI is not available on Windows builds.
JavaScript integration
| Option | Description |
|---|---|
--export-js <spec> | Export JavaScript function as WASM import (see format below) |
Argument value format
The--arg option accepts values in the following formats:
Scalar values
Vector values (v128)
Hexadecimal format:Smaller integer types
JavaScript export format
The--export-js option uses this format:
Examples
Supported types
i32- 32-bit integeri64- 64-bit integerf32- 32-bit floatf64- 64-bit floatv128- 128-bit vector
Examples
Parse and print a module
Instantiate and execute a function
Execute with arguments
Link multiple modules
WASI module execution
Map host directories to WASI
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
Link errors
Runtime traps
Advanced features
Module linking
You can link multiple WASM modules to resolve imports:Bytecode inspection
Inspect compiled bytecode for specific functions:- Instruction pointer
- Register allocations
- Source/destination mappings
JavaScript callbacks
WASM modules can call back into JavaScript: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
Related utilities
- 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