github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/wasm/slices/wasm.js (about) 1 'use strict'; 2 3 const WASM_URL = 'wasm.wasm'; 4 5 var wasm; 6 7 function update() { 8 const value = document.getElementById("a").value; 9 document.getElementById("b").innerHTML = JSON.stringify(window.splitter(value)); 10 } 11 12 function init() { 13 document.querySelector('#a').oninput = update; 14 15 const go = new Go(); 16 if ('instantiateStreaming' in WebAssembly) { 17 WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(function (obj) { 18 wasm = obj.instance; 19 go.run(wasm); 20 }) 21 } else { 22 fetch(WASM_URL).then(resp => 23 resp.arrayBuffer() 24 ).then(bytes => 25 WebAssembly.instantiate(bytes, go.importObject).then(function (obj) { 26 wasm = obj.instance; 27 go.run(wasm); 28 }) 29 ) 30 } 31 } 32 33 init();