This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The exports() method of the WebAssembly.Module() constructor returns an array containing references to the exported functions available in a given WebAssembly module.
var custSec = WebAssembly.Module.exports(module);
WebAssembly.Module object instance.An array containing objects representing the exported functions of the given module.
If module is not a WebAssembly.Module object instance, a TypeError is thrown.
The following example compiles and instantiates the loaded simple.wasm byte code, importing a JavaScript function into the WebAssembly Module in the process. It then exports a function from the module via Instance.exports.
In addition, we create two variables, storing in them the exports and imports properties of the module instance mod.
var importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
}
}
};
fetch('simple.wasm').then(function(response) {
response.arrayBuffer().then(function(bytes) {
WebAssembly.compile(bytes).then(function(mod) {
var instance = new WebAssembly.Instance(mod, importObject);
instance.exports.exported_func();
var exports = WebAssembly.Module.exports(mod);
var imp = WebAssembly.Module.imports(mod);
console.log(exports[0]);
console.log(imp[0]);
})
})
}); In this case, console.log(exports[0]) returns an object containing information about the exported function exported_func(). It looks like this:
{ name: "exported_func", kind: "function" } | Specification | Status | Comment |
|---|---|---|
| Web Assembly JavaScript API The definition of 'exports()' in that specification. | Draft | Initial draft definition. |
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | No support[1] | No support | No support[2] | No support | No support[1] | No support |
| Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|---|
| Basic support | No support | No support[1] | No support | No support[2] | No support | No support | No support | No support[1] |
[1] Experimental support can be enabled in Chrome 51+ and Opera 38+ by going to chrome://flags and enabling the Experimental WebAssembly flag.
[2] Experimental support can be enabled in Firefox 47+ by enabling the javascript.options.wasm flag in about:config.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports