Como o WASM é executado no navegador
Entenda o modelo de execução por trás do WebAssembly: como o mecanismo compila, instancia e executa WASM junto com JavaScript.
Como o WASM é executado no navegador é uma aula grátis de WebAssembly (WASM) for High Performance Apps no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de WebAssembly (WASM) for High Performance Apps, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de WebAssembly (WASM) for High Performance Apps inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
WASM Is Not Interpreted Bytecode... Quite
WASM ships as a compact binary that the browser engine turns into fast machine code — compiled and run near native speed, not interpreted line-by-line. Let's trace its path.
The .wasm Binary
A WASM module is a .wasm file: a stack-based binary with sections for types, functions, memory, and exports. WAT is its readable text twin.
(module
(func (export "add") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add))Step 1: Fetch the Module
Step 1: the browser fetches the binary, usually with fetch, reading it into an ArrayBuffer.
const response = await fetch('add.wasm');
const bytes = await response.arrayBuffer();Step 2: Compile
Step 2: the engine validates and compiles those bytes into machine code, producing a WebAssembly.Module.
const module = await WebAssembly.compile(bytes);Step 3: Instantiate
Step 3: instantiation creates a live WebAssembly.Instance with its own memory and exported functions, ready to call.
const instance = await WebAssembly.instantiate(module, {});
const add = instance.exports.add;Streaming Compilation
Streaming compilation compiles while downloading — no buffering the whole file first. Use instantiateStreaming for the fastest start.
const { instance } = await WebAssembly.instantiateStreaming(
fetch('add.wasm'), {}
);Calling Exported Functions
Once instantiated, WASM exports behave like ordinary JS functions — just call them with arguments and get results back.
const result = instance.exports.add(2, 3);
console.log(result); // 5Linear Memory
Linear memory is one contiguous, resizable ArrayBuffer that both JS and WASM read and write. It's how larger data crosses the boundary.
const mem = new Uint8Array(instance.exports.memory.buffer);The Sandbox
WASM runs in a strict sandbox: no direct DOM, network, or file access — it can only call functions JS imports in. That's what keeps it safe and portable.
Importing JS Into WASM
To give WASM capabilities, pass an imports object at instantiation. WASM can then call those JS functions — the only way it reaches the outside world.
const imports = { env: { log: (x) => console.log(x) } };
const { instance } = await WebAssembly.instantiate(bytes, imports);Putting It Together
The lifecycle in one line: fetch, compile, instantiate, call. Data crosses via linear memory, and JS controls the sandbox through imports.
Quick Check
Which API both compiles and instantiates a WASM module as it downloads?
Recap
Recap: a binary is fetched, compiled, and instantiated; streaming overlaps the two; exports act like JS functions sharing linear memory; the sandbox stays safe via imports.
Aprenda WebAssembly (WASM) for High Performance Apps com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 12
- Aulas
- 48
Perguntas Frequentes
A aula “Como o WASM é executado no navegador” é grátis?
Sim — o texto completo de “Como o WASM é executado no navegador” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de WebAssembly (WASM) for High Performance Apps, atualize para CoddyKit PRO. O curso de WebAssembly (WASM) for High Performance Apps inclui 4 aulas no total.
O que vou aprender em “Como o WASM é executado no navegador”?
Entenda o modelo de execução por trás do WebAssembly: como o mecanismo compila, instancia e executa WASM junto com JavaScript. Você pratica WebAssembly (WASM) for High Performance Apps com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar WebAssembly (WASM) for High Performance Apps?
Nenhuma experiência prévia é necessária. WebAssembly (WASM) for High Performance Apps no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Como o WASM é executado no navegador”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de WebAssembly (WASM) for High Performance Apps?
Sim. Cada aula de WebAssembly (WASM) for High Performance Apps inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- O que é WebAssembly (WASM)?
- Por que usar WASM? Principais benefícios
- Ecossistema e ferramentas do WASM
- Como o WASM é executado no navegador