The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality.

Documentation WebAssembly by Mozilla Contributors, licensed under CC-BY-SA 2.5.

Static methods

staticcompile(bufferSource:BufferSource):Promise<Module>

The WebAssembly.compile() function compiles a WebAssembly Module from WebAssembly binary code. This function is useful if it is necessary to a compile a module before it can be instantiated (otherwise, the WebAssembly.instantiate() function should be used).

staticcompileStreaming(source:Response):Promise<Module>

The WebAssembly.compileStreaming() function compiles a WebAssembly Module directly from a streamed underlying source. This function is useful if it is necessary to a compile a module before it can be instantiated (otherwise, the WebAssembly.instantiateStreaming() function should be used).

staticinstantiate(bufferSource:BufferSource, importObject:{}):Promise<WebAssemblyInstantiatedSource>

staticinstantiate(module:Module, importObject:{}):Promise<Instance>

The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code. This function has two overloads:

  • The primary overload takes the WebAssembly binary code, in the form of a typed array or ArrayBuffer, and performs both compilation and instantiation in one step. The returned Promise resolves to both a compiled WebAssembly.Module and its first WebAssembly.Instance.

  • The secondary overload takes an already-compiled WebAssembly.Module and returns a Promise that resolves to an Instance of that Module. This overload is useful if the Module has already been compiled.

staticinstantiateStreaming(source:Response, importObject:{}):Promise<WebAssemblyInstantiatedSource>

The WebAssembly.instantiateStreaming() function compiles and instantiates a WebAssembly module directly from a streamed underlying source. This is the most efficient, optimized way to load wasm code.

staticvalidate(bufferSource:BufferSource):Bool

The WebAssembly.validate() function validates a given typed array of WebAssembly binary code, returning whether the bytes form a valid wasm module (true) or not (false).