Skip to content
WASM Analyzer LogoWASM Analyzer LogoWASM Analyzer
GitHub

Tables

WebAssembly tables are mutable wrapper objects. A table is similar to an array, and contains function references. The contents of a table may be altered from both host code and Wasm.

Wasm tables can both be imports for, and exports from, a Wasm module or component (see the Imports section of our documentation for an example of passing imports, like a function, into a module).





Examples


Creating a Wasm table looks like this:

const aTableDescriptor = {
  element: "anyfunc", // anyfunc (any function) or externref (external function references)
  initial: 5, // initial number of items in the Table
  maximum: 100, // (optional) the maximum number of items the Table is allowed to contain
};

const aTable = new WebAssembly.Table(aTableDescriptor);

Accessing an exported table might look something like this:

WebAssembly.instantiateStreaming(fetch("module.wasm")).then((obj) => {
  const aTable = obj.instance.exports.tbl; // setting table reference to a variable
  const firstValue = aTable.get(0)(); // getting the first value from the table
});




Additional reading


More information about Wasm Tables can be found in Mozilla’s WebAssembly documentation.