Browser Target

← WASM
Io

Io runs in the browser as a WebAssembly module. The browser build compiles the full VM into a WASM reactor module that JS loads and drives via exported functions.

Building

make browser        # build browser/io_browser.wasm
make serve          # serve REPL at http://localhost:8000
make check-browser  # run headless Playwright tests

Requires wasi-sdk for cross-compilation and Node.js + Playwright for headless tests.

Architecture

┌──────────────────────────────────────────────┐
│  Browser (JS)                                │
│                                              │
│  io.js                                       │
│  ├── WASI shim (fd_write, clock, etc.)       │
│  ├── DOM handle table (Map<int, Element>)    │
│  ├── DOM bridge functions (dom namespace)    │
│  ├── WASM loader (loadIo / ioEval)           │
│  └── REPL UI wiring                          │
│                                              │
│  ┌────────────────────────────────────────┐  │
│  │  WebAssembly (io_browser.wasm)         │  │
│  │                                        │  │
│  │  io_browser.c — init, eval, I/O        │  │
│  │  io_dom.c    — DOM/Element protos      │  │
│  │  iovm/*      — full Io VM              │  │
│  └────────────────────────────────────────┘  │
└──────────────────────────────────────────────┘

The WASM module is built with -mexec-model=reactor (no main()). JS calls exported functions:

ExportPurpose
io_init()Initialize the Io VM (call once)
io_get_input_buf()Pointer to 64KB input buffer
io_eval_input()Evaluate code written to input buffer
io_get_output()Pointer to output string
io_get_output_len()Length of output

WASI Shim

The browser has no filesystem or OS. io.js provides a minimal WASI shim:

  • stdout/stderr — captured to a JS string
  • clockperformance.now() in nanoseconds
  • filesystem — all path operations return ENOTCAPABLE
  • proc_exit — throws a JS Error
  • randomcrypto.getRandomValues()

Files

FilePurpose
browser/io_browser.cReactor entry point: init, eval, output capture
browser/io_dom.cDOM and Element proto implementation
browser/io_dom.hHeader for DOM protos
browser/io.jsWASI shim, DOM bridge, WASM loader, REPL UI
browser/index.htmlREPL page
browser/test.htmlAutomated test page
browser/run_tests.mjsHeadless Playwright test runner