github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/wasm/callback/wasm.js (about)

     1  'use strict';
     2  
     3  const WASM_URL = 'wasm.wasm';
     4  
     5  var wasm;
     6  
     7  function init() {
     8    const go = new Go();
     9    if ('instantiateStreaming' in WebAssembly) {
    10      WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(function (obj) {
    11        wasm = obj.instance;
    12        go.run(wasm);
    13      })
    14    } else {
    15      fetch(WASM_URL).then(resp =>
    16        resp.arrayBuffer()
    17      ).then(bytes =>
    18        WebAssembly.instantiate(bytes, go.importObject).then(function (obj) {
    19          wasm = obj.instance;
    20          go.run(wasm);
    21        })
    22      )
    23    }
    24  }
    25  
    26  init();