Skip to content
WASM Analyzer LogoWASM Analyzer LogoWASM Analyzer
GitHub

Globals

Globals are global variables. These variables can be accessed from both host code and within WebAssembly instances. Globals can be defined as mutable or immutable. This is done through the mutable property, with the possible values true or false. Globals can be both imported into a module, and exported from one.





Types


Global values are WebAssembly.ValueTypes, which can be of the following types:

abbreviationexplanation
anyfuncReference to a function
externrefReference to entity in host environment
f3232 bit float
f6464 bit float
i3232 bit integer
i6464 bit integer
v128128 bit vector





Examples:


Creating a global will look something like this :

const aGlobal = new WebAssembly.Global({ value: "i32", mutable: true }, aValue);


Accessing an exported global will look something like this:

WebAssembly.instantiateStreaming(
  fetch("moduleOrComponent.wasm"),
  importsObject
).then(({ obj }) => {
  const aGlobalRef = obj.exports.getGlobal(); // getting a reference to an exported modal
});





Additional reading


Read more about about globals and how to work with them in Mozilla’s WebAssembly documentation, here.