// Generated by scripts/generate-wasm-exec.mjs from wasm/wasm_exec.js. // Do not edit: regenerate after vendoring a new Go-built signer runtime. const WASM_EXEC_LINES: readonly string[] = [ "// Copyright 2018 The Go Authors. All rights reserved.", "// Use of this source code is governed by a BSD-style", "// license that can be found in the LICENSE file.", "", "\"use strict\";", "", "(() => {", "\tconst enosys = () => {", "\t\tconst err = new Error(\"not implemented\");", "\t\terr.code = \"ENOSYS\";", "\t\treturn err;", "\t};", "", "\tif (!globalThis.fs) {", "\t\tlet outputBuf = \"\";", "\t\tglobalThis.fs = {", "\t\t\tconstants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused", "\t\t\twriteSync(fd, buf) {", "\t\t\t\toutputBuf += decoder.decode(buf);", "\t\t\t\tconst nl = outputBuf.lastIndexOf(\"\\n\");", "\t\t\t\tif (nl != -1) {", "\t\t\t\t\tconsole.log(outputBuf.substring(0, nl));", "\t\t\t\t\toutputBuf = outputBuf.substring(nl + 1);", "\t\t\t\t}", "\t\t\t\treturn buf.length;", "\t\t\t},", "\t\t\twrite(fd, buf, offset, length, position, callback) {", "\t\t\t\tif (offset !== 0 || length !== buf.length || position !== null) {", "\t\t\t\t\tcallback(enosys());", "\t\t\t\t\treturn;", "\t\t\t\t}", "\t\t\t\tconst n = this.writeSync(fd, buf);", "\t\t\t\tcallback(null, n);", "\t\t\t},", "\t\t\tchmod(path, mode, callback) { callback(enosys()); },", "\t\t\tchown(path, uid, gid, callback) { callback(enosys()); },", "\t\t\tclose(fd, callback) { callback(enosys()); },", "\t\t\tfchmod(fd, mode, callback) { callback(enosys()); },", "\t\t\tfchown(fd, uid, gid, callback) { callback(enosys()); },", "\t\t\tfstat(fd, callback) { callback(enosys()); },", "\t\t\tfsync(fd, callback) { callback(null); },", "\t\t\tftruncate(fd, length, callback) { callback(enosys()); },", "\t\t\tlchown(path, uid, gid, callback) { callback(enosys()); },", "\t\t\tlink(path, link, callback) { callback(enosys()); },", "\t\t\tlstat(path, callback) { callback(enosys()); },", "\t\t\tmkdir(path, perm, callback) { callback(enosys()); },", "\t\t\topen(path, flags, mode, callback) { callback(enosys()); },", "\t\t\tread(fd, buffer, offset, length, position, callback) { callback(enosys()); },", "\t\t\treaddir(path, callback) { callback(enosys()); },", "\t\t\treadlink(path, callback) { callback(enosys()); },", "\t\t\trename(from, to, callback) { callback(enosys()); },", "\t\t\trmdir(path, callback) { callback(enosys()); },", "\t\t\tstat(path, callback) { callback(enosys()); },", "\t\t\tsymlink(path, link, callback) { callback(enosys()); },", "\t\t\ttruncate(path, length, callback) { callback(enosys()); },", "\t\t\tunlink(path, callback) { callback(enosys()); },", "\t\t\tutimes(path, atime, mtime, callback) { callback(enosys()); },", "\t\t};", "\t}", "", "\tif (!globalThis.process) {", "\t\tglobalThis.process = {", "\t\t\tgetuid() { return -1; },", "\t\t\tgetgid() { return -1; },", "\t\t\tgeteuid() { return -1; },", "\t\t\tgetegid() { return -1; },", "\t\t\tgetgroups() { throw enosys(); },", "\t\t\tpid: -1,", "\t\t\tppid: -1,", "\t\t\tumask() { throw enosys(); },", "\t\t\tcwd() { throw enosys(); },", "\t\t\tchdir() { throw enosys(); },", "\t\t}", "\t}", "", "\tif (!globalThis.crypto) {", "\t\tthrow new Error(\"globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)\");", "\t}", "", "\tif (!globalThis.performance) {", "\t\tthrow new Error(\"globalThis.performance is not available, polyfill required (performance.now only)\");", "\t}", "", "\tif (!globalThis.TextEncoder) {", "\t\tthrow new Error(\"globalThis.TextEncoder is not available, polyfill required\");", "\t}", "", "\tif (!globalThis.TextDecoder) {", "\t\tthrow new Error(\"globalThis.TextDecoder is not available, polyfill required\");", "\t}", "", "\tconst encoder = new TextEncoder(\"utf-8\");", "\tconst decoder = new TextDecoder(\"utf-8\");", "", "\tglobalThis.Go = class {", "\t\tconstructor() {", "\t\t\tthis.argv = [\"js\"];", "\t\t\tthis.env = {};", "\t\t\tthis.exit = (code) => {", "\t\t\t\tif (code !== 0) {", "\t\t\t\t\tconsole.warn(\"exit code:\", code);", "\t\t\t\t}", "\t\t\t};", "\t\t\tthis._exitPromise = new Promise((resolve) => {", "\t\t\t\tthis._resolveExitPromise = resolve;", "\t\t\t});", "\t\t\tthis._pendingEvent = null;", "\t\t\tthis._scheduledTimeouts = new Map();", "\t\t\tthis._nextCallbackTimeoutID = 1;", "", "\t\t\tconst setInt64 = (addr, v) => {", "\t\t\t\tthis.mem.setUint32(addr + 0, v, true);", "\t\t\t\tthis.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);", "\t\t\t}", "", "\t\t\tconst setInt32 = (addr, v) => {", "\t\t\t\tthis.mem.setUint32(addr + 0, v, true);", "\t\t\t}", "", "\t\t\tconst getInt64 = (addr) => {", "\t\t\t\tconst low = this.mem.getUint32(addr + 0, true);", "\t\t\t\tconst high = this.mem.getInt32(addr + 4, true);", "\t\t\t\treturn low + high * 4294967296;", "\t\t\t}", "", "\t\t\tconst loadValue = (addr) => {", "\t\t\t\tconst f = this.mem.getFloat64(addr, true);", "\t\t\t\tif (f === 0) {", "\t\t\t\t\treturn undefined;", "\t\t\t\t}", "\t\t\t\tif (!isNaN(f)) {", "\t\t\t\t\treturn f;", "\t\t\t\t}", "", "\t\t\t\tconst id = this.mem.getUint32(addr, true);", "\t\t\t\treturn this._values[id];", "\t\t\t}", "", "\t\t\tconst storeValue = (addr, v) => {", "\t\t\t\tconst nanHead = 0x7FF80000;", "", "\t\t\t\tif (typeof v === \"number\" && v !== 0) {", "\t\t\t\t\tif (isNaN(v)) {", "\t\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead, true);", "\t\t\t\t\t\tthis.mem.setUint32(addr, 0, true);", "\t\t\t\t\t\treturn;", "\t\t\t\t\t}", "\t\t\t\t\tthis.mem.setFloat64(addr, v, true);", "\t\t\t\t\treturn;", "\t\t\t\t}", "", "\t\t\t\tif (v === undefined) {", "\t\t\t\t\tthis.mem.setFloat64(addr, 0, true);", "\t\t\t\t\treturn;", "\t\t\t\t}", "", "\t\t\t\tlet id = this._ids.get(v);", "\t\t\t\tif (id === undefined) {", "\t\t\t\t\tid = this._idPool.pop();", "\t\t\t\t\tif (id === undefined) {", "\t\t\t\t\t\tid = this._values.length;", "\t\t\t\t\t}", "\t\t\t\t\tthis._values[id] = v;", "\t\t\t\t\tthis._goRefCounts[id] = 0;", "\t\t\t\t\tthis._ids.set(v, id);", "\t\t\t\t}", "\t\t\t\tthis._goRefCounts[id]++;", "\t\t\t\tlet typeFlag = 0;", "\t\t\t\tswitch (typeof v) {", "\t\t\t\t\tcase \"object\":", "\t\t\t\t\t\tif (v !== null) {", "\t\t\t\t\t\t\ttypeFlag = 1;", "\t\t\t\t\t\t}", "\t\t\t\t\t\tbreak;", "\t\t\t\t\tcase \"string\":", "\t\t\t\t\t\ttypeFlag = 2;", "\t\t\t\t\t\tbreak;", "\t\t\t\t\tcase \"symbol\":", "\t\t\t\t\t\ttypeFlag = 3;", "\t\t\t\t\t\tbreak;", "\t\t\t\t\tcase \"function\":", "\t\t\t\t\t\ttypeFlag = 4;", "\t\t\t\t\t\tbreak;", "\t\t\t\t}", "\t\t\t\tthis.mem.setUint32(addr + 4, nanHead | typeFlag, true);", "\t\t\t\tthis.mem.setUint32(addr, id, true);", "\t\t\t}", "", "\t\t\tconst loadSlice = (addr) => {", "\t\t\t\tconst array = getInt64(addr + 0);", "\t\t\t\tconst len = getInt64(addr + 8);", "\t\t\t\treturn new Uint8Array(this._inst.exports.mem.buffer, array, len);", "\t\t\t}", "", "\t\t\tconst loadSliceOfValues = (addr) => {", "\t\t\t\tconst array = getInt64(addr + 0);", "\t\t\t\tconst len = getInt64(addr + 8);", "\t\t\t\tconst a = new Array(len);", "\t\t\t\tfor (let i = 0; i < len; i++) {", "\t\t\t\t\ta[i] = loadValue(array + i * 8);", "\t\t\t\t}", "\t\t\t\treturn a;", "\t\t\t}", "", "\t\t\tconst loadString = (addr) => {", "\t\t\t\tconst saddr = getInt64(addr + 0);", "\t\t\t\tconst len = getInt64(addr + 8);", "\t\t\t\treturn decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));", "\t\t\t}", "", "\t\t\tconst timeOrigin = Date.now() - performance.now();", "\t\t\tthis.importObject = {", "\t\t\t\t_gotest: {", "\t\t\t\t\tadd: (a, b) => a + b,", "\t\t\t\t},", "\t\t\t\tgojs: {", "\t\t\t\t\t// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)", "\t\t\t\t\t// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported", "\t\t\t\t\t// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).", "\t\t\t\t\t// This changes the SP, thus we have to update the SP used by the imported function.", "", "\t\t\t\t\t// func wasmExit(code int32)", "\t\t\t\t\t\"runtime.wasmExit\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst code = this.mem.getInt32(sp + 8, true);", "\t\t\t\t\t\tthis.exited = true;", "\t\t\t\t\t\tdelete this._inst;", "\t\t\t\t\t\tdelete this._values;", "\t\t\t\t\t\tdelete this._goRefCounts;", "\t\t\t\t\t\tdelete this._ids;", "\t\t\t\t\t\tdelete this._idPool;", "\t\t\t\t\t\tthis.exit(code);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)", "\t\t\t\t\t\"runtime.wasmWrite\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst fd = getInt64(sp + 8);", "\t\t\t\t\t\tconst p = getInt64(sp + 16);", "\t\t\t\t\t\tconst n = this.mem.getInt32(sp + 24, true);", "\t\t\t\t\t\tfs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func resetMemoryDataView()", "\t\t\t\t\t\"runtime.resetMemoryDataView\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func nanotime1() int64", "\t\t\t\t\t\"runtime.nanotime1\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tsetInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func walltime() (sec int64, nsec int32)", "\t\t\t\t\t\"runtime.walltime\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst msec = (new Date).getTime();", "\t\t\t\t\t\tsetInt64(sp + 8, msec / 1000);", "\t\t\t\t\t\tthis.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func scheduleTimeoutEvent(delay int64) int32", "\t\t\t\t\t\"runtime.scheduleTimeoutEvent\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst id = this._nextCallbackTimeoutID;", "\t\t\t\t\t\tthis._nextCallbackTimeoutID++;", "\t\t\t\t\t\tthis._scheduledTimeouts.set(id, setTimeout(", "\t\t\t\t\t\t\t() => {", "\t\t\t\t\t\t\t\tthis._resume();", "\t\t\t\t\t\t\t\twhile (this._scheduledTimeouts.has(id)) {", "\t\t\t\t\t\t\t\t\t// for some reason Go failed to register the timeout event, log and try again", "\t\t\t\t\t\t\t\t\t// (temporary workaround for https://github.com/golang/go/issues/28975)", "\t\t\t\t\t\t\t\t\tconsole.warn(\"scheduleTimeoutEvent: missed timeout event\");", "\t\t\t\t\t\t\t\t\tthis._resume();", "\t\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\t},", "\t\t\t\t\t\t\tgetInt64(sp + 8),", "\t\t\t\t\t\t));", "\t\t\t\t\t\tthis.mem.setInt32(sp + 16, id, true);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func clearTimeoutEvent(id int32)", "\t\t\t\t\t\"runtime.clearTimeoutEvent\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst id = this.mem.getInt32(sp + 8, true);", "\t\t\t\t\t\tclearTimeout(this._scheduledTimeouts.get(id));", "\t\t\t\t\t\tthis._scheduledTimeouts.delete(id);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func getRandomData(r []byte)", "\t\t\t\t\t\"runtime.getRandomData\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tcrypto.getRandomValues(loadSlice(sp + 8));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func finalizeRef(v ref)", "\t\t\t\t\t\"syscall/js.finalizeRef\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst id = this.mem.getUint32(sp + 8, true);", "\t\t\t\t\t\tthis._goRefCounts[id]--;", "\t\t\t\t\t\tif (this._goRefCounts[id] === 0) {", "\t\t\t\t\t\t\tconst v = this._values[id];", "\t\t\t\t\t\t\tthis._values[id] = null;", "\t\t\t\t\t\t\tthis._ids.delete(v);", "\t\t\t\t\t\t\tthis._idPool.push(id);", "\t\t\t\t\t\t}", "\t\t\t\t\t},", "", "\t\t\t\t\t// func stringVal(value string) ref", "\t\t\t\t\t\"syscall/js.stringVal\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tstoreValue(sp + 24, loadString(sp + 8));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueGet(v ref, p string) ref", "\t\t\t\t\t\"syscall/js.valueGet\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));", "\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\tstoreValue(sp + 32, result);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueSet(v ref, p string, x ref)", "\t\t\t\t\t\"syscall/js.valueSet\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tReflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueDelete(v ref, p string)", "\t\t\t\t\t\"syscall/js.valueDelete\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tReflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueIndex(v ref, i int) ref", "\t\t\t\t\t\"syscall/js.valueIndex\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tstoreValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));", "\t\t\t\t\t},", "", "\t\t\t\t\t// valueSetIndex(v ref, i int, x ref)", "\t\t\t\t\t\"syscall/js.valueSetIndex\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tReflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueCall(v ref, m string, args []ref) (ref, bool)", "\t\t\t\t\t\"syscall/js.valueCall\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\ttry {", "\t\t\t\t\t\t\tconst v = loadValue(sp + 8);", "\t\t\t\t\t\t\tconst m = Reflect.get(v, loadString(sp + 16));", "\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 32);", "\t\t\t\t\t\t\tconst result = Reflect.apply(m, v, args);", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 56, result);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 1);", "\t\t\t\t\t\t} catch (err) {", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 56, err);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 0);", "\t\t\t\t\t\t}", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueInvoke(v ref, args []ref) (ref, bool)", "\t\t\t\t\t\"syscall/js.valueInvoke\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\ttry {", "\t\t\t\t\t\t\tconst v = loadValue(sp + 8);", "\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);", "\t\t\t\t\t\t\tconst result = Reflect.apply(v, undefined, args);", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 40, result);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);", "\t\t\t\t\t\t} catch (err) {", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 40, err);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);", "\t\t\t\t\t\t}", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueNew(v ref, args []ref) (ref, bool)", "\t\t\t\t\t\"syscall/js.valueNew\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\ttry {", "\t\t\t\t\t\t\tconst v = loadValue(sp + 8);", "\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);", "\t\t\t\t\t\t\tconst result = Reflect.construct(v, args);", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 40, result);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);", "\t\t\t\t\t\t} catch (err) {", "\t\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above", "\t\t\t\t\t\t\tstoreValue(sp + 40, err);", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);", "\t\t\t\t\t\t}", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueLength(v ref) int", "\t\t\t\t\t\"syscall/js.valueLength\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tsetInt64(sp + 16, parseInt(loadValue(sp + 8).length));", "\t\t\t\t\t},", "", "\t\t\t\t\t// valuePrepareString(v ref) (ref, int)", "\t\t\t\t\t\"syscall/js.valuePrepareString\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst str = encoder.encode(String(loadValue(sp + 8)));", "\t\t\t\t\t\tstoreValue(sp + 16, str);", "\t\t\t\t\t\tsetInt64(sp + 24, str.length);", "\t\t\t\t\t},", "", "\t\t\t\t\t// valueLoadString(v ref, b []byte)", "\t\t\t\t\t\"syscall/js.valueLoadString\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst str = loadValue(sp + 8);", "\t\t\t\t\t\tloadSlice(sp + 16).set(str);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func valueInstanceOf(v ref, t ref) bool", "\t\t\t\t\t\"syscall/js.valueInstanceOf\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tthis.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func copyBytesToGo(dst []byte, src ref) (int, bool)", "\t\t\t\t\t\"syscall/js.copyBytesToGo\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst dst = loadSlice(sp + 8);", "\t\t\t\t\t\tconst src = loadValue(sp + 32);", "\t\t\t\t\t\tif (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);", "\t\t\t\t\t\t\treturn;", "\t\t\t\t\t\t}", "\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);", "\t\t\t\t\t\tdst.set(toCopy);", "\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);", "\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);", "\t\t\t\t\t},", "", "\t\t\t\t\t// func copyBytesToJS(dst ref, src []byte) (int, bool)", "\t\t\t\t\t\"syscall/js.copyBytesToJS\": (sp) => {", "\t\t\t\t\t\tsp >>>= 0;", "\t\t\t\t\t\tconst dst = loadValue(sp + 8);", "\t\t\t\t\t\tconst src = loadSlice(sp + 16);", "\t\t\t\t\t\tif (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {", "\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);", "\t\t\t\t\t\t\treturn;", "\t\t\t\t\t\t}", "\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);", "\t\t\t\t\t\tdst.set(toCopy);", "\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);", "\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);", "\t\t\t\t\t},", "", "\t\t\t\t\t\"debug\": (value) => {", "\t\t\t\t\t\tconsole.log(value);", "\t\t\t\t\t},", "\t\t\t\t}", "\t\t\t};", "\t\t}", "", "\t\tasync run(instance) {", "\t\t\tif (!(instance instanceof WebAssembly.Instance)) {", "\t\t\t\tthrow new Error(\"Go.run: WebAssembly.Instance expected\");", "\t\t\t}", "\t\t\tthis._inst = instance;", "\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);", "\t\t\tthis._values = [ // JS values that Go currently has references to, indexed by reference id", "\t\t\t\tNaN,", "\t\t\t\t0,", "\t\t\t\tnull,", "\t\t\t\ttrue,", "\t\t\t\tfalse,", "\t\t\t\tglobalThis,", "\t\t\t\tthis,", "\t\t\t];", "\t\t\tthis._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id", "\t\t\tthis._ids = new Map([ // mapping from JS values to reference ids", "\t\t\t\t[0, 1],", "\t\t\t\t[null, 2],", "\t\t\t\t[true, 3],", "\t\t\t\t[false, 4],", "\t\t\t\t[globalThis, 5],", "\t\t\t\t[this, 6],", "\t\t\t]);", "\t\t\tthis._idPool = []; // unused ids that have been garbage collected", "\t\t\tthis.exited = false; // whether the Go program has exited", "", "\t\t\t// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.", "\t\t\tlet offset = 4096;", "", "\t\t\tconst strPtr = (str) => {", "\t\t\t\tconst ptr = offset;", "\t\t\t\tconst bytes = encoder.encode(str + \"\\0\");", "\t\t\t\tnew Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);", "\t\t\t\toffset += bytes.length;", "\t\t\t\tif (offset % 8 !== 0) {", "\t\t\t\t\toffset += 8 - (offset % 8);", "\t\t\t\t}", "\t\t\t\treturn ptr;", "\t\t\t};", "", "\t\t\tconst argc = this.argv.length;", "", "\t\t\tconst argvPtrs = [];", "\t\t\tthis.argv.forEach((arg) => {", "\t\t\t\targvPtrs.push(strPtr(arg));", "\t\t\t});", "\t\t\targvPtrs.push(0);", "", "\t\t\tconst keys = Object.keys(this.env).sort();", "\t\t\tkeys.forEach((key) => {", "\t\t\t\targvPtrs.push(strPtr(`${key}=${this.env[key]}`));", "\t\t\t});", "\t\t\targvPtrs.push(0);", "", "\t\t\tconst argv = offset;", "\t\t\targvPtrs.forEach((ptr) => {", "\t\t\t\tthis.mem.setUint32(offset, ptr, true);", "\t\t\t\tthis.mem.setUint32(offset + 4, 0, true);", "\t\t\t\toffset += 8;", "\t\t\t});", "", "\t\t\t// The linker guarantees global data starts from at least wasmMinDataAddr.", "\t\t\t// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.", "\t\t\tconst wasmMinDataAddr = 4096 + 8192;", "\t\t\tif (offset >= wasmMinDataAddr) {", "\t\t\t\tthrow new Error(\"total length of command line and environment variables exceeds limit\");", "\t\t\t}", "", "\t\t\tthis._inst.exports.run(argc, argv);", "\t\t\tif (this.exited) {", "\t\t\t\tthis._resolveExitPromise();", "\t\t\t}", "\t\t\tawait this._exitPromise;", "\t\t}", "", "\t\t_resume() {", "\t\t\tif (this.exited) {", "\t\t\t\tthrow new Error(\"Go program has already exited\");", "\t\t\t}", "\t\t\tthis._inst.exports.resume();", "\t\t\tif (this.exited) {", "\t\t\t\tthis._resolveExitPromise();", "\t\t\t}", "\t\t}", "", "\t\t_makeFuncWrapper(id) {", "\t\t\tconst go = this;", "\t\t\treturn function () {", "\t\t\t\tconst event = { id: id, this: this, args: arguments };", "\t\t\t\tgo._pendingEvent = event;", "\t\t\t\tgo._resume();", "\t\t\t\treturn event.result;", "\t\t\t};", "\t\t}", "\t}", "})();", "", ] /** * Go's canonical `wasm_exec.js`, verbatim, as opaque runtime text. Evaluated by * the WASM loader to install `globalThis.Go`. * * @internal */ export const WASM_EXEC_JS: string = WASM_EXEC_LINES.join('\n')