Skip to content

Instantly share code, notes, and snippets.

@lilac
Created March 6, 2023 04:31
Show Gist options
  • Save lilac/99b8587365de140357eb9308537a614f to your computer and use it in GitHub Desktop.
Save lilac/99b8587365de140357eb9308537a614f to your computer and use it in GitHub Desktop.
A js interpreter in WebAssembly (wasm)

Playground

  • Install wazero with the following commmand.

    go get github.com/tetratelabs/wazero@latest
  • Download the wasm file of a Javascript interpreter. For simplicity, the following ways are listed.

    • If you have wapm installed, you could download one with

      wapm install mozilla/spidermonkey
    • If you don't want to depend on another package manager like wapm, you could download one such artificact using a direct url. This file contains the mapping of versions to urls. Pick one, and save it to somewhere like /tmp.

  • Run the wasm module.

    wazero run /tmp/js.wasm

    Now you're in the javascript repl. If you want command line navigation, rlwrap is handy.

    rlwrap wazero run /tmp/js.wasm
  • Compile the wasm module to native.

    wazero compile /tmp/js.wasm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment