Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# WebAssembly标准入门
## 【One-Line Pitch】
A comprehensive, hands-on introduction to WebAssembly—the new standard for high-performance, portable, secure code in the browser—covering everything from JavaScript integration to the underlying assembly language and binary format. Ideal for web developers seeking near-native performance, as well as C/C++ and Go programmers who want to run their code in the browser.
## 【Book Arc】
- **Opening (~0%–9%)**: The book opens with the history of web technologies—from JavaScript's rise via Ajax and the V8 engine, to earlier failed attempts at running native code in the browser (NPAPI, ActiveX, NaCL) and the eventual emergence of WebAssembly from asm.js. It then reviews essential JavaScript concepts (functions, closures, Promises, typed arrays) that serve as prerequisites for working with WebAssembly.
- **Early (~9%–26%)**: Introduces the JavaScript API for WebAssembly: compiling and instantiating modules, the WebAssembly.Module object (including caching and custom sections), and the WebAssembly.Memory object for sharing data between JavaScript and WebAssembly. Covers practical patterns like fetchAndInstantiate() and memory growth.
- **Early (~26%–30%)**: Explains the WebAssembly.Table object—a critical mechanism for implementing function pointers safely. Discusses why tables exist (security), how to create and populate them from JavaScript, and how WebAssembly code calls functions indirectly through table indices.
- **Middle (~30%–48%)**: Dives into the WebAssembly assembly language (text format, .wat). Covers S-expressions, function signatures, local variables, globals, the stack-based virtual machine model, control flow (if/block/loop/br_table/return), and import/export declarations. Includes the start section for auto-executed functions.
- **Middle (~48%–52%)**: Explains the binary format (.wasm), focusing on LEB128 variable-length integer encoding—the foundation for compact binary representation. Walks through a concrete example of encoding a number and dissects a minimal binary module section by section (Type, Function, Code segments).
## 【Key Takeaways】
- **WebAssembly solves JavaScript's performance ceiling** (Early): By providing a compact binary format that browsers can parse and optimize faster than JavaScript, WebAssembly achieves near-native execution speeds while remaining portable and secure. This matters for compute-intensive web applications like games, image processing, and scientific computing.
- **The JavaScript API is the gateway** (Early): WebAssembly.compile() and WebAssembly.instantiate() are the primary asynchronous methods for loading modules. The streaming variants (compileStreaming/instantiateStreaming) are simpler but have limited browser support (Safari lacks them), so the book recommends the non-streaming versions for compatibility.
- **Memory is a shared, linear array** (Early): WebAssembly.Memory is essentially an ArrayBuffer that both JavaScript and WebAssembly can access. A single memory object can be shared across multiple instances for inter-module communication. Key constraint: TypedArray views must be recreated after memory growth, and maximum capacity limits growth attempts.
- **Tables enable safe function pointers** (Early): Because WebAssembly code cannot see real memory addresses, the Table object stores function references by index, allowing indirect calls (call_indirect) without exposing raw pointers. This design prevents malicious code from jumping to arbitrary addresses—a fundamental security feature.
- **The stack machine model is the core abstraction** (Middle): WebAssembly is a stack-based virtual machine: instructions pop operands from and push results onto an operand stack. Understanding this model is essential for reading and writing .wat code, as every instruction's behavior is defined by its stack effects.
- **Control flow uses structured blocks** (Middle): Unlike unstructured jumps, WebAssembly uses block, loop, and if constructs with labeled break targets (br, br_if, br_table). This structured approach keeps code verifiable and safe. The return instruction provides an early exit from functions.
- **LEB128 encoding keeps binaries small** (Middle): Variable-length integer encoding uses 7 bits per byte with a continuation flag, making small numbers compact (1 byte for values < 128) while still supporting 64-bit integers. This is a key reason WebAssembly modules are smaller than equivalent asm.js code.
- **i64 has a JavaScript boundary limitation** (Early): JavaScript's Number type cannot precisely represent 64-bit integers, so exported functions cannot use i64 parameters or return values—attempting to do so throws a TypeError. This is a practical constraint for cross-language interop.
## 【Reading Tips】
- **Skim the JavaScript history (0–4%)** if you're already familiar with web platform evolution; it's context-setting but not essential for hands-on work. Do read the JavaScript refresher on Promises and typed arrays if you need a quick review.
- **Deep-read Chapters 3 and 4** (Early–Middle): These are the heart of the book. Work through every code example—especially the fibonacci and table-call examples—by running them in your browser. The .wat syntax becomes intuitive only through practice.
- **Pay special attention to the Table and call_indirect material** (Early): This is the most conceptually challenging part for newcomers. The security rationale and the "index instead of address" model are worth understanding thoroughly before moving on.
- **The binary format chapter (Middle)** can be skimmed on first reading unless you're building tooling. Focus on understanding LEB128 conceptually and recognizing the section structure; you can return to byte-level details when needed.
- **Use the appendix of 200+ instructions** as a reference rather than reading it linearly. When you encounter an unfamiliar instruction in examples, look it up there.
## 【Coverage Limits】
This guide covers the book's core content: JavaScript API usage, the .wat text format, and the binary format fundamentals. The excerpts do not cover the later chapters on C/C++ and Go toolchain integration, which the book's introduction promises but which fall outside the sampled material.
##
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
WebAssembly标准入门 (Unknown)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
WebAssembly标准入门 (Unknown)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
WebAssembly标准入门 (Unknown)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment