Saltar al contenido ForoHackers

WebAssembly: start here

WebAssembly
#3091 · · Citar · Denunciar

WebAssembly is a compact binary instruction format for a portable, sandboxed virtual machine. Languages such as C, C++ and Rust compile to it, and browsers run it next to JavaScript at near-native speed. Outside the browser, it is used as a safe, portable way to run plugins and services. It is a compilation target more than a language you write by hand.

Key concepts

  • Stack machine and modules: a module has typed functions with simple instructions over a value stack.
  • Linear memory: one resizable array of bytes that the module addresses; the host decides what else it can reach.
  • Sandboxing: a module can only do what its imports allow, with no direct access to the system.
  • Imports and exports: functions passed in from the host and exposed back to it.
  • Host interface: in a browser, JavaScript glues modules to the page; outside, a system interface standardises file and clock access.
  • Text and binary formats: a readable text form for study and a compact binary for delivery.

Vocabulary

  • Module: the compiled unit of WebAssembly, validated before it runs.
  • Runtime: the engine that executes modules, in a browser or standalone.
  • WASI: the system interface for running WebAssembly outside browsers.
  • Toolchain: a compiler and linker that target WebAssembly from another language.

What to study, in order

  1. Read a small module in its text format and run it with a standalone runtime.
  2. Compile a C or Rust function to WebAssembly and call it from JavaScript.
  3. Pass strings and structures through linear memory, and see why it is manual.
  4. Run a module outside the browser and limit what it may access.
  5. Compare performance with plain JavaScript on a computation-heavy task.
  6. Read the specification's validation and execution sections.

Related tags

#rust #javascript #browsers #runtimes

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder