mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
36 lines
756 B
JavaScript
36 lines
756 B
JavaScript
'use strict';
|
|
|
|
const WASM_URL = '../../../wasm.wasm';
|
|
|
|
var wasm;
|
|
|
|
function updateResult() {
|
|
wasm.exports.update();
|
|
}
|
|
|
|
function init() {
|
|
document.querySelector('#a').oninput = updateResult;
|
|
document.querySelector('#b').oninput = updateResult;
|
|
|
|
const go = new Go();
|
|
if ('instantiateStreaming' in WebAssembly) {
|
|
WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(function(obj) {
|
|
wasm = obj.instance;
|
|
go.run(wasm);
|
|
updateResult();
|
|
})
|
|
} else {
|
|
fetch(WASM_URL).then(resp =>
|
|
resp.arrayBuffer()
|
|
).then(bytes =>
|
|
WebAssembly.instantiate(bytes, go.importObject).then(function(obj) {
|
|
wasm = obj.instance;
|
|
go.run(wasm);
|
|
updateResult();
|
|
})
|
|
)
|
|
}
|
|
}
|
|
|
|
init();
|