wasm: add support for js.FuncOf

This commit is contained in:
Ayke van Laethem
2019-05-24 15:30:09 +02:00
committed by Ayke
parent 3313decb68
commit eb1d834dd4
9 changed files with 129 additions and 27 deletions
+26
View File
@@ -0,0 +1,26 @@
'use strict';
const WASM_URL = 'wasm.wasm';
var wasm;
function init() {
const go = new Go();
if ('instantiateStreaming' in WebAssembly) {
WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(function (obj) {
wasm = obj.instance;
go.run(wasm);
})
} else {
fetch(WASM_URL).then(resp =>
resp.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, go.importObject).then(function (obj) {
wasm = obj.instance;
go.run(wasm);
})
)
}
}
init();