nodejs/node
WASI
Owners: @nodejs/wasi. Public docs at doc/api/wasi.md.
Purpose
Provide a host implementation of the WebAssembly System Interface (WASI) so WebAssembly modules can perform file system, environment variable, and clock operations from inside Node. The implementation is built on uvwasi, a portable WASI runtime that itself sits on libuv.
Directory layout
lib/wasi.js // public node:wasi module
src/
node_wasi.{cc,h} // Node binding to uvwasi
deps/
uvwasi/ // upstream uvwasi
test/
wasi/ // integration tests + .wasm fixtures
fixtures/wasi/ // Wasm binariesKey abstractions
| Type / file | Role |
|---|---|
WASI (lib/wasi.js) |
Public class; constructed with args, env, preopens. |
wasi.start(instance) |
Calls the Wasm _start entry; reaped exit codes propagate. |
wasi.initialize(instance) |
Reactor-style instantiate; calls _initialize. |
wasi.getImportObject() |
Imports map handed to WebAssembly.instantiate. |
node_wasi::WASI (src/node_wasi.cc) |
C++ wrapping uvwasi_t. |
How a WASI instance is wired
graph LR
JS[new WASI({...})] --> CppCtor[node_wasi::WASI ctor]
CppCtor --> uvwasi[uvwasi_init]
uvwasi --> uv[libuv FS / env / clock]
JS --> Imports[wasi.getImportObject()]
Imports --> Instance[WebAssembly.instantiate]
Instance --> Mem[Memory shared with WASI]
JS --> Start[wasi.start(instance)]
Start --> Wasm[Wasm exports._start]
Wasm --> Imports
Imports --> uvwasiThe import object is a thin shim — each WASI ABI function calls into the C++ binding which calls into uvwasi. The Wasm memory is read once during start so that path resolution and returned buffers can be addressed.
Permission model
WASI is gated by the wasi permission domain (src/permission/wasi_permission.cc). Even with --allow-wasi, the underlying FS operations re-check fs permissions on the preopen paths.
Integration points
- uvwasi: vendored at
deps/uvwasi/; updates flow throughtools/dep_updaters/(no dedicated script — pulled with general updates). WebAssemblyAPI:wasidoes not link Wasm itself; the user callsWebAssembly.instantiateand passeswasi.getImportObject().
Entry points for modification
- Behaviour bug? Most are upstream in
uvwasi. Sometimes the binding glue insrc/node_wasi.ccis at fault. - New WASI version (preview2 / Component Model)? Likely starts as an experimental module behind a flag and a separate vendored runtime.
- Tests at
test/wasi/exercise both_startand_initializeentry points.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.