A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/Module below:

WebAssembly.Module - WebAssembly | MDN

WebAssembly.Module

Baseline Widely available *

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.

Note: The WebAssembly.Module object is unrelated to the Module object used in Emscripten.

Constructor
WebAssembly.Module()

Creates a new Module object.

Static methods
WebAssembly.Module.customSections()

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

WebAssembly.Module.exports()

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

WebAssembly.Module.imports()

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

Examples Sending a compiled module to a worker

The following example compiles the loaded simple.wasm byte code using the WebAssembly.compileStreaming() method and sends the resulting Module instance to a worker using postMessage().

See the index-compile.html source code or view it live.

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

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

The worker function wasm_worker.js defines an import object for the module to use. The function then sets up an event handler to receive the module from the main thread. When the module is received, we create an instance from it using the WebAssembly.instantiate() method and invoke an exported function from inside it.

const importObject = {
  my_namespace: {
    imported_func(arg) {
      console.log(arg);
    },
  },
};

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

  WebAssembly.instantiate(mod, importObject).then((instance) => {
    instance.exports.exported_func();
  });
};
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4