import 'vendor/golang' const go = new Go(); const decoder = new TextDecoder("utf-8"); const getInt64 = (mem, addr) => { const low = mem.getUint32(addr + 0, true); const high = mem.getInt32(addr + 4, true); return low + high * 4294967296; } const loadString = (mem, addr) => { const saddr = getInt64(mem, addr + 0); const len = getInt64(mem, addr + 8); return decoder.decode(new DataView(mem.buffer, saddr, len)); } const loadValue = (mem, addr) => { const f = mem.getFloat64(addr, true); if (f === 0) { return undefined; } if (!isNaN(f)) { return f; } const id = mem.getUint32(addr, true); return go._values[id]; } go.importObject.go['main.defineClass'] = function(sp) { const mem = new DataView(go._inst.exports.mem.buffer) const name = loadString(mem, sp + 8); const constructor = loadValue(mem, sp + 24) const prototypes = loadValue(mem, sp + 40) window[name] = (new Function( 'constructor', 'prototypes', ` function ${name}() { if(!(this instanceof ${name})) { throw new TypeError("Cannot call a class as a function") } return constructor.apply(this, arguments) } prototypes.call(${name}.prototype) return ${name} ` ))(constructor, prototypes); } WebAssembly .instantiateStreaming( fetch(require('./main.wasm')), go.importObject, ) .then(result => { go.run(result.instance); });