WebAssembly in Action
Gerard Gallant
  • MEAP began November 2018
  • Publication in May 2019 (estimated)
  • ISBN 9781617295744
  • 375 pages (estimated)
  • printed in black & white

WebAssembly in the future and when you want to know what is going on, you should read this book.

Sander Zegveld

“Any application that can be written in JavaScript, will eventually be written in JavaScript.”
 — Jeff Atwood, Cofounder of StackOverflow

“Atwood’s Law” is driven by the idea that all applications will ultimately wind up on the web and therefore must be written in JavaScript. WebAssembly may be your way out! With WebAssembly, you can write in nearly any modern language and run your code in the browser through a memory-safe, sandboxed execution environment that can be embedded in a web browser and other platforms. Getting set up and moving with WebAssembly requires you to modify your web dev process; WebAssembly in Action will get you started quickly and guide you through real-world examples and detailed diagrams that help you create, run, and debug WebAssembly modules.
Table of Contents detailed table of contents

Part 1: First Steps

1 Meet WebAssembly

1.1 What is WebAssembly?

1.2 What problems does it solve?

1.2.1 Performance improvements

1.2.2 asm.js, the forerunner to WebAssembly

1.2.3 Faster startup times compared with JavaScript

1.2.4 Ability to use languages other than JavaScript in the browser

1.2.5 Opportunity for code reuse

1.3 How does it work?

1.3.1 Overview of how compilers work

1.3.2 Loading, compiling, and instantiating a module

1.3.3 Structure of a WebAssembly module

1.3.4 WebAssembly Text Format

1.4 How is WebAssembly secure?

1.5 What languages can I use to create a WebAssembly module?

1.6 Where can I use my module?

1.7 Summary

2 Before you get started

2.1 Known sections

2.2 Custom sections

2.3 Summary

3 Creating your first WebAssembly module

3.1 The Emscripten toolkit

3.2 WebAssembly modules

3.3 Compiling C or C++ with Emscripten and using the HTML template

3.4 JavaScript plumbing code

3.4.1 Compiling C or C++ with Emscripten generated JavaScript

3.4.2 Creating a basic HTML webpage for use in browsers

3.5 Only the WebAssembly file

3.5.1 Compiling C or C++ as a side module with Emscripten

3.5.2 Loading and instantiating in a browser

3.6 Feature detection: How to test if WebAssembly is available

3.7 Summary

Part 2: Working with Modules

4 Creating a WebAssembly module that JavaScript talks to

4.1 Using C or C++ to create a module with Emscripten plumbing

4.1.1 Making the C++ modifications

4.1.2 Compiling the code into a WebAssembly module

4.1.3 Creating the webpage

4.1.4 Creating the JavaScript that will interact with the module

4.1.5 Viewing the results

4.2 Using C or C++ to create a module without Emscripten

4.2.1 Making the C++ modifications

4.2.2 Compiling the code into a WebAssembly module

4.2.3 Creating the JavaScript that will interact with the module

4.2.4 Viewing the results

4.3 Summary

5 Creating a WebAssembly module that calls into JavaScript

5.1 Using C or C++ to create a module with Emscripten plumbing

5.1.1 Adjusting the C++ code

5.1.2 Creating the JavaScript that you want included in Emscripten’s generated JavaScript file

5.1.3 Compiling the code into a WebAssembly module

5.1.4 Adjusting the JavaScript code of the webpage

5.1.5 Viewing the results

5.2 Using C or C++ to create a module without Emscripten plumbing

5.2.1 Making the C++ modifications

5.2.2 Compiling the code into a WebAssembly module

5.2.3 Adjusting the JavaScript that will interact with the module

5.2.4 Viewing the results

5.3 Summary

6 Creating a WebAssembly module that talks to JavaScript using function pointers

6.1 Using C or C++ to create a module with Emscripten plumbing

6.1.1 Using a function pointer given to the module by JavaScript

6.1.2 Adjusting the C++ code

6.1.3 Compiling the code into a WebAssembly module

6.1.4 Adjusting the JavaScript code of the webpage

6.1.5 Viewing the results

6.2 Using C or C++ to create a module without Emscripten plumbing

6.2.1 Using function pointers given to the module by JavaScript

6.2.2 Making the C++ modifications

6.2.3 Compiling the code into a WebAssembly module

6.2.4 Adjusting the JavaScript that will interact with the module

6.2.5 Viewing the results

6.3 Summary

Part 3: Advanced Topics

7 Dynamic linking: the basics

7.1 Dynamic linking: pros and cons

7.2 Dynamic linking options

7.2.1 Side modules and main modules

7.2.2 Dynamic linking: dlopen

7.2.3 Dynamic linking: dynamicLibraries

7.2.4 Dynamic linking: WebAssembly JavaScript API

7.3 Dynamic linking review

7.4 Exercises

7.5 Summary

8 Dynamic linking: the implementation

9 Running code in a thread separate from the UI in a browser

10 Working with WebAssembly modules in NodeJS

Part 4: Debugging and Tools

11 The WebAssembly Text Format

12 Debugging

13 Tools

14 Future WebAssembly improvements that are in the works


Appendix A: Installation & tool setup

A.1 Python

A.1.1 Running a local web server

A.1.2 The WebAssembly Media Type

A.2 Emscripten

A.2.1 Downloading the Emscripten SDK

A.2.2 If you’re using Windows

A.2.3 If you’re using a Mac or Linux

A.2.4 Working around installation issues

A.3 NodeJS

A.4 WebAssembly Binary Toolkit

A.5 Bootstrap

Appendix B: ccall, cwrap, and direct method calls

B.1 ccall

B.1.1 Building a simple WebAssembly module

B.1.2 Building the webpage that will talk to the WebAssembly module

B.2 cwrap

B.2.1 Adjusting the JavaScript code to use cwrap

B.3 Direct method calls

B.4 Passing an array to a module

Appendix C: Emscripten Macros

C.1 emscripten_run_script macros


C.2.1 No parameter values

C.2.2 Passing parameter values

C.2.3 Passing pointers as parameters

C.2.4 Returning a string pointer


C.3.1 EM_ASM

C.3.2 EM_ASM_

C.3.3 Passing pointers as parameters


C.3.5 Returning a string pointer

Appendix D: Exercise solutions

D.1 Chapter 7

D.1.1 Exercise 1:

D.1.2 Exercise 2:

About the Technology

WebAssembly compiles code written in C, C++, Rust, and other high-level languages into an ultra-compact bytecode files that run in the browser and other environments at near-native speeds. Besides vastly improved performance, opportunities to reuse existing code, and the freedom to build in your favorite language, this game-changer allows access to newer and faster libraries. WebAssembly is the joint effort of industry leaders like Microsoft, Mozilla, Google, and others, with support built into all major browsers.

About the book

WebAssembly in Action introduces the WebAssembly stack and walks you through the process of writing and running browser-based applications. Expert developer Gerard Gallant gives you a firm foundation of the structure of a module, HTML basics, JavaScript Promises, and the WebAssembly JavaScript API. After building simple modules, you’ll delve deeper into dynamic linking of multiple modules at runtime, working with NodeJS modules, building modules with C/C++ and the Emscripten toolkit, and running a UI-independent thread with an HTML5 web worker.

To ensure your code is error-free, you’ll also learn about WebAssembly Text Format, which is vital for debugging. You’ll reinforce your learning with real-world examples and get a glimpse of features-to-come, including host bindings and garbage collection. WebAssembly makes it possible to create apps for online video gaming, image and video editing, virtual reality, peer-to-peer collaboration, music streaming, and many more without adjusting to the idiosyncrasies of JavaScript. This well-rounded tutorial is your ticket!

What's inside

  • The WebAssembly format
  • Dynamic linking of multiple modules at runtime
  • Communicating between modules and JavaScript
  • Debugging modules
  • Unreleased features like host bindings and garbage collection!

About the reader

Written for developers with a basic understanding of C/C++, JavaScript, and HTML.

About the author

Gerard Gallant is a Microsoft Certified Professional and a Senior Software Developer at Dovico Software. He blogs regularly on Blogger.com and DZone.com.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook + liveBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks

A great comprehensive introduction to a new frontend technology.

Denis Kreis

With the well-organized content, the author has made sure that everyone from beginner to very experienced developers will have something to learn.

Reza Zeinali