WebAssembly.Module.exports()
function returns an array containing descriptions of all the declared exports of the given
Module
.
WebAssembly.Module.exports(module);
WebAssembly.Module
对象。
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 (see our
index-compile.html
demo on GitHub, and
view it live
also) compiles the loaded simple.wasm byte code using the
WebAssembly.compileStreaming()
method and then sends it to a
worker
使用
postMessage()
.
var worker = new Worker("wasm_worker.js");
WebAssembly.compileStreaming(fetch('simple.wasm'))
.then(mod =>
worker.postMessage(mod)
);
In the worker (see
wasm_worker.js
) we define an import object for the module to use, then set 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, invoke an exported function from inside it, then show how we can return information on the available exports on a module using
WebAssembly.Module.exports
.
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();
});
var exports = WebAssembly.Module.exports(mod);
console.log(exports[0]);
};
exports[0]
output looks like this:
{ name: "exported_func", kind: "function" }
| 规范 |
|---|
|
WebAssembly JavaScript 接口
The definition of 'exports()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
exports
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
完整支持
不支持
见实现注意事项。
WebAssembly
WebAssembly.Module
WebAssembly.Global
WebAssembly.Instance
WebAssembly.Memory
WebAssembly.Table
WebAssembly.CompileError
WebAssembly.LinkError
WebAssembly.RuntimeError
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()