Skip to content

wasmExec

wasmExec(opts): Promise<ExitCode>

Defined in: packages/runtime/src/wasm/runtime.ts:97

Execute an Emscripten-compiled WASM program within a fishbowl process.

  1. Pre-load preloadPaths from proc.fs into Emscripten’s MEMFS
  2. Initialize the Emscripten module with env injected via preRun
  3. Run the program — raw TTY mode drives via the Asyncify bridge and _main; line mode uses a pre-buffered synchronous stdin callback and callMain
  4. Sync modified and newly-created files from MEMFS back to proc.fs
  5. Return the program’s exit code

WasmExecOptions

See WasmExecOptions.

Promise<ExitCode>

The program’s exit code.

Emscripten reads ENV during preRun, not after module init — env vars are injected via a preRun hook for this reason.

module.locateFile is stubbed to return the input path unchanged, preventing the glue from calling new URL(name, import.meta.url) which fails when the glue is evaluated outside its original module context (e.g. served from the HTTP registry and eval’d as CJS).

In line mode, stdin is fully buffered before callMain because Emscripten’s module.stdin callback is synchronous.

const code = await wasmExec({
wasmBinary, glueFactory, proc, args: proc.argv, ttyMode: 'line'
})