isomorfeus-asset-manager 0.14.21 → 0.14.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -219,6 +219,7 @@ var mustBeInteger = (value) => typeof value === "number" && value === (value | 0
219
219
  var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
220
220
  var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
221
221
  var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
222
+ var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
222
223
  var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
223
224
  var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
224
225
  var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
@@ -245,10 +246,12 @@ function checkForInvalidFlags(object, keys, where) {
245
246
  function validateInitializeOptions(options) {
246
247
  let keys = /* @__PURE__ */ Object.create(null);
247
248
  let wasmURL = getFlag(options, keys, "wasmURL", mustBeString);
249
+ let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
248
250
  let worker = getFlag(options, keys, "worker", mustBeBoolean);
249
- checkForInvalidFlags(options, keys, "in startService() call");
251
+ checkForInvalidFlags(options, keys, "in initialize() call");
250
252
  return {
251
253
  wasmURL,
254
+ wasmModule,
252
255
  worker
253
256
  };
254
257
  }
@@ -287,6 +290,7 @@ function pushCommonFlags(flags, options, keys) {
287
290
  let globalName = getFlag(options, keys, "globalName", mustBeString);
288
291
  let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
289
292
  let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
293
+ let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
290
294
  let minify = getFlag(options, keys, "minify", mustBeBoolean);
291
295
  let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
292
296
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
@@ -338,6 +342,8 @@ function pushCommonFlags(flags, options, keys) {
338
342
  flags.push(`--mangle-props=${mangleProps.source}`);
339
343
  if (reserveProps)
340
344
  flags.push(`--reserve-props=${reserveProps.source}`);
345
+ if (mangleQuoted !== void 0)
346
+ flags.push(`--mangle-quoted=${mangleQuoted}`);
341
347
  if (jsx)
342
348
  flags.push(`--jsx=${jsx}`);
343
349
  if (jsxFactory)
@@ -587,7 +593,7 @@ function createChannel(streamIn) {
587
593
  let pluginCallbacks = /* @__PURE__ */ new Map();
588
594
  let watchCallbacks = /* @__PURE__ */ new Map();
589
595
  let serveCallbacks = /* @__PURE__ */ new Map();
590
- let isClosed = false;
596
+ let closeData = null;
591
597
  let nextRequestID = 0;
592
598
  let nextBuildKey = 0;
593
599
  let stdout = new Uint8Array(16 * 1024);
@@ -616,19 +622,20 @@ function createChannel(streamIn) {
616
622
  stdoutUsed -= offset;
617
623
  }
618
624
  };
619
- let afterClose = () => {
620
- isClosed = true;
625
+ let afterClose = (error) => {
626
+ closeData = { reason: error ? ": " + (error.message || error) : "" };
627
+ const text = "The service was stopped" + closeData.reason;
621
628
  for (let callback of responseCallbacks.values()) {
622
- callback("The service was stopped", null);
629
+ callback(text, null);
623
630
  }
624
631
  responseCallbacks.clear();
625
632
  for (let callbacks of serveCallbacks.values()) {
626
- callbacks.onWait("The service was stopped");
633
+ callbacks.onWait(text);
627
634
  }
628
635
  serveCallbacks.clear();
629
636
  for (let callback of watchCallbacks.values()) {
630
637
  try {
631
- callback(new Error("The service was stopped"), null);
638
+ callback(new Error(text), null);
632
639
  } catch (e) {
633
640
  console.error(e);
634
641
  }
@@ -636,8 +643,8 @@ function createChannel(streamIn) {
636
643
  watchCallbacks.clear();
637
644
  };
638
645
  let sendRequest = (refs, value, callback) => {
639
- if (isClosed)
640
- return callback("The service is no longer running", null);
646
+ if (closeData)
647
+ return callback("The service is no longer running" + closeData.reason, null);
641
648
  let id = nextRequestID++;
642
649
  responseCallbacks.set(id, (error, response) => {
643
650
  try {
@@ -652,8 +659,8 @@ function createChannel(streamIn) {
652
659
  streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
653
660
  };
654
661
  let sendResponse = (id, value) => {
655
- if (isClosed)
656
- throw new Error("The service is no longer running");
662
+ if (closeData)
663
+ throw new Error("The service is no longer running" + closeData.reason);
657
664
  streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
658
665
  };
659
666
  let handleRequest = async (id, request) => {
@@ -724,8 +731,8 @@ function createChannel(streamIn) {
724
731
  if (isFirstPacket) {
725
732
  isFirstPacket = false;
726
733
  let binaryVersion = String.fromCharCode(...bytes);
727
- if (binaryVersion !== "0.14.23") {
728
- throw new Error(`Cannot start service: Host version "${"0.14.23"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
734
+ if (binaryVersion !== "0.14.36") {
735
+ throw new Error(`Cannot start service: Host version "${"0.14.36"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
729
736
  }
730
737
  return;
731
738
  }
@@ -1230,7 +1237,7 @@ function createChannel(streamIn) {
1230
1237
  if (!rebuild) {
1231
1238
  let isDisposed = false;
1232
1239
  rebuild = () => new Promise((resolve, reject) => {
1233
- if (isDisposed || isClosed)
1240
+ if (isDisposed || closeData)
1234
1241
  throw new Error("Cannot rebuild");
1235
1242
  sendRequest(refs, { command: "rebuild", key }, (error2, response2) => {
1236
1243
  if (error2) {
@@ -1670,7 +1677,7 @@ function convertOutputFiles({ path, contents }) {
1670
1677
  }
1671
1678
 
1672
1679
  // lib/npm/browser.ts
1673
- var version = "0.14.23";
1680
+ var version = "0.14.36";
1674
1681
  var build = (options) => ensureServiceIsRunning().build(options);
1675
1682
  var serve = () => {
1676
1683
  throw new Error(`The "serve" API only works in node`);
@@ -1702,747 +1709,621 @@ var ensureServiceIsRunning = () => {
1702
1709
  var initialize = (options) => {
1703
1710
  options = validateInitializeOptions(options || {});
1704
1711
  let wasmURL = options.wasmURL;
1712
+ let wasmModule = options.wasmModule;
1705
1713
  let useWorker = options.worker !== false;
1706
- if (!wasmURL)
1707
- throw new Error('Must provide the "wasmURL" option');
1708
- wasmURL += "";
1714
+ if (!wasmURL && !wasmModule)
1715
+ throw new Error('Must provide either the "wasmURL" option or the "wasmModule" option');
1709
1716
  if (initializePromise)
1710
1717
  throw new Error('Cannot call "initialize" more than once');
1711
- initializePromise = startRunningService(wasmURL, useWorker);
1718
+ initializePromise = startRunningService(wasmURL || "", wasmModule, useWorker);
1712
1719
  initializePromise.catch(() => {
1713
1720
  initializePromise = void 0;
1714
1721
  });
1715
1722
  return initializePromise;
1716
1723
  };
1717
- var startRunningService = async (wasmURL, useWorker) => {
1718
- let res = await fetch(wasmURL);
1719
- if (!res.ok)
1720
- throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1721
- let wasm = await res.arrayBuffer();
1722
- let code = `{let global={};for(let o=self;o;o=Object.getPrototypeOf(o))for(let k of Object.getOwnPropertyNames(o))if(!(k in global))Object.defineProperty(global,k,{get:()=>self[k]});// Copyright 2018 The Go Authors. All rights reserved.
1723
- // Use of this source code is governed by a BSD-style
1724
- // license that can be found in the LICENSE file.
1725
-
1726
- (() => {
1727
- // Map multiple JavaScript environments to a single common API,
1728
- // preferring web standards over Node.js API.
1729
- //
1730
- // Environments considered:
1731
- // - Browsers
1732
- // - Node.js
1733
- // - Electron
1734
- // - Parcel
1735
- // - Webpack
1736
-
1737
- if (typeof global !== "undefined") {
1738
- // global already exists
1739
- } else if (typeof window !== "undefined") {
1740
- window.global = window;
1741
- } else if (typeof self !== "undefined") {
1742
- self.global = self;
1743
- } else {
1744
- throw new Error("cannot export Go (neither global, window nor self is defined)");
1745
- }
1746
-
1747
- if (!global.require && typeof require !== "undefined") {
1748
- global.require = require;
1749
- }
1750
-
1751
- if (!global.fs && global.require) {
1752
- const fs = require("fs");
1753
- if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
1754
-
1755
- global.fs = Object.assign({}, fs, {
1756
- // Hack around a Unicode bug in node: https://github.com/nodejs/node/issues/24550
1757
- write(fd, buf, offset, length, position, callback) {
1758
- if (offset === 0 && length === buf.length && position === null) {
1759
- if (fd === process.stdout.fd) {
1760
- try {
1761
- process.stdout.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf));
1762
- } catch (err) {
1763
- callback(err, 0, null);
1724
+ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
1725
+ let wasm;
1726
+ if (wasmModule) {
1727
+ wasm = wasmModule;
1728
+ } else {
1729
+ let res = await fetch(wasmURL);
1730
+ if (!res.ok)
1731
+ throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1732
+ wasm = await res.arrayBuffer();
1733
+ }
1734
+ let worker;
1735
+ if (useWorker) {
1736
+ let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(() => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n }, getInt64(sp + 8) + 1));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.14.36"}`];\n if (wasm instanceof WebAssembly.Module) {\n WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));\n } else {\n WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));\n }\n };\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
1737
+ worker = new Worker(URL.createObjectURL(blob));
1738
+ } else {
1739
+ let onmessage = ((postMessage) => {
1740
+ // Copyright 2018 The Go Authors. All rights reserved.
1741
+ // Use of this source code is governed by a BSD-style
1742
+ // license that can be found in the LICENSE file.
1743
+ let onmessage;
1744
+ let globalThis = {};
1745
+ for (let o = self; o; o = Object.getPrototypeOf(o))
1746
+ for (let k of Object.getOwnPropertyNames(o))
1747
+ if (!(k in globalThis))
1748
+ Object.defineProperty(globalThis, k, { get: () => self[k] });
1749
+ "use strict";
1750
+ (() => {
1751
+ const enosys = () => {
1752
+ const err = new Error("not implemented");
1753
+ err.code = "ENOSYS";
1754
+ return err;
1755
+ };
1756
+ if (!globalThis.fs) {
1757
+ let outputBuf = "";
1758
+ globalThis.fs = {
1759
+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
1760
+ writeSync(fd, buf) {
1761
+ outputBuf += decoder.decode(buf);
1762
+ const nl = outputBuf.lastIndexOf("\n");
1763
+ if (nl != -1) {
1764
+ console.log(outputBuf.substr(0, nl));
1765
+ outputBuf = outputBuf.substr(nl + 1);
1766
+ }
1767
+ return buf.length;
1768
+ },
1769
+ write(fd, buf, offset, length, position, callback) {
1770
+ if (offset !== 0 || length !== buf.length || position !== null) {
1771
+ callback(enosys());
1772
+ return;
1773
+ }
1774
+ const n = this.writeSync(fd, buf);
1775
+ callback(null, n);
1776
+ },
1777
+ chmod(path, mode, callback) {
1778
+ callback(enosys());
1779
+ },
1780
+ chown(path, uid, gid, callback) {
1781
+ callback(enosys());
1782
+ },
1783
+ close(fd, callback) {
1784
+ callback(enosys());
1785
+ },
1786
+ fchmod(fd, mode, callback) {
1787
+ callback(enosys());
1788
+ },
1789
+ fchown(fd, uid, gid, callback) {
1790
+ callback(enosys());
1791
+ },
1792
+ fstat(fd, callback) {
1793
+ callback(enosys());
1794
+ },
1795
+ fsync(fd, callback) {
1796
+ callback(null);
1797
+ },
1798
+ ftruncate(fd, length, callback) {
1799
+ callback(enosys());
1800
+ },
1801
+ lchown(path, uid, gid, callback) {
1802
+ callback(enosys());
1803
+ },
1804
+ link(path, link, callback) {
1805
+ callback(enosys());
1806
+ },
1807
+ lstat(path, callback) {
1808
+ callback(enosys());
1809
+ },
1810
+ mkdir(path, perm, callback) {
1811
+ callback(enosys());
1812
+ },
1813
+ open(path, flags, mode, callback) {
1814
+ callback(enosys());
1815
+ },
1816
+ read(fd, buffer, offset, length, position, callback) {
1817
+ callback(enosys());
1818
+ },
1819
+ readdir(path, callback) {
1820
+ callback(enosys());
1821
+ },
1822
+ readlink(path, callback) {
1823
+ callback(enosys());
1824
+ },
1825
+ rename(from, to, callback) {
1826
+ callback(enosys());
1827
+ },
1828
+ rmdir(path, callback) {
1829
+ callback(enosys());
1830
+ },
1831
+ stat(path, callback) {
1832
+ callback(enosys());
1833
+ },
1834
+ symlink(path, link, callback) {
1835
+ callback(enosys());
1836
+ },
1837
+ truncate(path, length, callback) {
1838
+ callback(enosys());
1839
+ },
1840
+ unlink(path, callback) {
1841
+ callback(enosys());
1842
+ },
1843
+ utimes(path, atime, mtime, callback) {
1844
+ callback(enosys());
1764
1845
  }
1765
- return;
1846
+ };
1847
+ }
1848
+ if (!globalThis.process) {
1849
+ globalThis.process = {
1850
+ getuid() {
1851
+ return -1;
1852
+ },
1853
+ getgid() {
1854
+ return -1;
1855
+ },
1856
+ geteuid() {
1857
+ return -1;
1858
+ },
1859
+ getegid() {
1860
+ return -1;
1861
+ },
1862
+ getgroups() {
1863
+ throw enosys();
1864
+ },
1865
+ pid: -1,
1866
+ ppid: -1,
1867
+ umask() {
1868
+ throw enosys();
1869
+ },
1870
+ cwd() {
1871
+ throw enosys();
1872
+ },
1873
+ chdir() {
1874
+ throw enosys();
1875
+ }
1876
+ };
1877
+ }
1878
+ if (!globalThis.crypto) {
1879
+ throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
1880
+ }
1881
+ if (!globalThis.performance) {
1882
+ throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
1883
+ }
1884
+ if (!globalThis.TextEncoder) {
1885
+ throw new Error("globalThis.TextEncoder is not available, polyfill required");
1886
+ }
1887
+ if (!globalThis.TextDecoder) {
1888
+ throw new Error("globalThis.TextDecoder is not available, polyfill required");
1889
+ }
1890
+ const encoder = new TextEncoder("utf-8");
1891
+ const decoder = new TextDecoder("utf-8");
1892
+ globalThis.Go = class {
1893
+ constructor() {
1894
+ this.argv = ["js"];
1895
+ this.env = {};
1896
+ this.exit = (code) => {
1897
+ if (code !== 0) {
1898
+ console.warn("exit code:", code);
1899
+ }
1900
+ };
1901
+ this._exitPromise = new Promise((resolve) => {
1902
+ this._resolveExitPromise = resolve;
1903
+ });
1904
+ this._pendingEvent = null;
1905
+ this._scheduledTimeouts = /* @__PURE__ */ new Map();
1906
+ this._nextCallbackTimeoutID = 1;
1907
+ const setInt64 = (addr, v) => {
1908
+ this.mem.setUint32(addr + 0, v, true);
1909
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
1910
+ };
1911
+ const getInt64 = (addr) => {
1912
+ const low = this.mem.getUint32(addr + 0, true);
1913
+ const high = this.mem.getInt32(addr + 4, true);
1914
+ return low + high * 4294967296;
1915
+ };
1916
+ const loadValue = (addr) => {
1917
+ const f = this.mem.getFloat64(addr, true);
1918
+ if (f === 0) {
1919
+ return void 0;
1920
+ }
1921
+ if (!isNaN(f)) {
1922
+ return f;
1923
+ }
1924
+ const id = this.mem.getUint32(addr, true);
1925
+ return this._values[id];
1926
+ };
1927
+ const storeValue = (addr, v) => {
1928
+ const nanHead = 2146959360;
1929
+ if (typeof v === "number" && v !== 0) {
1930
+ if (isNaN(v)) {
1931
+ this.mem.setUint32(addr + 4, nanHead, true);
1932
+ this.mem.setUint32(addr, 0, true);
1933
+ return;
1934
+ }
1935
+ this.mem.setFloat64(addr, v, true);
1936
+ return;
1937
+ }
1938
+ if (v === void 0) {
1939
+ this.mem.setFloat64(addr, 0, true);
1940
+ return;
1941
+ }
1942
+ let id = this._ids.get(v);
1943
+ if (id === void 0) {
1944
+ id = this._idPool.pop();
1945
+ if (id === void 0) {
1946
+ id = this._values.length;
1947
+ }
1948
+ this._values[id] = v;
1949
+ this._goRefCounts[id] = 0;
1950
+ this._ids.set(v, id);
1951
+ }
1952
+ this._goRefCounts[id]++;
1953
+ let typeFlag = 0;
1954
+ switch (typeof v) {
1955
+ case "object":
1956
+ if (v !== null) {
1957
+ typeFlag = 1;
1958
+ }
1959
+ break;
1960
+ case "string":
1961
+ typeFlag = 2;
1962
+ break;
1963
+ case "symbol":
1964
+ typeFlag = 3;
1965
+ break;
1966
+ case "function":
1967
+ typeFlag = 4;
1968
+ break;
1969
+ }
1970
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
1971
+ this.mem.setUint32(addr, id, true);
1972
+ };
1973
+ const loadSlice = (addr) => {
1974
+ const array = getInt64(addr + 0);
1975
+ const len = getInt64(addr + 8);
1976
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
1977
+ };
1978
+ const loadSliceOfValues = (addr) => {
1979
+ const array = getInt64(addr + 0);
1980
+ const len = getInt64(addr + 8);
1981
+ const a = new Array(len);
1982
+ for (let i = 0; i < len; i++) {
1983
+ a[i] = loadValue(array + i * 8);
1984
+ }
1985
+ return a;
1986
+ };
1987
+ const loadString = (addr) => {
1988
+ const saddr = getInt64(addr + 0);
1989
+ const len = getInt64(addr + 8);
1990
+ return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
1991
+ };
1992
+ const timeOrigin = Date.now() - performance.now();
1993
+ this.importObject = {
1994
+ go: {
1995
+ "runtime.wasmExit": (sp) => {
1996
+ sp >>>= 0;
1997
+ const code = this.mem.getInt32(sp + 8, true);
1998
+ this.exited = true;
1999
+ delete this._inst;
2000
+ delete this._values;
2001
+ delete this._goRefCounts;
2002
+ delete this._ids;
2003
+ delete this._idPool;
2004
+ this.exit(code);
2005
+ },
2006
+ "runtime.wasmWrite": (sp) => {
2007
+ sp >>>= 0;
2008
+ const fd = getInt64(sp + 8);
2009
+ const p = getInt64(sp + 16);
2010
+ const n = this.mem.getInt32(sp + 24, true);
2011
+ globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
2012
+ },
2013
+ "runtime.resetMemoryDataView": (sp) => {
2014
+ sp >>>= 0;
2015
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2016
+ },
2017
+ "runtime.nanotime1": (sp) => {
2018
+ sp >>>= 0;
2019
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
2020
+ },
2021
+ "runtime.walltime": (sp) => {
2022
+ sp >>>= 0;
2023
+ const msec = new Date().getTime();
2024
+ setInt64(sp + 8, msec / 1e3);
2025
+ this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
2026
+ },
2027
+ "runtime.scheduleTimeoutEvent": (sp) => {
2028
+ sp >>>= 0;
2029
+ const id = this._nextCallbackTimeoutID;
2030
+ this._nextCallbackTimeoutID++;
2031
+ this._scheduledTimeouts.set(id, setTimeout(() => {
2032
+ this._resume();
2033
+ while (this._scheduledTimeouts.has(id)) {
2034
+ console.warn("scheduleTimeoutEvent: missed timeout event");
2035
+ this._resume();
2036
+ }
2037
+ }, getInt64(sp + 8) + 1));
2038
+ this.mem.setInt32(sp + 16, id, true);
2039
+ },
2040
+ "runtime.clearTimeoutEvent": (sp) => {
2041
+ sp >>>= 0;
2042
+ const id = this.mem.getInt32(sp + 8, true);
2043
+ clearTimeout(this._scheduledTimeouts.get(id));
2044
+ this._scheduledTimeouts.delete(id);
2045
+ },
2046
+ "runtime.getRandomData": (sp) => {
2047
+ sp >>>= 0;
2048
+ crypto.getRandomValues(loadSlice(sp + 8));
2049
+ },
2050
+ "syscall/js.finalizeRef": (sp) => {
2051
+ sp >>>= 0;
2052
+ const id = this.mem.getUint32(sp + 8, true);
2053
+ this._goRefCounts[id]--;
2054
+ if (this._goRefCounts[id] === 0) {
2055
+ const v = this._values[id];
2056
+ this._values[id] = null;
2057
+ this._ids.delete(v);
2058
+ this._idPool.push(id);
2059
+ }
2060
+ },
2061
+ "syscall/js.stringVal": (sp) => {
2062
+ sp >>>= 0;
2063
+ storeValue(sp + 24, loadString(sp + 8));
2064
+ },
2065
+ "syscall/js.valueGet": (sp) => {
2066
+ sp >>>= 0;
2067
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
2068
+ sp = this._inst.exports.getsp() >>> 0;
2069
+ storeValue(sp + 32, result);
2070
+ },
2071
+ "syscall/js.valueSet": (sp) => {
2072
+ sp >>>= 0;
2073
+ Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
2074
+ },
2075
+ "syscall/js.valueDelete": (sp) => {
2076
+ sp >>>= 0;
2077
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
2078
+ },
2079
+ "syscall/js.valueIndex": (sp) => {
2080
+ sp >>>= 0;
2081
+ storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
2082
+ },
2083
+ "syscall/js.valueSetIndex": (sp) => {
2084
+ sp >>>= 0;
2085
+ Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
2086
+ },
2087
+ "syscall/js.valueCall": (sp) => {
2088
+ sp >>>= 0;
2089
+ try {
2090
+ const v = loadValue(sp + 8);
2091
+ const m = Reflect.get(v, loadString(sp + 16));
2092
+ const args = loadSliceOfValues(sp + 32);
2093
+ const result = Reflect.apply(m, v, args);
2094
+ sp = this._inst.exports.getsp() >>> 0;
2095
+ storeValue(sp + 56, result);
2096
+ this.mem.setUint8(sp + 64, 1);
2097
+ } catch (err) {
2098
+ sp = this._inst.exports.getsp() >>> 0;
2099
+ storeValue(sp + 56, err);
2100
+ this.mem.setUint8(sp + 64, 0);
2101
+ }
2102
+ },
2103
+ "syscall/js.valueInvoke": (sp) => {
2104
+ sp >>>= 0;
2105
+ try {
2106
+ const v = loadValue(sp + 8);
2107
+ const args = loadSliceOfValues(sp + 16);
2108
+ const result = Reflect.apply(v, void 0, args);
2109
+ sp = this._inst.exports.getsp() >>> 0;
2110
+ storeValue(sp + 40, result);
2111
+ this.mem.setUint8(sp + 48, 1);
2112
+ } catch (err) {
2113
+ sp = this._inst.exports.getsp() >>> 0;
2114
+ storeValue(sp + 40, err);
2115
+ this.mem.setUint8(sp + 48, 0);
2116
+ }
2117
+ },
2118
+ "syscall/js.valueNew": (sp) => {
2119
+ sp >>>= 0;
2120
+ try {
2121
+ const v = loadValue(sp + 8);
2122
+ const args = loadSliceOfValues(sp + 16);
2123
+ const result = Reflect.construct(v, args);
2124
+ sp = this._inst.exports.getsp() >>> 0;
2125
+ storeValue(sp + 40, result);
2126
+ this.mem.setUint8(sp + 48, 1);
2127
+ } catch (err) {
2128
+ sp = this._inst.exports.getsp() >>> 0;
2129
+ storeValue(sp + 40, err);
2130
+ this.mem.setUint8(sp + 48, 0);
2131
+ }
2132
+ },
2133
+ "syscall/js.valueLength": (sp) => {
2134
+ sp >>>= 0;
2135
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
2136
+ },
2137
+ "syscall/js.valuePrepareString": (sp) => {
2138
+ sp >>>= 0;
2139
+ const str = encoder.encode(String(loadValue(sp + 8)));
2140
+ storeValue(sp + 16, str);
2141
+ setInt64(sp + 24, str.length);
2142
+ },
2143
+ "syscall/js.valueLoadString": (sp) => {
2144
+ sp >>>= 0;
2145
+ const str = loadValue(sp + 8);
2146
+ loadSlice(sp + 16).set(str);
2147
+ },
2148
+ "syscall/js.valueInstanceOf": (sp) => {
2149
+ sp >>>= 0;
2150
+ this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
2151
+ },
2152
+ "syscall/js.copyBytesToGo": (sp) => {
2153
+ sp >>>= 0;
2154
+ const dst = loadSlice(sp + 8);
2155
+ const src = loadValue(sp + 32);
2156
+ if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
2157
+ this.mem.setUint8(sp + 48, 0);
2158
+ return;
2159
+ }
2160
+ const toCopy = src.subarray(0, dst.length);
2161
+ dst.set(toCopy);
2162
+ setInt64(sp + 40, toCopy.length);
2163
+ this.mem.setUint8(sp + 48, 1);
2164
+ },
2165
+ "syscall/js.copyBytesToJS": (sp) => {
2166
+ sp >>>= 0;
2167
+ const dst = loadValue(sp + 8);
2168
+ const src = loadSlice(sp + 16);
2169
+ if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
2170
+ this.mem.setUint8(sp + 48, 0);
2171
+ return;
2172
+ }
2173
+ const toCopy = src.subarray(0, dst.length);
2174
+ dst.set(toCopy);
2175
+ setInt64(sp + 40, toCopy.length);
2176
+ this.mem.setUint8(sp + 48, 1);
2177
+ },
2178
+ "debug": (value) => {
2179
+ console.log(value);
2180
+ }
2181
+ }
2182
+ };
1766
2183
  }
1767
- if (fd === process.stderr.fd) {
1768
- try {
1769
- process.stderr.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf));
1770
- } catch (err) {
1771
- callback(err, 0, null);
2184
+ async run(instance) {
2185
+ if (!(instance instanceof WebAssembly.Instance)) {
2186
+ throw new Error("Go.run: WebAssembly.Instance expected");
1772
2187
  }
2188
+ this._inst = instance;
2189
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2190
+ this._values = [
2191
+ NaN,
2192
+ 0,
2193
+ null,
2194
+ true,
2195
+ false,
2196
+ globalThis,
2197
+ this
2198
+ ];
2199
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
2200
+ this._ids = /* @__PURE__ */ new Map([
2201
+ [0, 1],
2202
+ [null, 2],
2203
+ [true, 3],
2204
+ [false, 4],
2205
+ [globalThis, 5],
2206
+ [this, 6]
2207
+ ]);
2208
+ this._idPool = [];
2209
+ this.exited = false;
2210
+ let offset = 4096;
2211
+ const strPtr = (str) => {
2212
+ const ptr = offset;
2213
+ const bytes = encoder.encode(str + "\0");
2214
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
2215
+ offset += bytes.length;
2216
+ if (offset % 8 !== 0) {
2217
+ offset += 8 - offset % 8;
2218
+ }
2219
+ return ptr;
2220
+ };
2221
+ const argc = this.argv.length;
2222
+ const argvPtrs = [];
2223
+ this.argv.forEach((arg) => {
2224
+ argvPtrs.push(strPtr(arg));
2225
+ });
2226
+ argvPtrs.push(0);
2227
+ const keys = Object.keys(this.env).sort();
2228
+ keys.forEach((key) => {
2229
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
2230
+ });
2231
+ argvPtrs.push(0);
2232
+ const argv = offset;
2233
+ argvPtrs.forEach((ptr) => {
2234
+ this.mem.setUint32(offset, ptr, true);
2235
+ this.mem.setUint32(offset + 4, 0, true);
2236
+ offset += 8;
2237
+ });
2238
+ const wasmMinDataAddr = 4096 + 8192;
2239
+ if (offset >= wasmMinDataAddr) {
2240
+ throw new Error("total length of command line and environment variables exceeds limit");
2241
+ }
2242
+ this._inst.exports.run(argc, argv);
2243
+ if (this.exited) {
2244
+ this._resolveExitPromise();
2245
+ }
2246
+ await this._exitPromise;
2247
+ }
2248
+ _resume() {
2249
+ if (this.exited) {
2250
+ throw new Error("Go program has already exited");
2251
+ }
2252
+ this._inst.exports.resume();
2253
+ if (this.exited) {
2254
+ this._resolveExitPromise();
2255
+ }
2256
+ }
2257
+ _makeFuncWrapper(id) {
2258
+ const go = this;
2259
+ return function() {
2260
+ const event = { id, this: this, args: arguments };
2261
+ go._pendingEvent = event;
2262
+ go._resume();
2263
+ return event.result;
2264
+ };
2265
+ }
2266
+ };
2267
+ })();
2268
+ onmessage = ({ data: wasm }) => {
2269
+ let decoder = new TextDecoder();
2270
+ let fs = globalThis.fs;
2271
+ let stderr = "";
2272
+ fs.writeSync = (fd, buffer) => {
2273
+ if (fd === 1) {
2274
+ postMessage(buffer);
2275
+ } else if (fd === 2) {
2276
+ stderr += decoder.decode(buffer);
2277
+ let parts = stderr.split("\n");
2278
+ if (parts.length > 1)
2279
+ console.log(parts.slice(0, -1).join("\n"));
2280
+ stderr = parts[parts.length - 1];
2281
+ } else {
2282
+ throw new Error("Bad write");
2283
+ }
2284
+ return buffer.length;
2285
+ };
2286
+ let stdin = [];
2287
+ let resumeStdin;
2288
+ let stdinPos = 0;
2289
+ onmessage = ({ data }) => {
2290
+ if (data.length > 0) {
2291
+ stdin.push(data);
2292
+ if (resumeStdin)
2293
+ resumeStdin();
2294
+ }
2295
+ };
2296
+ fs.read = (fd, buffer, offset, length, position, callback) => {
2297
+ if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {
2298
+ throw new Error("Bad read");
2299
+ }
2300
+ if (stdin.length === 0) {
2301
+ resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);
1773
2302
  return;
1774
2303
  }
2304
+ let first = stdin[0];
2305
+ let count = Math.max(0, Math.min(length, first.length - stdinPos));
2306
+ buffer.set(first.subarray(stdinPos, stdinPos + count), offset);
2307
+ stdinPos += count;
2308
+ if (stdinPos === first.length) {
2309
+ stdin.shift();
2310
+ stdinPos = 0;
2311
+ }
2312
+ callback(null, count);
2313
+ };
2314
+ let go = new globalThis.Go();
2315
+ go.argv = ["", `--service=${"0.14.36"}`];
2316
+ if (wasm instanceof WebAssembly.Module) {
2317
+ WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2318
+ } else {
2319
+ WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
1775
2320
  }
1776
- fs.write(fd, buf, offset, length, position, callback);
1777
- },
1778
- });
1779
-
1780
- }
1781
- }
1782
-
1783
- const enosys = () => {
1784
- const err = new Error("not implemented");
1785
- err.code = "ENOSYS";
1786
- return err;
1787
- };
1788
-
1789
- if (!global.fs) {
1790
- let outputBuf = "";
1791
- global.fs = {
1792
- constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
1793
- writeSync(fd, buf) {
1794
- outputBuf += decoder.decode(buf);
1795
- const nl = outputBuf.lastIndexOf("\\n");
1796
- if (nl != -1) {
1797
- console.log(outputBuf.substr(0, nl));
1798
- outputBuf = outputBuf.substr(nl + 1);
1799
- }
1800
- return buf.length;
1801
- },
1802
- write(fd, buf, offset, length, position, callback) {
1803
- if (offset !== 0 || length !== buf.length || position !== null) {
1804
- callback(enosys());
1805
- return;
1806
- }
1807
- const n = this.writeSync(fd, buf);
1808
- callback(null, n);
1809
- },
1810
- chmod(path, mode, callback) { callback(enosys()); },
1811
- chown(path, uid, gid, callback) { callback(enosys()); },
1812
- close(fd, callback) { callback(enosys()); },
1813
- fchmod(fd, mode, callback) { callback(enosys()); },
1814
- fchown(fd, uid, gid, callback) { callback(enosys()); },
1815
- fstat(fd, callback) { callback(enosys()); },
1816
- fsync(fd, callback) { callback(null); },
1817
- ftruncate(fd, length, callback) { callback(enosys()); },
1818
- lchown(path, uid, gid, callback) { callback(enosys()); },
1819
- link(path, link, callback) { callback(enosys()); },
1820
- lstat(path, callback) { callback(enosys()); },
1821
- mkdir(path, perm, callback) { callback(enosys()); },
1822
- open(path, flags, mode, callback) { callback(enosys()); },
1823
- read(fd, buffer, offset, length, position, callback) { callback(enosys()); },
1824
- readdir(path, callback) { callback(enosys()); },
1825
- readlink(path, callback) { callback(enosys()); },
1826
- rename(from, to, callback) { callback(enosys()); },
1827
- rmdir(path, callback) { callback(enosys()); },
1828
- stat(path, callback) { callback(enosys()); },
1829
- symlink(path, link, callback) { callback(enosys()); },
1830
- truncate(path, length, callback) { callback(enosys()); },
1831
- unlink(path, callback) { callback(enosys()); },
1832
- utimes(path, atime, mtime, callback) { callback(enosys()); },
1833
- };
1834
- }
1835
-
1836
- if (!global.process) {
1837
- global.process = {
1838
- getuid() { return -1; },
1839
- getgid() { return -1; },
1840
- geteuid() { return -1; },
1841
- getegid() { return -1; },
1842
- getgroups() { throw enosys(); },
1843
- pid: -1,
1844
- ppid: -1,
1845
- umask() { throw enosys(); },
1846
- cwd() { throw enosys(); },
1847
- chdir() { throw enosys(); },
1848
- }
1849
- }
1850
-
1851
- if (!global.crypto && global.require) {
1852
- const nodeCrypto = require("crypto");
1853
- global.crypto = {
1854
- getRandomValues(b) {
1855
- nodeCrypto.randomFillSync(b);
1856
- },
1857
- };
1858
- }
1859
- if (!global.crypto) {
1860
- throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");
1861
- }
1862
-
1863
- if (!global.performance) {
1864
- global.performance = {
1865
- now() {
1866
- const [sec, nsec] = process.hrtime();
1867
- return sec * 1000 + nsec / 1000000;
1868
- },
1869
- };
1870
- }
1871
-
1872
- if (!global.TextEncoder && global.require) {
1873
- global.TextEncoder = require("util").TextEncoder;
1874
- }
1875
- if (!global.TextEncoder) {
1876
- throw new Error("global.TextEncoder is not available, polyfill required");
1877
- }
1878
-
1879
- if (!global.TextDecoder && global.require) {
1880
- global.TextDecoder = require("util").TextDecoder;
1881
- }
1882
- if (!global.TextDecoder) {
1883
- throw new Error("global.TextDecoder is not available, polyfill required");
1884
- }
1885
-
1886
-
1887
- // Make sure Go sees the shadowed "fs" global
1888
- const { fs } = global;
1889
-
1890
-
1891
- const encoder = new TextEncoder("utf-8");
1892
- const decoder = new TextDecoder("utf-8");
1893
-
1894
- global.Go = class {
1895
- constructor() {
1896
- this.argv = ["js"];
1897
- this.env = {};
1898
- this.exit = (code) => {
1899
- if (code !== 0) {
1900
- console.warn("exit code:", code);
1901
- }
1902
- };
1903
- this._exitPromise = new Promise((resolve) => {
1904
- this._resolveExitPromise = resolve;
1905
- });
1906
- this._pendingEvent = null;
1907
- this._scheduledTimeouts = new Map();
1908
- this._nextCallbackTimeoutID = 1;
1909
-
1910
- const setInt64 = (addr, v) => {
1911
- this.mem.setUint32(addr + 0, v, true);
1912
- this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
1913
- }
1914
-
1915
- const getInt64 = (addr) => {
1916
- const low = this.mem.getUint32(addr + 0, true);
1917
- const high = this.mem.getInt32(addr + 4, true);
1918
- return low + high * 4294967296;
1919
- }
1920
-
1921
- const loadValue = (addr) => {
1922
- const f = this.mem.getFloat64(addr, true);
1923
- if (f === 0) {
1924
- return undefined;
1925
- }
1926
- if (!isNaN(f)) {
1927
- return f;
1928
- }
1929
-
1930
- const id = this.mem.getUint32(addr, true);
1931
- return this._values[id];
1932
- }
1933
-
1934
- const storeValue = (addr, v) => {
1935
- const nanHead = 0x7FF80000;
1936
-
1937
- if (typeof v === "number" && v !== 0) {
1938
- if (isNaN(v)) {
1939
- this.mem.setUint32(addr + 4, nanHead, true);
1940
- this.mem.setUint32(addr, 0, true);
1941
- return;
1942
- }
1943
- this.mem.setFloat64(addr, v, true);
1944
- return;
1945
- }
1946
-
1947
- if (v === undefined) {
1948
- this.mem.setFloat64(addr, 0, true);
1949
- return;
1950
- }
1951
-
1952
- let id = this._ids.get(v);
1953
- if (id === undefined) {
1954
- id = this._idPool.pop();
1955
- if (id === undefined) {
1956
- id = this._values.length;
1957
- }
1958
- this._values[id] = v;
1959
- this._goRefCounts[id] = 0;
1960
- this._ids.set(v, id);
1961
- }
1962
- this._goRefCounts[id]++;
1963
- let typeFlag = 0;
1964
- switch (typeof v) {
1965
- case "object":
1966
- if (v !== null) {
1967
- typeFlag = 1;
1968
- }
1969
- break;
1970
- case "string":
1971
- typeFlag = 2;
1972
- break;
1973
- case "symbol":
1974
- typeFlag = 3;
1975
- break;
1976
- case "function":
1977
- typeFlag = 4;
1978
- break;
1979
- }
1980
- this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
1981
- this.mem.setUint32(addr, id, true);
1982
- }
1983
-
1984
- const loadSlice = (addr) => {
1985
- const array = getInt64(addr + 0);
1986
- const len = getInt64(addr + 8);
1987
- return new Uint8Array(this._inst.exports.mem.buffer, array, len);
1988
- }
1989
-
1990
- const loadSliceOfValues = (addr) => {
1991
- const array = getInt64(addr + 0);
1992
- const len = getInt64(addr + 8);
1993
- const a = new Array(len);
1994
- for (let i = 0; i < len; i++) {
1995
- a[i] = loadValue(array + i * 8);
1996
- }
1997
- return a;
1998
- }
1999
-
2000
- const loadString = (addr) => {
2001
- const saddr = getInt64(addr + 0);
2002
- const len = getInt64(addr + 8);
2003
- return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
2004
- }
2005
-
2006
- const timeOrigin = Date.now() - performance.now();
2007
- this.importObject = {
2008
- go: {
2009
- // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
2010
- // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
2011
- // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
2012
- // This changes the SP, thus we have to update the SP used by the imported function.
2013
-
2014
- // func wasmExit(code int32)
2015
- "runtime.wasmExit": (sp) => {
2016
- sp >>>= 0;
2017
- const code = this.mem.getInt32(sp + 8, true);
2018
- this.exited = true;
2019
- delete this._inst;
2020
- delete this._values;
2021
- delete this._goRefCounts;
2022
- delete this._ids;
2023
- delete this._idPool;
2024
- this.exit(code);
2025
- },
2026
-
2027
- // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
2028
- "runtime.wasmWrite": (sp) => {
2029
- sp >>>= 0;
2030
- const fd = getInt64(sp + 8);
2031
- const p = getInt64(sp + 16);
2032
- const n = this.mem.getInt32(sp + 24, true);
2033
- fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
2034
- },
2035
-
2036
- // func resetMemoryDataView()
2037
- "runtime.resetMemoryDataView": (sp) => {
2038
- sp >>>= 0;
2039
- this.mem = new DataView(this._inst.exports.mem.buffer);
2040
- },
2041
-
2042
- // func nanotime1() int64
2043
- "runtime.nanotime1": (sp) => {
2044
- sp >>>= 0;
2045
- setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
2046
- },
2047
-
2048
- // func walltime() (sec int64, nsec int32)
2049
- "runtime.walltime": (sp) => {
2050
- sp >>>= 0;
2051
- const msec = (new Date).getTime();
2052
- setInt64(sp + 8, msec / 1000);
2053
- this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
2054
- },
2055
-
2056
- // func scheduleTimeoutEvent(delay int64) int32
2057
- "runtime.scheduleTimeoutEvent": (sp) => {
2058
- sp >>>= 0;
2059
- const id = this._nextCallbackTimeoutID;
2060
- this._nextCallbackTimeoutID++;
2061
- this._scheduledTimeouts.set(id, setTimeout(
2062
- () => {
2063
- this._resume();
2064
- while (this._scheduledTimeouts.has(id)) {
2065
- // for some reason Go failed to register the timeout event, log and try again
2066
- // (temporary workaround for https://github.com/golang/go/issues/28975)
2067
- console.warn("scheduleTimeoutEvent: missed timeout event");
2068
- this._resume();
2069
- }
2070
- },
2071
- getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early
2072
- ));
2073
- this.mem.setInt32(sp + 16, id, true);
2074
- },
2075
-
2076
- // func clearTimeoutEvent(id int32)
2077
- "runtime.clearTimeoutEvent": (sp) => {
2078
- sp >>>= 0;
2079
- const id = this.mem.getInt32(sp + 8, true);
2080
- clearTimeout(this._scheduledTimeouts.get(id));
2081
- this._scheduledTimeouts.delete(id);
2082
- },
2083
-
2084
- // func getRandomData(r []byte)
2085
- "runtime.getRandomData": (sp) => {
2086
- sp >>>= 0;
2087
- crypto.getRandomValues(loadSlice(sp + 8));
2088
- },
2089
-
2090
- // func finalizeRef(v ref)
2091
- "syscall/js.finalizeRef": (sp) => {
2092
- sp >>>= 0;
2093
- const id = this.mem.getUint32(sp + 8, true);
2094
- this._goRefCounts[id]--;
2095
- if (this._goRefCounts[id] === 0) {
2096
- const v = this._values[id];
2097
- this._values[id] = null;
2098
- this._ids.delete(v);
2099
- this._idPool.push(id);
2100
- }
2101
- },
2102
-
2103
- // func stringVal(value string) ref
2104
- "syscall/js.stringVal": (sp) => {
2105
- sp >>>= 0;
2106
- storeValue(sp + 24, loadString(sp + 8));
2107
- },
2108
-
2109
- // func valueGet(v ref, p string) ref
2110
- "syscall/js.valueGet": (sp) => {
2111
- sp >>>= 0;
2112
- const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
2113
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2114
- storeValue(sp + 32, result);
2115
- },
2116
-
2117
- // func valueSet(v ref, p string, x ref)
2118
- "syscall/js.valueSet": (sp) => {
2119
- sp >>>= 0;
2120
- Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
2121
- },
2122
-
2123
- // func valueDelete(v ref, p string)
2124
- "syscall/js.valueDelete": (sp) => {
2125
- sp >>>= 0;
2126
- Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
2127
- },
2128
-
2129
- // func valueIndex(v ref, i int) ref
2130
- "syscall/js.valueIndex": (sp) => {
2131
- sp >>>= 0;
2132
- storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
2133
- },
2134
-
2135
- // valueSetIndex(v ref, i int, x ref)
2136
- "syscall/js.valueSetIndex": (sp) => {
2137
- sp >>>= 0;
2138
- Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
2139
- },
2140
-
2141
- // func valueCall(v ref, m string, args []ref) (ref, bool)
2142
- "syscall/js.valueCall": (sp) => {
2143
- sp >>>= 0;
2144
- try {
2145
- const v = loadValue(sp + 8);
2146
- const m = Reflect.get(v, loadString(sp + 16));
2147
- const args = loadSliceOfValues(sp + 32);
2148
- const result = Reflect.apply(m, v, args);
2149
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2150
- storeValue(sp + 56, result);
2151
- this.mem.setUint8(sp + 64, 1);
2152
- } catch (err) {
2153
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2154
- storeValue(sp + 56, err);
2155
- this.mem.setUint8(sp + 64, 0);
2156
- }
2157
- },
2158
-
2159
- // func valueInvoke(v ref, args []ref) (ref, bool)
2160
- "syscall/js.valueInvoke": (sp) => {
2161
- sp >>>= 0;
2162
- try {
2163
- const v = loadValue(sp + 8);
2164
- const args = loadSliceOfValues(sp + 16);
2165
- const result = Reflect.apply(v, undefined, args);
2166
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2167
- storeValue(sp + 40, result);
2168
- this.mem.setUint8(sp + 48, 1);
2169
- } catch (err) {
2170
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2171
- storeValue(sp + 40, err);
2172
- this.mem.setUint8(sp + 48, 0);
2173
- }
2174
- },
2175
-
2176
- // func valueNew(v ref, args []ref) (ref, bool)
2177
- "syscall/js.valueNew": (sp) => {
2178
- sp >>>= 0;
2179
- try {
2180
- const v = loadValue(sp + 8);
2181
- const args = loadSliceOfValues(sp + 16);
2182
- const result = Reflect.construct(v, args);
2183
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2184
- storeValue(sp + 40, result);
2185
- this.mem.setUint8(sp + 48, 1);
2186
- } catch (err) {
2187
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2188
- storeValue(sp + 40, err);
2189
- this.mem.setUint8(sp + 48, 0);
2190
- }
2191
- },
2192
-
2193
- // func valueLength(v ref) int
2194
- "syscall/js.valueLength": (sp) => {
2195
- sp >>>= 0;
2196
- setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
2197
- },
2198
-
2199
- // valuePrepareString(v ref) (ref, int)
2200
- "syscall/js.valuePrepareString": (sp) => {
2201
- sp >>>= 0;
2202
- const str = encoder.encode(String(loadValue(sp + 8)));
2203
- storeValue(sp + 16, str);
2204
- setInt64(sp + 24, str.length);
2205
- },
2206
-
2207
- // valueLoadString(v ref, b []byte)
2208
- "syscall/js.valueLoadString": (sp) => {
2209
- sp >>>= 0;
2210
- const str = loadValue(sp + 8);
2211
- loadSlice(sp + 16).set(str);
2212
- },
2213
-
2214
- // func valueInstanceOf(v ref, t ref) bool
2215
- "syscall/js.valueInstanceOf": (sp) => {
2216
- sp >>>= 0;
2217
- this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
2218
- },
2219
-
2220
- // func copyBytesToGo(dst []byte, src ref) (int, bool)
2221
- "syscall/js.copyBytesToGo": (sp) => {
2222
- sp >>>= 0;
2223
- const dst = loadSlice(sp + 8);
2224
- const src = loadValue(sp + 32);
2225
- if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
2226
- this.mem.setUint8(sp + 48, 0);
2227
- return;
2228
- }
2229
- const toCopy = src.subarray(0, dst.length);
2230
- dst.set(toCopy);
2231
- setInt64(sp + 40, toCopy.length);
2232
- this.mem.setUint8(sp + 48, 1);
2233
- },
2234
-
2235
- // func copyBytesToJS(dst ref, src []byte) (int, bool)
2236
- "syscall/js.copyBytesToJS": (sp) => {
2237
- sp >>>= 0;
2238
- const dst = loadValue(sp + 8);
2239
- const src = loadSlice(sp + 16);
2240
- if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
2241
- this.mem.setUint8(sp + 48, 0);
2242
- return;
2243
- }
2244
- const toCopy = src.subarray(0, dst.length);
2245
- dst.set(toCopy);
2246
- setInt64(sp + 40, toCopy.length);
2247
- this.mem.setUint8(sp + 48, 1);
2248
- },
2249
-
2250
- "debug": (value) => {
2251
- console.log(value);
2252
- },
2253
- }
2254
- };
2255
- }
2256
-
2257
- async run(instance) {
2258
- if (!(instance instanceof WebAssembly.Instance)) {
2259
- throw new Error("Go.run: WebAssembly.Instance expected");
2260
- }
2261
- this._inst = instance;
2262
- this.mem = new DataView(this._inst.exports.mem.buffer);
2263
- this._values = [ // JS values that Go currently has references to, indexed by reference id
2264
- NaN,
2265
- 0,
2266
- null,
2267
- true,
2268
- false,
2269
- global,
2270
- this,
2271
- ];
2272
- this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
2273
- this._ids = new Map([ // mapping from JS values to reference ids
2274
- [0, 1],
2275
- [null, 2],
2276
- [true, 3],
2277
- [false, 4],
2278
- [global, 5],
2279
- [this, 6],
2280
- ]);
2281
- this._idPool = []; // unused ids that have been garbage collected
2282
- this.exited = false; // whether the Go program has exited
2283
-
2284
- // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
2285
- let offset = 4096;
2286
-
2287
- const strPtr = (str) => {
2288
- const ptr = offset;
2289
- const bytes = encoder.encode(str + "\\0");
2290
- new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
2291
- offset += bytes.length;
2292
- if (offset % 8 !== 0) {
2293
- offset += 8 - (offset % 8);
2294
- }
2295
- return ptr;
2296
- };
2297
-
2298
- const argc = this.argv.length;
2299
-
2300
- const argvPtrs = [];
2301
- this.argv.forEach((arg) => {
2302
- argvPtrs.push(strPtr(arg));
2303
- });
2304
- argvPtrs.push(0);
2305
-
2306
- const keys = Object.keys(this.env).sort();
2307
- keys.forEach((key) => {
2308
- argvPtrs.push(strPtr(\`\${key}=\${this.env[key]}\`));
2309
- });
2310
- argvPtrs.push(0);
2311
-
2312
- const argv = offset;
2313
- argvPtrs.forEach((ptr) => {
2314
- this.mem.setUint32(offset, ptr, true);
2315
- this.mem.setUint32(offset + 4, 0, true);
2316
- offset += 8;
2317
- });
2318
-
2319
- // The linker guarantees global data starts from at least wasmMinDataAddr.
2320
- // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
2321
- const wasmMinDataAddr = 4096 + 8192;
2322
- if (offset >= wasmMinDataAddr) {
2323
- throw new Error("total length of command line and environment variables exceeds limit");
2324
- }
2325
-
2326
- this._inst.exports.run(argc, argv);
2327
- if (this.exited) {
2328
- this._resolveExitPromise();
2329
- }
2330
- await this._exitPromise;
2331
- }
2332
-
2333
- _resume() {
2334
- if (this.exited) {
2335
- throw new Error("Go program has already exited");
2336
- }
2337
- this._inst.exports.resume();
2338
- if (this.exited) {
2339
- this._resolveExitPromise();
2340
- }
2341
- }
2342
-
2343
- _makeFuncWrapper(id) {
2344
- const go = this;
2345
- return function () {
2346
- const event = { id: id, this: this, args: arguments };
2347
- go._pendingEvent = event;
2348
- go._resume();
2349
- return event.result;
2350
- };
2351
- }
2352
- }
2353
-
2354
- if (
2355
- typeof module !== "undefined" &&
2356
- global.require &&
2357
- global.require.main === module &&
2358
- global.process &&
2359
- global.process.versions &&
2360
- !global.process.versions.electron
2361
- ) {
2362
- if (process.argv.length < 3) {
2363
- console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
2364
- process.exit(1);
2365
- }
2366
-
2367
- const go = new Go();
2368
- go.argv = process.argv.slice(2);
2369
- go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
2370
- go.exit = process.exit;
2371
- WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
2372
- process.on("exit", (code) => { // Node.js exits if no event handler is pending
2373
- if (code === 0 && !go.exited) {
2374
- // deadlock, make Go print error and stack traces
2375
- go._pendingEvent = { id: 0 };
2376
- go._resume();
2377
- }
2378
- });
2379
- return go.run(result.instance);
2380
- }).catch((err) => {
2381
- console.error(err);
2382
- process.exit(1);
2383
- });
2384
- }
2385
- })();
2386
- onmessage = ({ data: wasm }) => {
2387
- let decoder = new TextDecoder();
2388
- let fs = global.fs;
2389
- let stderr = "";
2390
- fs.writeSync = (fd, buffer) => {
2391
- if (fd === 1) {
2392
- postMessage(buffer);
2393
- } else if (fd === 2) {
2394
- stderr += decoder.decode(buffer);
2395
- let parts = stderr.split("\\n");
2396
- if (parts.length > 1)
2397
- console.log(parts.slice(0, -1).join("\\n"));
2398
- stderr = parts[parts.length - 1];
2399
- } else {
2400
- throw new Error("Bad write");
2401
- }
2402
- return buffer.length;
2403
- };
2404
- let stdin = [];
2405
- let resumeStdin;
2406
- let stdinPos = 0;
2407
- onmessage = ({ data }) => {
2408
- if (data.length > 0) {
2409
- stdin.push(data);
2410
- if (resumeStdin)
2411
- resumeStdin();
2412
- }
2413
- };
2414
- fs.read = (fd, buffer, offset, length, position, callback) => {
2415
- if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {
2416
- throw new Error("Bad read");
2417
- }
2418
- if (stdin.length === 0) {
2419
- resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);
2420
- return;
2421
- }
2422
- let first = stdin[0];
2423
- let count = Math.max(0, Math.min(length, first.length - stdinPos));
2424
- buffer.set(first.subarray(stdinPos, stdinPos + count), offset);
2425
- stdinPos += count;
2426
- if (stdinPos === first.length) {
2427
- stdin.shift();
2428
- stdinPos = 0;
2429
- }
2430
- callback(null, count);
2431
- };
2432
- let go = new global.Go();
2433
- go.argv = ["", \`--service=\${"0.14.23"}\`];
2434
- WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
2435
- };}`;
2436
- let worker;
2437
- if (useWorker) {
2438
- let blob = new Blob([code], { type: "text/javascript" });
2439
- worker = new Worker(URL.createObjectURL(blob));
2440
- } else {
2441
- let fn = new Function("postMessage", code + `var onmessage; return m => onmessage(m)`);
2442
- let onmessage = fn((data) => worker.onmessage({ data }));
2321
+ };
2322
+ return (m) => onmessage(m);
2323
+ })((data) => worker.onmessage({ data }));
2443
2324
  worker = {
2444
2325
  onmessage: null,
2445
- postMessage: (data) => onmessage({ data }),
2326
+ postMessage: (data) => setTimeout(() => onmessage({ data })),
2446
2327
  terminate() {
2447
2328
  }
2448
2329
  };
@@ -2465,7 +2346,7 @@ onmessage = ({ data: wasm }) => {
2465
2346
  options,
2466
2347
  isTTY: false,
2467
2348
  defaultWD: "/",
2468
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2349
+ callback: (err, res) => err ? reject(err) : resolve(res)
2469
2350
  })),
2470
2351
  transform: (input, options) => new Promise((resolve, reject) => service.transform({
2471
2352
  callName: "transform",
@@ -2481,21 +2362,21 @@ onmessage = ({ data: wasm }) => {
2481
2362
  callback(null);
2482
2363
  }
2483
2364
  },
2484
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2365
+ callback: (err, res) => err ? reject(err) : resolve(res)
2485
2366
  })),
2486
2367
  formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
2487
2368
  callName: "formatMessages",
2488
2369
  refs: null,
2489
2370
  messages,
2490
2371
  options,
2491
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2372
+ callback: (err, res) => err ? reject(err) : resolve(res)
2492
2373
  })),
2493
2374
  analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
2494
2375
  callName: "analyzeMetafile",
2495
2376
  refs: null,
2496
2377
  metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
2497
2378
  options,
2498
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2379
+ callback: (err, res) => err ? reject(err) : resolve(res)
2499
2380
  }))
2500
2381
  };
2501
2382
  };