WebAssembly.Module.imports()

The WebAssembly.imports() function returns an array containing descriptions of all the declared imports of the given Module.

Syntax

var custSec = WebAssembly.Module.imports(module);

Parameters

module
A WebAssembly.Module object.

Return value

An array containing objects representing the imported functions of the given module.

Exceptions

If module is not a WebAssembly.Module object instance, a TypeError is thrown.

Example

The following example (see imports.html source code; see it live also) compiles the loaded simple.wasm module.  This module is then queried for its imports.

fetch('simple.wasm').then(response =>
  response.arrayBuffer()
).then(bytes =>
  WebAssembly.compile(bytes)
).then(function(mod) {
  var imports = WebAssembly.Module.imports(mod);
  console.log(imports[0]);
});

The output looks like this:

{ module: "imports", name: "imported_func", kind: "function" }

Specifications

Specification Status Comment
WebAssembly JavaScript API
The definition of 'imports()' in that specification.
Draft Initial draft definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support5716522 No4411
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic support5757 Yes1522 No ?11

1. This feature is behind the Experimental JavaScript Features preference.

2. Disabled in the Firefox 52 Extended Support Release (ESR).

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, fscholz, syu_kato, lukewagner, svodnik
 Last updated by: chrisdavidmills,