September 2018
Intermediate to advanced
328 pages
9h 10m
English
We will fetch and instantiate a .wasm file in several of the examples, so it makes sense to move the JavaScript loading code to a common file. The actual fetch and instantiation code is only a few lines, but having to repeatedly redefine the importObj object that Emscripten expects is a waste of time. We'll make this code available in a commonly accessible file to expedite the code-writing process. Create a new folder named /common in the /book-examples folder and add a file named load-wasm.js with the following contents:
/** * Returns a valid importObj.env object with default values to pass * into the WebAssembly.Instance constructor for Emscripten's * Wasm module. */const getDefaultEnv = () => ({ memoryBase: ...Read now
Unlock full access