Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

WebAssembly.Instance

BaselineWidely available

AWebAssembly.Instance object is a stateful, executable instance of aWebAssembly.Module.Instance objects contain all theExported WebAssembly functions that allow calling into WebAssembly code from JavaScript.

Constructor

WebAssembly.Instance()

Creates a newInstance object.

Instance properties

exports

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.

Examples

Synchronously instantiating a WebAssembly module

TheWebAssembly.Instance() constructor function can be called to synchronously instantiate a givenWebAssembly.Module object, for example:

js
const importObject = {  my_namespace: {    imported_func(arg) {      console.log(arg);    },  },};fetch("simple.wasm")  .then((response) => response.arrayBuffer())  .then((bytes) => {    const mod = new WebAssembly.Module(bytes);    const instance = new WebAssembly.Instance(mod, importObject);    instance.exports.exported_func();  });

The preferred way to get anInstance is asynchronously, for example using theWebAssembly.instantiateStreaming() function like this:

js
const importObject = {  my_namespace: {    imported_func(arg) {      console.log(arg);    },  },};WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(  (obj) => obj.instance.exports.exported_func(),);

This also demonstrates how theexports property is used to access exported functions.

Specifications

Specification
WebAssembly JavaScript Interface
# instances

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp