isomorfeus-asset-manager 0.14.21 → 0.14.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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);
@@ -299,6 +303,7 @@ function pushCommonFlags(flags, options, keys) {
299
303
  let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
300
304
  let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
301
305
  let define = getFlag(options, keys, "define", mustBeObject);
306
+ let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
302
307
  let pure = getFlag(options, keys, "pure", mustBeArray);
303
308
  let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
304
309
  if (legalComments)
@@ -338,6 +343,8 @@ function pushCommonFlags(flags, options, keys) {
338
343
  flags.push(`--mangle-props=${mangleProps.source}`);
339
344
  if (reserveProps)
340
345
  flags.push(`--reserve-props=${reserveProps.source}`);
346
+ if (mangleQuoted !== void 0)
347
+ flags.push(`--mangle-quoted=${mangleQuoted}`);
341
348
  if (jsx)
342
349
  flags.push(`--jsx=${jsx}`);
343
350
  if (jsxFactory)
@@ -351,6 +358,13 @@ function pushCommonFlags(flags, options, keys) {
351
358
  flags.push(`--define:${key}=${define[key]}`);
352
359
  }
353
360
  }
361
+ if (logOverride) {
362
+ for (let key in logOverride) {
363
+ if (key.indexOf("=") >= 0)
364
+ throw new Error(`Invalid log override: ${key}`);
365
+ flags.push(`--log-override:${key}=${logOverride[key]}`);
366
+ }
367
+ }
354
368
  if (pure)
355
369
  for (let fn of pure)
356
370
  flags.push(`--pure:${fn}`);
@@ -587,7 +601,7 @@ function createChannel(streamIn) {
587
601
  let pluginCallbacks = /* @__PURE__ */ new Map();
588
602
  let watchCallbacks = /* @__PURE__ */ new Map();
589
603
  let serveCallbacks = /* @__PURE__ */ new Map();
590
- let isClosed = false;
604
+ let closeData = null;
591
605
  let nextRequestID = 0;
592
606
  let nextBuildKey = 0;
593
607
  let stdout = new Uint8Array(16 * 1024);
@@ -616,19 +630,20 @@ function createChannel(streamIn) {
616
630
  stdoutUsed -= offset;
617
631
  }
618
632
  };
619
- let afterClose = () => {
620
- isClosed = true;
633
+ let afterClose = (error) => {
634
+ closeData = { reason: error ? ": " + (error.message || error) : "" };
635
+ const text = "The service was stopped" + closeData.reason;
621
636
  for (let callback of responseCallbacks.values()) {
622
- callback("The service was stopped", null);
637
+ callback(text, null);
623
638
  }
624
639
  responseCallbacks.clear();
625
640
  for (let callbacks of serveCallbacks.values()) {
626
- callbacks.onWait("The service was stopped");
641
+ callbacks.onWait(text);
627
642
  }
628
643
  serveCallbacks.clear();
629
644
  for (let callback of watchCallbacks.values()) {
630
645
  try {
631
- callback(new Error("The service was stopped"), null);
646
+ callback(new Error(text), null);
632
647
  } catch (e) {
633
648
  console.error(e);
634
649
  }
@@ -636,8 +651,8 @@ function createChannel(streamIn) {
636
651
  watchCallbacks.clear();
637
652
  };
638
653
  let sendRequest = (refs, value, callback) => {
639
- if (isClosed)
640
- return callback("The service is no longer running", null);
654
+ if (closeData)
655
+ return callback("The service is no longer running" + closeData.reason, null);
641
656
  let id = nextRequestID++;
642
657
  responseCallbacks.set(id, (error, response) => {
643
658
  try {
@@ -652,8 +667,8 @@ function createChannel(streamIn) {
652
667
  streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
653
668
  };
654
669
  let sendResponse = (id, value) => {
655
- if (isClosed)
656
- throw new Error("The service is no longer running");
670
+ if (closeData)
671
+ throw new Error("The service is no longer running" + closeData.reason);
657
672
  streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
658
673
  };
659
674
  let handleRequest = async (id, request) => {
@@ -724,8 +739,8 @@ function createChannel(streamIn) {
724
739
  if (isFirstPacket) {
725
740
  isFirstPacket = false;
726
741
  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)}`);
742
+ if (binaryVersion !== "0.14.42") {
743
+ throw new Error(`Cannot start service: Host version "${"0.14.42"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
729
744
  }
730
745
  return;
731
746
  }
@@ -1230,7 +1245,7 @@ function createChannel(streamIn) {
1230
1245
  if (!rebuild) {
1231
1246
  let isDisposed = false;
1232
1247
  rebuild = () => new Promise((resolve, reject) => {
1233
- if (isDisposed || isClosed)
1248
+ if (isDisposed || closeData)
1234
1249
  throw new Error("Cannot rebuild");
1235
1250
  sendRequest(refs, { command: "rebuild", key }, (error2, response2) => {
1236
1251
  if (error2) {
@@ -1670,7 +1685,7 @@ function convertOutputFiles({ path, contents }) {
1670
1685
  }
1671
1686
 
1672
1687
  // lib/npm/browser.ts
1673
- var version = "0.14.23";
1688
+ var version = "0.14.42";
1674
1689
  var build = (options) => ensureServiceIsRunning().build(options);
1675
1690
  var serve = () => {
1676
1691
  throw new Error(`The "serve" API only works in node`);
@@ -1702,747 +1717,621 @@ var ensureServiceIsRunning = () => {
1702
1717
  var initialize = (options) => {
1703
1718
  options = validateInitializeOptions(options || {});
1704
1719
  let wasmURL = options.wasmURL;
1720
+ let wasmModule = options.wasmModule;
1705
1721
  let useWorker = options.worker !== false;
1706
- if (!wasmURL)
1707
- throw new Error('Must provide the "wasmURL" option');
1708
- wasmURL += "";
1722
+ if (!wasmURL && !wasmModule)
1723
+ throw new Error('Must provide either the "wasmURL" option or the "wasmModule" option');
1709
1724
  if (initializePromise)
1710
1725
  throw new Error('Cannot call "initialize" more than once');
1711
- initializePromise = startRunningService(wasmURL, useWorker);
1726
+ initializePromise = startRunningService(wasmURL || "", wasmModule, useWorker);
1712
1727
  initializePromise.catch(() => {
1713
1728
  initializePromise = void 0;
1714
1729
  });
1715
1730
  return initializePromise;
1716
1731
  };
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);
1732
+ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
1733
+ let wasm;
1734
+ if (wasmModule) {
1735
+ wasm = wasmModule;
1736
+ } else {
1737
+ let res = await fetch(wasmURL);
1738
+ if (!res.ok)
1739
+ throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1740
+ wasm = await res.arrayBuffer();
1741
+ }
1742
+ let worker;
1743
+ if (useWorker) {
1744
+ 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.42"}`];\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" });
1745
+ worker = new Worker(URL.createObjectURL(blob));
1746
+ } else {
1747
+ let onmessage = ((postMessage) => {
1748
+ // Copyright 2018 The Go Authors. All rights reserved.
1749
+ // Use of this source code is governed by a BSD-style
1750
+ // license that can be found in the LICENSE file.
1751
+ let onmessage;
1752
+ let globalThis = {};
1753
+ for (let o = self; o; o = Object.getPrototypeOf(o))
1754
+ for (let k of Object.getOwnPropertyNames(o))
1755
+ if (!(k in globalThis))
1756
+ Object.defineProperty(globalThis, k, { get: () => self[k] });
1757
+ "use strict";
1758
+ (() => {
1759
+ const enosys = () => {
1760
+ const err = new Error("not implemented");
1761
+ err.code = "ENOSYS";
1762
+ return err;
1763
+ };
1764
+ if (!globalThis.fs) {
1765
+ let outputBuf = "";
1766
+ globalThis.fs = {
1767
+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
1768
+ writeSync(fd, buf) {
1769
+ outputBuf += decoder.decode(buf);
1770
+ const nl = outputBuf.lastIndexOf("\n");
1771
+ if (nl != -1) {
1772
+ console.log(outputBuf.substr(0, nl));
1773
+ outputBuf = outputBuf.substr(nl + 1);
1774
+ }
1775
+ return buf.length;
1776
+ },
1777
+ write(fd, buf, offset, length, position, callback) {
1778
+ if (offset !== 0 || length !== buf.length || position !== null) {
1779
+ callback(enosys());
1780
+ return;
1781
+ }
1782
+ const n = this.writeSync(fd, buf);
1783
+ callback(null, n);
1784
+ },
1785
+ chmod(path, mode, callback) {
1786
+ callback(enosys());
1787
+ },
1788
+ chown(path, uid, gid, callback) {
1789
+ callback(enosys());
1790
+ },
1791
+ close(fd, callback) {
1792
+ callback(enosys());
1793
+ },
1794
+ fchmod(fd, mode, callback) {
1795
+ callback(enosys());
1796
+ },
1797
+ fchown(fd, uid, gid, callback) {
1798
+ callback(enosys());
1799
+ },
1800
+ fstat(fd, callback) {
1801
+ callback(enosys());
1802
+ },
1803
+ fsync(fd, callback) {
1804
+ callback(null);
1805
+ },
1806
+ ftruncate(fd, length, callback) {
1807
+ callback(enosys());
1808
+ },
1809
+ lchown(path, uid, gid, callback) {
1810
+ callback(enosys());
1811
+ },
1812
+ link(path, link, callback) {
1813
+ callback(enosys());
1814
+ },
1815
+ lstat(path, callback) {
1816
+ callback(enosys());
1817
+ },
1818
+ mkdir(path, perm, callback) {
1819
+ callback(enosys());
1820
+ },
1821
+ open(path, flags, mode, callback) {
1822
+ callback(enosys());
1823
+ },
1824
+ read(fd, buffer, offset, length, position, callback) {
1825
+ callback(enosys());
1826
+ },
1827
+ readdir(path, callback) {
1828
+ callback(enosys());
1829
+ },
1830
+ readlink(path, callback) {
1831
+ callback(enosys());
1832
+ },
1833
+ rename(from, to, callback) {
1834
+ callback(enosys());
1835
+ },
1836
+ rmdir(path, callback) {
1837
+ callback(enosys());
1838
+ },
1839
+ stat(path, callback) {
1840
+ callback(enosys());
1841
+ },
1842
+ symlink(path, link, callback) {
1843
+ callback(enosys());
1844
+ },
1845
+ truncate(path, length, callback) {
1846
+ callback(enosys());
1847
+ },
1848
+ unlink(path, callback) {
1849
+ callback(enosys());
1850
+ },
1851
+ utimes(path, atime, mtime, callback) {
1852
+ callback(enosys());
1764
1853
  }
1765
- return;
1854
+ };
1855
+ }
1856
+ if (!globalThis.process) {
1857
+ globalThis.process = {
1858
+ getuid() {
1859
+ return -1;
1860
+ },
1861
+ getgid() {
1862
+ return -1;
1863
+ },
1864
+ geteuid() {
1865
+ return -1;
1866
+ },
1867
+ getegid() {
1868
+ return -1;
1869
+ },
1870
+ getgroups() {
1871
+ throw enosys();
1872
+ },
1873
+ pid: -1,
1874
+ ppid: -1,
1875
+ umask() {
1876
+ throw enosys();
1877
+ },
1878
+ cwd() {
1879
+ throw enosys();
1880
+ },
1881
+ chdir() {
1882
+ throw enosys();
1883
+ }
1884
+ };
1885
+ }
1886
+ if (!globalThis.crypto) {
1887
+ throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
1888
+ }
1889
+ if (!globalThis.performance) {
1890
+ throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
1891
+ }
1892
+ if (!globalThis.TextEncoder) {
1893
+ throw new Error("globalThis.TextEncoder is not available, polyfill required");
1894
+ }
1895
+ if (!globalThis.TextDecoder) {
1896
+ throw new Error("globalThis.TextDecoder is not available, polyfill required");
1897
+ }
1898
+ const encoder = new TextEncoder("utf-8");
1899
+ const decoder = new TextDecoder("utf-8");
1900
+ globalThis.Go = class {
1901
+ constructor() {
1902
+ this.argv = ["js"];
1903
+ this.env = {};
1904
+ this.exit = (code) => {
1905
+ if (code !== 0) {
1906
+ console.warn("exit code:", code);
1907
+ }
1908
+ };
1909
+ this._exitPromise = new Promise((resolve) => {
1910
+ this._resolveExitPromise = resolve;
1911
+ });
1912
+ this._pendingEvent = null;
1913
+ this._scheduledTimeouts = /* @__PURE__ */ new Map();
1914
+ this._nextCallbackTimeoutID = 1;
1915
+ const setInt64 = (addr, v) => {
1916
+ this.mem.setUint32(addr + 0, v, true);
1917
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
1918
+ };
1919
+ const getInt64 = (addr) => {
1920
+ const low = this.mem.getUint32(addr + 0, true);
1921
+ const high = this.mem.getInt32(addr + 4, true);
1922
+ return low + high * 4294967296;
1923
+ };
1924
+ const loadValue = (addr) => {
1925
+ const f = this.mem.getFloat64(addr, true);
1926
+ if (f === 0) {
1927
+ return void 0;
1928
+ }
1929
+ if (!isNaN(f)) {
1930
+ return f;
1931
+ }
1932
+ const id = this.mem.getUint32(addr, true);
1933
+ return this._values[id];
1934
+ };
1935
+ const storeValue = (addr, v) => {
1936
+ const nanHead = 2146959360;
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
+ if (v === void 0) {
1947
+ this.mem.setFloat64(addr, 0, true);
1948
+ return;
1949
+ }
1950
+ let id = this._ids.get(v);
1951
+ if (id === void 0) {
1952
+ id = this._idPool.pop();
1953
+ if (id === void 0) {
1954
+ id = this._values.length;
1955
+ }
1956
+ this._values[id] = v;
1957
+ this._goRefCounts[id] = 0;
1958
+ this._ids.set(v, id);
1959
+ }
1960
+ this._goRefCounts[id]++;
1961
+ let typeFlag = 0;
1962
+ switch (typeof v) {
1963
+ case "object":
1964
+ if (v !== null) {
1965
+ typeFlag = 1;
1966
+ }
1967
+ break;
1968
+ case "string":
1969
+ typeFlag = 2;
1970
+ break;
1971
+ case "symbol":
1972
+ typeFlag = 3;
1973
+ break;
1974
+ case "function":
1975
+ typeFlag = 4;
1976
+ break;
1977
+ }
1978
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
1979
+ this.mem.setUint32(addr, id, true);
1980
+ };
1981
+ const loadSlice = (addr) => {
1982
+ const array = getInt64(addr + 0);
1983
+ const len = getInt64(addr + 8);
1984
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
1985
+ };
1986
+ const loadSliceOfValues = (addr) => {
1987
+ const array = getInt64(addr + 0);
1988
+ const len = getInt64(addr + 8);
1989
+ const a = new Array(len);
1990
+ for (let i = 0; i < len; i++) {
1991
+ a[i] = loadValue(array + i * 8);
1992
+ }
1993
+ return a;
1994
+ };
1995
+ const loadString = (addr) => {
1996
+ const saddr = getInt64(addr + 0);
1997
+ const len = getInt64(addr + 8);
1998
+ return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
1999
+ };
2000
+ const timeOrigin = Date.now() - performance.now();
2001
+ this.importObject = {
2002
+ go: {
2003
+ "runtime.wasmExit": (sp) => {
2004
+ sp >>>= 0;
2005
+ const code = this.mem.getInt32(sp + 8, true);
2006
+ this.exited = true;
2007
+ delete this._inst;
2008
+ delete this._values;
2009
+ delete this._goRefCounts;
2010
+ delete this._ids;
2011
+ delete this._idPool;
2012
+ this.exit(code);
2013
+ },
2014
+ "runtime.wasmWrite": (sp) => {
2015
+ sp >>>= 0;
2016
+ const fd = getInt64(sp + 8);
2017
+ const p = getInt64(sp + 16);
2018
+ const n = this.mem.getInt32(sp + 24, true);
2019
+ globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
2020
+ },
2021
+ "runtime.resetMemoryDataView": (sp) => {
2022
+ sp >>>= 0;
2023
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2024
+ },
2025
+ "runtime.nanotime1": (sp) => {
2026
+ sp >>>= 0;
2027
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
2028
+ },
2029
+ "runtime.walltime": (sp) => {
2030
+ sp >>>= 0;
2031
+ const msec = new Date().getTime();
2032
+ setInt64(sp + 8, msec / 1e3);
2033
+ this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
2034
+ },
2035
+ "runtime.scheduleTimeoutEvent": (sp) => {
2036
+ sp >>>= 0;
2037
+ const id = this._nextCallbackTimeoutID;
2038
+ this._nextCallbackTimeoutID++;
2039
+ this._scheduledTimeouts.set(id, setTimeout(() => {
2040
+ this._resume();
2041
+ while (this._scheduledTimeouts.has(id)) {
2042
+ console.warn("scheduleTimeoutEvent: missed timeout event");
2043
+ this._resume();
2044
+ }
2045
+ }, getInt64(sp + 8) + 1));
2046
+ this.mem.setInt32(sp + 16, id, true);
2047
+ },
2048
+ "runtime.clearTimeoutEvent": (sp) => {
2049
+ sp >>>= 0;
2050
+ const id = this.mem.getInt32(sp + 8, true);
2051
+ clearTimeout(this._scheduledTimeouts.get(id));
2052
+ this._scheduledTimeouts.delete(id);
2053
+ },
2054
+ "runtime.getRandomData": (sp) => {
2055
+ sp >>>= 0;
2056
+ crypto.getRandomValues(loadSlice(sp + 8));
2057
+ },
2058
+ "syscall/js.finalizeRef": (sp) => {
2059
+ sp >>>= 0;
2060
+ const id = this.mem.getUint32(sp + 8, true);
2061
+ this._goRefCounts[id]--;
2062
+ if (this._goRefCounts[id] === 0) {
2063
+ const v = this._values[id];
2064
+ this._values[id] = null;
2065
+ this._ids.delete(v);
2066
+ this._idPool.push(id);
2067
+ }
2068
+ },
2069
+ "syscall/js.stringVal": (sp) => {
2070
+ sp >>>= 0;
2071
+ storeValue(sp + 24, loadString(sp + 8));
2072
+ },
2073
+ "syscall/js.valueGet": (sp) => {
2074
+ sp >>>= 0;
2075
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
2076
+ sp = this._inst.exports.getsp() >>> 0;
2077
+ storeValue(sp + 32, result);
2078
+ },
2079
+ "syscall/js.valueSet": (sp) => {
2080
+ sp >>>= 0;
2081
+ Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
2082
+ },
2083
+ "syscall/js.valueDelete": (sp) => {
2084
+ sp >>>= 0;
2085
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
2086
+ },
2087
+ "syscall/js.valueIndex": (sp) => {
2088
+ sp >>>= 0;
2089
+ storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
2090
+ },
2091
+ "syscall/js.valueSetIndex": (sp) => {
2092
+ sp >>>= 0;
2093
+ Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
2094
+ },
2095
+ "syscall/js.valueCall": (sp) => {
2096
+ sp >>>= 0;
2097
+ try {
2098
+ const v = loadValue(sp + 8);
2099
+ const m = Reflect.get(v, loadString(sp + 16));
2100
+ const args = loadSliceOfValues(sp + 32);
2101
+ const result = Reflect.apply(m, v, args);
2102
+ sp = this._inst.exports.getsp() >>> 0;
2103
+ storeValue(sp + 56, result);
2104
+ this.mem.setUint8(sp + 64, 1);
2105
+ } catch (err) {
2106
+ sp = this._inst.exports.getsp() >>> 0;
2107
+ storeValue(sp + 56, err);
2108
+ this.mem.setUint8(sp + 64, 0);
2109
+ }
2110
+ },
2111
+ "syscall/js.valueInvoke": (sp) => {
2112
+ sp >>>= 0;
2113
+ try {
2114
+ const v = loadValue(sp + 8);
2115
+ const args = loadSliceOfValues(sp + 16);
2116
+ const result = Reflect.apply(v, void 0, args);
2117
+ sp = this._inst.exports.getsp() >>> 0;
2118
+ storeValue(sp + 40, result);
2119
+ this.mem.setUint8(sp + 48, 1);
2120
+ } catch (err) {
2121
+ sp = this._inst.exports.getsp() >>> 0;
2122
+ storeValue(sp + 40, err);
2123
+ this.mem.setUint8(sp + 48, 0);
2124
+ }
2125
+ },
2126
+ "syscall/js.valueNew": (sp) => {
2127
+ sp >>>= 0;
2128
+ try {
2129
+ const v = loadValue(sp + 8);
2130
+ const args = loadSliceOfValues(sp + 16);
2131
+ const result = Reflect.construct(v, args);
2132
+ sp = this._inst.exports.getsp() >>> 0;
2133
+ storeValue(sp + 40, result);
2134
+ this.mem.setUint8(sp + 48, 1);
2135
+ } catch (err) {
2136
+ sp = this._inst.exports.getsp() >>> 0;
2137
+ storeValue(sp + 40, err);
2138
+ this.mem.setUint8(sp + 48, 0);
2139
+ }
2140
+ },
2141
+ "syscall/js.valueLength": (sp) => {
2142
+ sp >>>= 0;
2143
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
2144
+ },
2145
+ "syscall/js.valuePrepareString": (sp) => {
2146
+ sp >>>= 0;
2147
+ const str = encoder.encode(String(loadValue(sp + 8)));
2148
+ storeValue(sp + 16, str);
2149
+ setInt64(sp + 24, str.length);
2150
+ },
2151
+ "syscall/js.valueLoadString": (sp) => {
2152
+ sp >>>= 0;
2153
+ const str = loadValue(sp + 8);
2154
+ loadSlice(sp + 16).set(str);
2155
+ },
2156
+ "syscall/js.valueInstanceOf": (sp) => {
2157
+ sp >>>= 0;
2158
+ this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
2159
+ },
2160
+ "syscall/js.copyBytesToGo": (sp) => {
2161
+ sp >>>= 0;
2162
+ const dst = loadSlice(sp + 8);
2163
+ const src = loadValue(sp + 32);
2164
+ if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
2165
+ this.mem.setUint8(sp + 48, 0);
2166
+ return;
2167
+ }
2168
+ const toCopy = src.subarray(0, dst.length);
2169
+ dst.set(toCopy);
2170
+ setInt64(sp + 40, toCopy.length);
2171
+ this.mem.setUint8(sp + 48, 1);
2172
+ },
2173
+ "syscall/js.copyBytesToJS": (sp) => {
2174
+ sp >>>= 0;
2175
+ const dst = loadValue(sp + 8);
2176
+ const src = loadSlice(sp + 16);
2177
+ if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
2178
+ this.mem.setUint8(sp + 48, 0);
2179
+ return;
2180
+ }
2181
+ const toCopy = src.subarray(0, dst.length);
2182
+ dst.set(toCopy);
2183
+ setInt64(sp + 40, toCopy.length);
2184
+ this.mem.setUint8(sp + 48, 1);
2185
+ },
2186
+ "debug": (value) => {
2187
+ console.log(value);
2188
+ }
2189
+ }
2190
+ };
1766
2191
  }
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);
2192
+ async run(instance) {
2193
+ if (!(instance instanceof WebAssembly.Instance)) {
2194
+ throw new Error("Go.run: WebAssembly.Instance expected");
2195
+ }
2196
+ this._inst = instance;
2197
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2198
+ this._values = [
2199
+ NaN,
2200
+ 0,
2201
+ null,
2202
+ true,
2203
+ false,
2204
+ globalThis,
2205
+ this
2206
+ ];
2207
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
2208
+ this._ids = /* @__PURE__ */ new Map([
2209
+ [0, 1],
2210
+ [null, 2],
2211
+ [true, 3],
2212
+ [false, 4],
2213
+ [globalThis, 5],
2214
+ [this, 6]
2215
+ ]);
2216
+ this._idPool = [];
2217
+ this.exited = false;
2218
+ let offset = 4096;
2219
+ const strPtr = (str) => {
2220
+ const ptr = offset;
2221
+ const bytes = encoder.encode(str + "\0");
2222
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
2223
+ offset += bytes.length;
2224
+ if (offset % 8 !== 0) {
2225
+ offset += 8 - offset % 8;
2226
+ }
2227
+ return ptr;
2228
+ };
2229
+ const argc = this.argv.length;
2230
+ const argvPtrs = [];
2231
+ this.argv.forEach((arg) => {
2232
+ argvPtrs.push(strPtr(arg));
2233
+ });
2234
+ argvPtrs.push(0);
2235
+ const keys = Object.keys(this.env).sort();
2236
+ keys.forEach((key) => {
2237
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
2238
+ });
2239
+ argvPtrs.push(0);
2240
+ const argv = offset;
2241
+ argvPtrs.forEach((ptr) => {
2242
+ this.mem.setUint32(offset, ptr, true);
2243
+ this.mem.setUint32(offset + 4, 0, true);
2244
+ offset += 8;
2245
+ });
2246
+ const wasmMinDataAddr = 4096 + 8192;
2247
+ if (offset >= wasmMinDataAddr) {
2248
+ throw new Error("total length of command line and environment variables exceeds limit");
2249
+ }
2250
+ this._inst.exports.run(argc, argv);
2251
+ if (this.exited) {
2252
+ this._resolveExitPromise();
2253
+ }
2254
+ await this._exitPromise;
2255
+ }
2256
+ _resume() {
2257
+ if (this.exited) {
2258
+ throw new Error("Go program has already exited");
1772
2259
  }
2260
+ this._inst.exports.resume();
2261
+ if (this.exited) {
2262
+ this._resolveExitPromise();
2263
+ }
2264
+ }
2265
+ _makeFuncWrapper(id) {
2266
+ const go = this;
2267
+ return function() {
2268
+ const event = { id, this: this, args: arguments };
2269
+ go._pendingEvent = event;
2270
+ go._resume();
2271
+ return event.result;
2272
+ };
2273
+ }
2274
+ };
2275
+ })();
2276
+ onmessage = ({ data: wasm }) => {
2277
+ let decoder = new TextDecoder();
2278
+ let fs = globalThis.fs;
2279
+ let stderr = "";
2280
+ fs.writeSync = (fd, buffer) => {
2281
+ if (fd === 1) {
2282
+ postMessage(buffer);
2283
+ } else if (fd === 2) {
2284
+ stderr += decoder.decode(buffer);
2285
+ let parts = stderr.split("\n");
2286
+ if (parts.length > 1)
2287
+ console.log(parts.slice(0, -1).join("\n"));
2288
+ stderr = parts[parts.length - 1];
2289
+ } else {
2290
+ throw new Error("Bad write");
2291
+ }
2292
+ return buffer.length;
2293
+ };
2294
+ let stdin = [];
2295
+ let resumeStdin;
2296
+ let stdinPos = 0;
2297
+ onmessage = ({ data }) => {
2298
+ if (data.length > 0) {
2299
+ stdin.push(data);
2300
+ if (resumeStdin)
2301
+ resumeStdin();
2302
+ }
2303
+ };
2304
+ fs.read = (fd, buffer, offset, length, position, callback) => {
2305
+ if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {
2306
+ throw new Error("Bad read");
2307
+ }
2308
+ if (stdin.length === 0) {
2309
+ resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);
1773
2310
  return;
1774
2311
  }
2312
+ let first = stdin[0];
2313
+ let count = Math.max(0, Math.min(length, first.length - stdinPos));
2314
+ buffer.set(first.subarray(stdinPos, stdinPos + count), offset);
2315
+ stdinPos += count;
2316
+ if (stdinPos === first.length) {
2317
+ stdin.shift();
2318
+ stdinPos = 0;
2319
+ }
2320
+ callback(null, count);
2321
+ };
2322
+ let go = new globalThis.Go();
2323
+ go.argv = ["", `--service=${"0.14.42"}`];
2324
+ if (wasm instanceof WebAssembly.Module) {
2325
+ WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2326
+ } else {
2327
+ WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
1775
2328
  }
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 }));
2329
+ };
2330
+ return (m) => onmessage(m);
2331
+ })((data) => worker.onmessage({ data }));
2443
2332
  worker = {
2444
2333
  onmessage: null,
2445
- postMessage: (data) => onmessage({ data }),
2334
+ postMessage: (data) => setTimeout(() => onmessage({ data })),
2446
2335
  terminate() {
2447
2336
  }
2448
2337
  };
@@ -2465,7 +2354,7 @@ onmessage = ({ data: wasm }) => {
2465
2354
  options,
2466
2355
  isTTY: false,
2467
2356
  defaultWD: "/",
2468
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2357
+ callback: (err, res) => err ? reject(err) : resolve(res)
2469
2358
  })),
2470
2359
  transform: (input, options) => new Promise((resolve, reject) => service.transform({
2471
2360
  callName: "transform",
@@ -2481,21 +2370,21 @@ onmessage = ({ data: wasm }) => {
2481
2370
  callback(null);
2482
2371
  }
2483
2372
  },
2484
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2373
+ callback: (err, res) => err ? reject(err) : resolve(res)
2485
2374
  })),
2486
2375
  formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
2487
2376
  callName: "formatMessages",
2488
2377
  refs: null,
2489
2378
  messages,
2490
2379
  options,
2491
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2380
+ callback: (err, res) => err ? reject(err) : resolve(res)
2492
2381
  })),
2493
2382
  analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
2494
2383
  callName: "analyzeMetafile",
2495
2384
  refs: null,
2496
2385
  metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
2497
2386
  options,
2498
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2387
+ callback: (err, res) => err ? reject(err) : resolve(res)
2499
2388
  }))
2500
2389
  };
2501
2390
  };