import 'vendor/tinygo' const go = new Go(); go.importObject.env['main.defineClass'] = function(namePtr, nameLen, cPtr, cGcPtr, pPtr/*, pGcPtr*/) { const mem = new DataView(go._inst.exports.memory.buffer) const decoder = new TextDecoder("utf-8"); const name = decoder.decode(new DataView(go._inst.exports.memory.buffer, namePtr, nameLen)); const constructorID = mem.getUint32(cPtr, true) const constructor = go._values[constructorID] const prototypeID = mem.getUint32(pPtr, true) const prototypes = go._values[prototypeID] 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); });