WebAssembly.Module.exports()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2017å¹´10æ.
WebAssembly.Module.exports() 颿°ã¯ãæå®ããã Module ã®ã¨ã¯ã¹ãã¼ã宣è¨ã®å®ç¾©ã®é
åãè¿ãã¾ãã
æ§æ
WebAssembly.Module.exports(module);
弿°
- module
-
WebAssembly.Moduleãªãã¸ã§ã¯ãã§ãã
è¿å¤
æå®ããã¢ã¸ã¥ã¼ã«ã®ã¨ã¯ã¹ãã¼ãããã颿°ã表ç¾ãããªãã¸ã§ã¯ãã®é åã§ãã
ä¾å¤
ã¢ã¸ã¥ã¼ã«ã WebAssembly.Module ãªãã¸ã§ã¯ãã®ã¤ã³ã¹ã¿ã³ã¹ã§ã¯ãªãå ´åãTypeError ãçºçãã¾ãã
ä¾
>exports ã®ä½¿ç¨
次ã®ä¾ (Github ã®ã㢠index-compile.html ã¨ãåä½ä¾ãåç
§) ã§ã¯ãWebAssembly.compileStreaming() 颿°ã使ç¨ãã¦èªã¿è¾¼ãã simple.wasm ã®ãã¤ãã³ã¼ããã³ã³ãã¤ã«ãã¦ãã¯ã¼ã«ã¼ã« postMessage() ã使ç¨ãã¦éä¿¡ãã¦ãã¾ãã
var worker = new Worker("wasm_worker.js");
WebAssembly.compileStreaming(fetch("simple.wasm")).then((mod) =>
worker.postMessage(mod),
);
ã¯ã¼ã«ã¼ (wasm_worker.js ãåç
§) å
ã§ãã¢ã¸ã¥ã¼ã«ã§ä½¿ç¨ããããã«ã¤ã³ãã¼ããªãã¸ã§ã¯ããå®ç¾©ãã¦ããã®ãã¨ã«ã¡ã¤ã³ã¹ã¬ããããã¢ã¸ã¥ã¼ã«ãåãåãããã®ã¤ãã³ããã³ãã©ã¼ãã»ããã¢ãããã¾ããã¢ã¸ã¥ã¼ã«ãåãåã£ãã¨ããWebAssembly.Instantiate() ã¡ã½ããã使ç¨ãã¦ã¤ã³ã¹ã¿ã³ã¹ãçæãããã®å
é¨ã§ã¨ã¯ã¹ãã¼ãããã颿°ãå®è¡ãã¾ãããã®ãã¨ã« 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] ã®åºåã¯ãã®ããã«ãªãã¾ãã
{ name: "exported_func", kind: "function" }
仿§æ¸
| Specification |
|---|
| WebAssembly JavaScript Interface> # dom-module-exports> |
ãã©ã¦ã¶ã¼ã®äºææ§
é¢é£æ å ±
- WebAssembly æ¦è¦ãã¼ã¸
- WebAssembly ã®æ¦å¿µ
- WebAssembly JavaScript API ã®ä½¿ç¨