{ } qjs-modules

webassembly

The WebAssembly global (W3C JS API) over the native wasm module. Opt-in: importing the module installs the global when none exists.

import 'webassembly';

const { instance } = await WebAssembly.instantiate(bytes, { env: { f: x => x * 2 } });
instance.exports.g(21); // 42

Exports

namemeaning
WebAssembly (default and named)the namespace object, also globalThis.WebAssembly

Namespace

memberenumerablenotes
compile(bytes)yesresolves a Module
instantiate(bytes, imports?)yesresolves { module, instance }
instantiate(module, imports?)yesresolves an Instance
validate(bytes)yessynchronous; throws TypeError for a non-BufferSource
compileStreaming(source)yessource is a Response or a promise of one
instantiateStreaming(source, imports?)yesas instantiate(bytes, ...)
Module, Instance, Memory, Table, Globalnofrom wasm
CompileError, LinkError, RuntimeErrornofrom wasm
Symbol.toStringTagno"WebAssembly"

The async members never throw synchronously; they reject:

causerejection
bad argumentTypeError
invalid bytesWebAssembly.CompileError
unresolved or mistyped importWebAssembly.LinkError

The streaming members take any object with arrayBuffer() and headers.get(); they reject with TypeError unless the content type is application/wasm and the status is ok.

Not supported

Tag, Exception, JSTag, shared memories and externref; see wasm.