Skip to main content

Wasm

Efficiently execute computationally intensive tasks. Wasm module compilation, instantiation, memory management, and interaction with imports and exports.

Eg WebAssembly.instantiate, WebAssembly.Module, WebAssembly.Instance

Classes

c
WebAssembly.CompileError

The WebAssembly.CompileError object indicates an error during WebAssembly decoding or validation.

    c
    WebAssembly.Global

    A WebAssembly.Global object represents a global variable instance, accessible from both JavaScript and importable/exportable across one or more WebAssembly.Module instances. This allows dynamic linking of multiple modules.

    c
    WebAssembly.Instance

    A WebAssembly.Instance object is a stateful, executable instance of a WebAssembly.Module. Instance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.

    c
    WebAssembly.LinkError

    The WebAssembly.LinkError object indicates an error during module instantiation (besides traps from the start function).

      c
      WebAssembly.Memory

      The WebAssembly.Memory object is a resizable ArrayBuffer or SharedArrayBuffer that holds the raw bytes of memory accessed by a WebAssembly Instance.

      c
      WebAssembly.Module

      A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser — this can be efficiently shared with Workers, and instantiated multiple times.

      c
      WebAssembly.RuntimeError

      The WebAssembly.RuntimeError object is the error type that is thrown whenever WebAssembly specifies a trap.

        c
        WebAssembly.Table

        The WebAssembly.Table() object is a JavaScript wrapper object — an array-like structure representing a WebAssembly Table, which stores function references. A table created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.

        Functions

        f
        WebAssembly.compile

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

          f
          WebAssembly.compileStreaming

          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).

            f
            WebAssembly.instantiate

            The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code.

              f
              WebAssembly.instantiateStreaming

              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.

                f
                WebAssembly.validate

                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).

                  Interfaces

                  I
                  WebAssembly.GlobalDescriptor

                  The GlobalDescriptor describes the options you can pass to new WebAssembly.Global().

                  I
                  WebAssembly.MemoryDescriptor

                  The MemoryDescriptor describes the options you can pass to new WebAssembly.Memory().

                  I
                  WebAssembly.ModuleExportDescriptor

                  A ModuleExportDescriptor is the description of a declared export in a WebAssembly.Module.

                  I
                  WebAssembly.ModuleImportDescriptor

                  A ModuleImportDescriptor is the description of a declared import in a WebAssembly.Module.

                  I
                  WebAssembly.TableDescriptor

                  The TableDescriptor describes the options you can pass to new WebAssembly.Table().

                  I
                  WebAssembly.WebAssemblyInstantiatedSource

                  The value returned from WebAssembly.instantiate.

                  Namespaces

                  N
                  WebAssembly

                  The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality. Unlike most global objects, it is not a constructor; it groups the functions used to compile and instantiate WebAssembly modules together with the classes (Module, Instance, Memory, Table, Global) and error types used to work with them.

                    Type Aliases

                    T
                    WebAssembly.Exports

                    The set of values exported by a WebAssembly module instance, keyed by export name.

                      T
                      WebAssembly.ExportValue

                      A value that can be exported from a WebAssembly module instance.

                        T
                        WebAssembly.ImportExportKind

                        The kind of entity referenced by a module import or export descriptor.

                          T
                          WebAssembly.Imports

                          The import object supplied when instantiating a WebAssembly module, grouping imported values by module name.

                            T
                            WebAssembly.ImportValue

                            A value that can be supplied to a WebAssembly module as an import.

                              T
                              WebAssembly.ModuleImports

                              The set of values imported from a single module, keyed by import name.

                                T
                                WebAssembly.TableKind

                                The type of value stored in a WebAssembly.Table.

                                  T
                                  WebAssembly.ValueType

                                  The data type of a WebAssembly value, used to describe globals.


                                    class WebAssembly.CompileError

                                    extends Error

                                    The WebAssembly.CompileError object indicates an error during WebAssembly decoding or validation.

                                    MDN

                                    Constructors #

                                    #CompileError(
                                    message?: string,
                                    options?: ErrorOptions,
                                    )
                                    new

                                    Creates a new WebAssembly.CompileError object.


                                    class WebAssembly.Global

                                    A WebAssembly.Global object represents a global variable instance, accessible from both JavaScript and importable/exportable across one or more WebAssembly.Module instances. This allows dynamic linking of multiple modules.

                                    MDN

                                    Constructors #

                                    #Global(
                                    descriptor: GlobalDescriptor,
                                    v?: any,
                                    )
                                    new

                                    Creates a new Global object.

                                    Properties #

                                    #value: any

                                    The value contained inside the global variable — this can be used to directly set and get the global's value.

                                    Methods #

                                    #valueOf(): any

                                    Old-style method that returns the value contained inside the global variable.


                                    class WebAssembly.Instance

                                    A WebAssembly.Instance object is a stateful, executable instance of a WebAssembly.Module. Instance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.

                                    MDN

                                    Constructors #

                                    #Instance(
                                    module: Module,
                                    importObject?: Imports,
                                    )
                                    new

                                    Creates a new Instance object.

                                    Properties #

                                    #exports: Exports
                                    readonly

                                    Returns an object containing as its members all the functions exported from the WebAssembly module instance, to allow them to be accessed and used by JavaScript. Read-only.


                                    class WebAssembly.LinkError

                                    extends Error

                                    The WebAssembly.LinkError object indicates an error during module instantiation (besides traps from the start function).

                                    MDN

                                    Constructors #

                                    #LinkError(
                                    message?: string,
                                    options?: ErrorOptions,
                                    )
                                    new

                                    Creates a new WebAssembly.LinkError object.


                                    class WebAssembly.Memory

                                    The WebAssembly.Memory object is a resizable ArrayBuffer or SharedArrayBuffer that holds the raw bytes of memory accessed by a WebAssembly Instance.

                                    A memory created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.

                                    MDN

                                    Constructors #

                                    #Memory(descriptor: MemoryDescriptor)
                                    new

                                    Creates a new Memory object.

                                    Properties #

                                    #buffer: ArrayBuffer | SharedArrayBuffer
                                    readonly

                                    An accessor property that returns the buffer contained in the memory.

                                    Methods #

                                    #grow(delta: number): number

                                    Increases the size of the memory instance by a specified number of WebAssembly pages (each one is 64KB in size).


                                    class WebAssembly.Module

                                    A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser — this can be efficiently shared with Workers, and instantiated multiple times.

                                    MDN

                                    Constructors #

                                    #Module(bytes: BufferSource)
                                    new

                                    Creates a new Module object.

                                    Static Methods #

                                    #customSections(
                                    moduleObject: Module,
                                    sectionName: string,
                                    ): ArrayBuffer[]

                                    Given a Module and string, returns a copy of the contents of all custom sections in the module with the given string name.

                                    Given a Module, returns an array containing descriptions of all the declared exports.

                                    Given a Module, returns an array containing descriptions of all the declared imports.


                                    class WebAssembly.RuntimeError

                                    extends Error

                                    The WebAssembly.RuntimeError object is the error type that is thrown whenever WebAssembly specifies a trap.

                                    MDN

                                    Constructors #

                                    #RuntimeError(
                                    message?: string,
                                    options?: ErrorOptions,
                                    )
                                    new

                                    Creates a new WebAssembly.RuntimeError object.


                                    class WebAssembly.Table

                                    The WebAssembly.Table() object is a JavaScript wrapper object — an array-like structure representing a WebAssembly Table, which stores function references. A table created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.

                                    MDN

                                    Constructors #

                                    #Table(descriptor: TableDescriptor)
                                    new

                                    Creates a new Table object.

                                    Properties #

                                    #length: number
                                    readonly

                                    Returns the length of the table, i.e. the number of elements.

                                    Methods #

                                    #get(index: number): Function | null

                                    Accessor function — gets the element stored at a given index.

                                    #grow(delta: number): number

                                    Increases the size of the Table instance by a specified number of elements.

                                    #set(
                                    index: number,
                                    value: Function | null,
                                    ): void

                                    Sets an element stored at a given index to a given value.


                                    function WebAssembly.compile

                                    #compile(bytes: BufferSource): Promise<Module>

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

                                    MDN

                                    Parameters #

                                    Return Type #

                                    Promise<Module>

                                    function WebAssembly.compileStreaming

                                    #compileStreaming(source: Response | Promise<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).

                                    MDN

                                    Parameters #

                                    #source: Response | Promise<Response>

                                    Return Type #

                                    Promise<Module>

                                    function WebAssembly.instantiate

                                    Overload 1

                                    #instantiate(
                                    bytes: BufferSource,
                                    importObject?: Imports,
                                    ): Promise<WebAssemblyInstantiatedSource>

                                    The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code.

                                    This 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.

                                    MDN

                                    Parameters #

                                    #importObject: Imports
                                    optional

                                    Return Type #

                                    Overload 2

                                    #instantiate(
                                    moduleObject: Module,
                                    importObject?: Imports,
                                    ): Promise<Instance>

                                    The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code.

                                    This 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.

                                    MDN

                                    Parameters #

                                    #moduleObject: Module
                                    #importObject: Imports
                                    optional

                                    Return Type #

                                    Promise<Instance>

                                    function WebAssembly.instantiateStreaming

                                    #instantiateStreaming(
                                    response: Response | PromiseLike<Response>,
                                    importObject?: Imports,
                                    ): 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.

                                    MDN

                                    Parameters #

                                    #response: Response | PromiseLike<Response>
                                    #importObject: Imports
                                    optional

                                    Return Type #


                                    function WebAssembly.validate

                                    #validate(bytes: BufferSource): boolean

                                    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).

                                    MDN

                                    Parameters #

                                    Return Type #

                                    boolean

                                    interface WebAssembly.GlobalDescriptor

                                    The GlobalDescriptor describes the options you can pass to new WebAssembly.Global().

                                    Properties #

                                    #mutable: boolean
                                    optional

                                    Whether the global variable can be modified after creation. Defaults to false.

                                    The data type of the global variable.


                                    interface WebAssembly.MemoryDescriptor

                                    The MemoryDescriptor describes the options you can pass to new WebAssembly.Memory().

                                    Properties #

                                    #initial: number

                                    The initial size of the memory, in units of WebAssembly pages (64KB each).

                                    #maximum: number
                                    optional

                                    The maximum size the memory is allowed to grow to, in units of WebAssembly pages.

                                    #shared: boolean
                                    optional

                                    Whether the memory is shared between agents (backed by a SharedArrayBuffer). Defaults to false.




                                    interface WebAssembly.TableDescriptor

                                    The TableDescriptor describes the options you can pass to new WebAssembly.Table().

                                    Properties #

                                    The type of value stored in the table.

                                    #initial: number

                                    The initial number of elements in the table.

                                    #maximum: number
                                    optional

                                    The maximum number of elements the table is allowed to grow to.


                                    interface WebAssembly.WebAssemblyInstantiatedSource

                                    The value returned from WebAssembly.instantiate.

                                    Properties #

                                    A WebAssembly.Instance object that contains all the exported WebAssembly functions.

                                    A WebAssembly.Module object representing the compiled WebAssembly module. This Module can be instantiated again, or shared via postMessage().


                                    namespace WebAssembly

                                    The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality. Unlike most global objects, it is not a constructor; it groups the functions used to compile and instantiate WebAssembly modules together with the classes (Module, Instance, Memory, Table, Global) and error types used to work with them.

                                    MDN

                                    Classes #

                                    c
                                    WebAssembly.CompileError

                                    The WebAssembly.CompileError object indicates an error during WebAssembly decoding or validation.

                                      c
                                      WebAssembly.Global

                                      A WebAssembly.Global object represents a global variable instance, accessible from both JavaScript and importable/exportable across one or more WebAssembly.Module instances. This allows dynamic linking of multiple modules.

                                      c
                                      WebAssembly.Instance

                                      A WebAssembly.Instance object is a stateful, executable instance of a WebAssembly.Module. Instance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.

                                      c
                                      WebAssembly.LinkError

                                      The WebAssembly.LinkError object indicates an error during module instantiation (besides traps from the start function).

                                        c
                                        WebAssembly.Memory

                                        The WebAssembly.Memory object is a resizable ArrayBuffer or SharedArrayBuffer that holds the raw bytes of memory accessed by a WebAssembly Instance.

                                        c
                                        WebAssembly.Module

                                        A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser — this can be efficiently shared with Workers, and instantiated multiple times.

                                        c
                                        WebAssembly.RuntimeError

                                        The WebAssembly.RuntimeError object is the error type that is thrown whenever WebAssembly specifies a trap.

                                          c
                                          WebAssembly.Table

                                          The WebAssembly.Table() object is a JavaScript wrapper object — an array-like structure representing a WebAssembly Table, which stores function references. A table created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.

                                          Functions #

                                          f
                                          WebAssembly.compile

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

                                            f
                                            WebAssembly.compileStreaming

                                            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).

                                              f
                                              WebAssembly.instantiate

                                              The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code.

                                                f
                                                WebAssembly.instantiateStreaming

                                                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.

                                                  f
                                                  WebAssembly.validate

                                                  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).

                                                    Interfaces #

                                                    I
                                                    WebAssembly.GlobalDescriptor

                                                    The GlobalDescriptor describes the options you can pass to new WebAssembly.Global().

                                                    I
                                                    WebAssembly.MemoryDescriptor

                                                    The MemoryDescriptor describes the options you can pass to new WebAssembly.Memory().

                                                    I
                                                    WebAssembly.ModuleExportDescriptor

                                                    A ModuleExportDescriptor is the description of a declared export in a WebAssembly.Module.

                                                    I
                                                    WebAssembly.ModuleImportDescriptor

                                                    A ModuleImportDescriptor is the description of a declared import in a WebAssembly.Module.

                                                    I
                                                    WebAssembly.TableDescriptor

                                                    The TableDescriptor describes the options you can pass to new WebAssembly.Table().

                                                    I
                                                    WebAssembly.WebAssemblyInstantiatedSource

                                                    The value returned from WebAssembly.instantiate.

                                                    Type Aliases #

                                                    T
                                                    WebAssembly.Exports

                                                    The set of values exported by a WebAssembly module instance, keyed by export name.

                                                      T
                                                      WebAssembly.ExportValue

                                                      A value that can be exported from a WebAssembly module instance.

                                                        T
                                                        WebAssembly.ImportExportKind

                                                        The kind of entity referenced by a module import or export descriptor.

                                                          T
                                                          WebAssembly.Imports

                                                          The import object supplied when instantiating a WebAssembly module, grouping imported values by module name.

                                                            T
                                                            WebAssembly.ImportValue

                                                            A value that can be supplied to a WebAssembly module as an import.

                                                              T
                                                              WebAssembly.ModuleImports

                                                              The set of values imported from a single module, keyed by import name.

                                                                T
                                                                WebAssembly.TableKind

                                                                The type of value stored in a WebAssembly.Table.

                                                                  T
                                                                  WebAssembly.ValueType

                                                                  The data type of a WebAssembly value, used to describe globals.




                                                                    type alias WebAssembly.ImportExportKind

                                                                    The kind of entity referenced by a module import or export descriptor.

                                                                    Definition #

                                                                    "function"
                                                                    | "global"
                                                                    | "memory"
                                                                    | "table"

                                                                    type alias WebAssembly.Imports

                                                                    The import object supplied when instantiating a WebAssembly module, grouping imported values by module name.

                                                                    Definition #

                                                                    Record<string, ModuleImports>




                                                                    type alias WebAssembly.ValueType

                                                                    The data type of a WebAssembly value, used to describe globals.

                                                                    Definition #

                                                                    "f32"
                                                                    | "f64"
                                                                    | "i32"
                                                                    | "i64"

                                                                    Did you find what you needed?

                                                                    Privacy policy