[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/WebAssembly/Reference/JavaScript_interface/instantiate_static [Back]  [Original]

WebAssembly.instantiate() - WebAssembly | MDN

MDN Web Docs

View in English Always switch to English

WebAssembly.instantiate()

Baseline *

201710

*

WebAssembly.instantiate() WebAssembly 2

wasm

Promise<ResultObject> WebAssembly.instantiate(bufferSource, importObject);

bufferSource

.wasm ArrayBuffer

importObject

WebAssembly.Memory Instance WebAssembly.LinkError

2 ResultObject Promise

Promise<WebAssembly.Instance> WebAssembly.instantiate(module, importObject);

module

WebAssembly.Module

importObject

WebAssembly.Memory Instance 1 WebAssembly.LinkError

WebAssembly.Instance Promise

: WebAssembly.instantiateStreaming() instantiate()

fetch WebAssembly WebAssembly.instantiate() JavaScript WebAssembly Instance WebAssembly

js
var importObject = {
  imports: {
    imported_func: function (arg) {
      console.log(arg);
    },
  },
};

fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => WebAssembly.instantiate(bytes, importObject))
  .then((result) => result.instance.exports.exported_func());

: Github index.html ()

(GitHub index-compile.html ) simple.wasm WebAssembly.compileStreaming() postMessage()

js
var worker = new Worker("wasm_worker.js");

WebAssembly.compileStreaming(fetch("simple.wasm")).then((mod) =>
  worker.postMessage(mod),
);

(wasm_worker.js) WebAssembly.instantiate()

js
var importObject = {
  imports: {
    imported_func: function (arg) {
      console.log(arg);
    },
  },
};

onmessage = function (e) {
  console.log("module received from main thread");
  var mod = e.data;

  WebAssembly.instantiate(mod, importObject).then(function (instance) {
    instance.exports.exported_func();
  });
};

WebAssembly JavaScript Interface
# dom-webassembly-instantiate


Web Proxy Viewer  |  New URL  |  Original Page