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.
@@ -20,24 +20,19 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
24
23
  var __export = (target, all) => {
25
24
  for (var name in all)
26
25
  __defProp(target, name, { get: all[name], enumerable: true });
27
26
  };
28
- var __reExport = (target, module2, copyDefault, desc) => {
29
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
30
- for (let key of __getOwnPropNames(module2))
31
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
32
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
32
  }
34
- return target;
33
+ return to;
35
34
  };
36
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
37
- return (module2, temp) => {
38
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
39
- };
40
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
36
  var __async = (__this, __arguments, generator) => {
42
37
  return new Promise((resolve, reject) => {
43
38
  var fulfilled = (value) => {
@@ -75,6 +70,7 @@ __export(browser_exports, {
75
70
  transformSync: () => transformSync,
76
71
  version: () => version
77
72
  });
73
+ module.exports = __toCommonJS(browser_exports);
78
74
 
79
75
  // lib/shared/stdio_protocol.ts
80
76
  function encodePacket(packet) {
@@ -256,6 +252,7 @@ var mustBeInteger = (value) => typeof value === "number" && value === (value | 0
256
252
  var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
257
253
  var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
258
254
  var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
255
+ var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
259
256
  var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
260
257
  var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
261
258
  var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
@@ -282,10 +279,12 @@ function checkForInvalidFlags(object, keys, where) {
282
279
  function validateInitializeOptions(options) {
283
280
  let keys = /* @__PURE__ */ Object.create(null);
284
281
  let wasmURL = getFlag(options, keys, "wasmURL", mustBeString);
282
+ let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
285
283
  let worker = getFlag(options, keys, "worker", mustBeBoolean);
286
- checkForInvalidFlags(options, keys, "in startService() call");
284
+ checkForInvalidFlags(options, keys, "in initialize() call");
287
285
  return {
288
286
  wasmURL,
287
+ wasmModule,
289
288
  worker
290
289
  };
291
290
  }
@@ -324,6 +323,7 @@ function pushCommonFlags(flags, options, keys) {
324
323
  let globalName = getFlag(options, keys, "globalName", mustBeString);
325
324
  let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
326
325
  let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
326
+ let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
327
327
  let minify = getFlag(options, keys, "minify", mustBeBoolean);
328
328
  let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
329
329
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
@@ -336,6 +336,7 @@ function pushCommonFlags(flags, options, keys) {
336
336
  let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
337
337
  let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
338
338
  let define = getFlag(options, keys, "define", mustBeObject);
339
+ let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
339
340
  let pure = getFlag(options, keys, "pure", mustBeArray);
340
341
  let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
341
342
  if (legalComments)
@@ -375,6 +376,8 @@ function pushCommonFlags(flags, options, keys) {
375
376
  flags.push(`--mangle-props=${mangleProps.source}`);
376
377
  if (reserveProps)
377
378
  flags.push(`--reserve-props=${reserveProps.source}`);
379
+ if (mangleQuoted !== void 0)
380
+ flags.push(`--mangle-quoted=${mangleQuoted}`);
378
381
  if (jsx)
379
382
  flags.push(`--jsx=${jsx}`);
380
383
  if (jsxFactory)
@@ -388,6 +391,13 @@ function pushCommonFlags(flags, options, keys) {
388
391
  flags.push(`--define:${key}=${define[key]}`);
389
392
  }
390
393
  }
394
+ if (logOverride) {
395
+ for (let key in logOverride) {
396
+ if (key.indexOf("=") >= 0)
397
+ throw new Error(`Invalid log override: ${key}`);
398
+ flags.push(`--log-override:${key}=${logOverride[key]}`);
399
+ }
400
+ }
391
401
  if (pure)
392
402
  for (let fn of pure)
393
403
  flags.push(`--pure:${fn}`);
@@ -624,7 +634,7 @@ function createChannel(streamIn) {
624
634
  let pluginCallbacks = /* @__PURE__ */ new Map();
625
635
  let watchCallbacks = /* @__PURE__ */ new Map();
626
636
  let serveCallbacks = /* @__PURE__ */ new Map();
627
- let isClosed = false;
637
+ let closeData = null;
628
638
  let nextRequestID = 0;
629
639
  let nextBuildKey = 0;
630
640
  let stdout = new Uint8Array(16 * 1024);
@@ -653,19 +663,20 @@ function createChannel(streamIn) {
653
663
  stdoutUsed -= offset;
654
664
  }
655
665
  };
656
- let afterClose = () => {
657
- isClosed = true;
666
+ let afterClose = (error) => {
667
+ closeData = { reason: error ? ": " + (error.message || error) : "" };
668
+ const text = "The service was stopped" + closeData.reason;
658
669
  for (let callback of responseCallbacks.values()) {
659
- callback("The service was stopped", null);
670
+ callback(text, null);
660
671
  }
661
672
  responseCallbacks.clear();
662
673
  for (let callbacks of serveCallbacks.values()) {
663
- callbacks.onWait("The service was stopped");
674
+ callbacks.onWait(text);
664
675
  }
665
676
  serveCallbacks.clear();
666
677
  for (let callback of watchCallbacks.values()) {
667
678
  try {
668
- callback(new Error("The service was stopped"), null);
679
+ callback(new Error(text), null);
669
680
  } catch (e) {
670
681
  console.error(e);
671
682
  }
@@ -673,8 +684,8 @@ function createChannel(streamIn) {
673
684
  watchCallbacks.clear();
674
685
  };
675
686
  let sendRequest = (refs, value, callback) => {
676
- if (isClosed)
677
- return callback("The service is no longer running", null);
687
+ if (closeData)
688
+ return callback("The service is no longer running" + closeData.reason, null);
678
689
  let id = nextRequestID++;
679
690
  responseCallbacks.set(id, (error, response) => {
680
691
  try {
@@ -689,8 +700,8 @@ function createChannel(streamIn) {
689
700
  streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
690
701
  };
691
702
  let sendResponse = (id, value) => {
692
- if (isClosed)
693
- throw new Error("The service is no longer running");
703
+ if (closeData)
704
+ throw new Error("The service is no longer running" + closeData.reason);
694
705
  streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
695
706
  };
696
707
  let handleRequest = (id, request) => __async(this, null, function* () {
@@ -761,8 +772,8 @@ function createChannel(streamIn) {
761
772
  if (isFirstPacket) {
762
773
  isFirstPacket = false;
763
774
  let binaryVersion = String.fromCharCode(...bytes);
764
- if (binaryVersion !== "0.14.23") {
765
- throw new Error(`Cannot start service: Host version "${"0.14.23"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
775
+ if (binaryVersion !== "0.14.42") {
776
+ throw new Error(`Cannot start service: Host version "${"0.14.42"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
766
777
  }
767
778
  return;
768
779
  }
@@ -1267,7 +1278,7 @@ function createChannel(streamIn) {
1267
1278
  if (!rebuild) {
1268
1279
  let isDisposed = false;
1269
1280
  rebuild = () => new Promise((resolve, reject) => {
1270
- if (isDisposed || isClosed)
1281
+ if (isDisposed || closeData)
1271
1282
  throw new Error("Cannot rebuild");
1272
1283
  sendRequest(refs, { command: "rebuild", key }, (error2, response2) => {
1273
1284
  if (error2) {
@@ -1707,7 +1718,7 @@ function convertOutputFiles({ path, contents }) {
1707
1718
  }
1708
1719
 
1709
1720
  // lib/npm/browser.ts
1710
- var version = "0.14.23";
1721
+ var version = "0.14.42";
1711
1722
  var build = (options) => ensureServiceIsRunning().build(options);
1712
1723
  var serve = () => {
1713
1724
  throw new Error(`The "serve" API only works in node`);
@@ -1739,747 +1750,643 @@ var ensureServiceIsRunning = () => {
1739
1750
  var initialize = (options) => {
1740
1751
  options = validateInitializeOptions(options || {});
1741
1752
  let wasmURL = options.wasmURL;
1753
+ let wasmModule = options.wasmModule;
1742
1754
  let useWorker = options.worker !== false;
1743
- if (!wasmURL)
1744
- throw new Error('Must provide the "wasmURL" option');
1745
- wasmURL += "";
1755
+ if (!wasmURL && !wasmModule)
1756
+ throw new Error('Must provide either the "wasmURL" option or the "wasmModule" option');
1746
1757
  if (initializePromise)
1747
1758
  throw new Error('Cannot call "initialize" more than once');
1748
- initializePromise = startRunningService(wasmURL, useWorker);
1759
+ initializePromise = startRunningService(wasmURL || "", wasmModule, useWorker);
1749
1760
  initializePromise.catch(() => {
1750
1761
  initializePromise = void 0;
1751
1762
  });
1752
1763
  return initializePromise;
1753
1764
  };
1754
- var startRunningService = (wasmURL, useWorker) => __async(void 0, null, function* () {
1755
- let res = yield fetch(wasmURL);
1756
- if (!res.ok)
1757
- throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1758
- let wasm = yield res.arrayBuffer();
1759
- 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.
1760
- // Use of this source code is governed by a BSD-style
1761
- // license that can be found in the LICENSE file.
1762
-
1763
- (() => {
1764
- // Map multiple JavaScript environments to a single common API,
1765
- // preferring web standards over Node.js API.
1766
- //
1767
- // Environments considered:
1768
- // - Browsers
1769
- // - Node.js
1770
- // - Electron
1771
- // - Parcel
1772
- // - Webpack
1773
-
1774
- if (typeof global !== "undefined") {
1775
- // global already exists
1776
- } else if (typeof window !== "undefined") {
1777
- window.global = window;
1778
- } else if (typeof self !== "undefined") {
1779
- self.global = self;
1780
- } else {
1781
- throw new Error("cannot export Go (neither global, window nor self is defined)");
1782
- }
1783
-
1784
- if (!global.require && typeof require !== "undefined") {
1785
- global.require = require;
1786
- }
1787
-
1788
- if (!global.fs && global.require) {
1789
- const fs = require("fs");
1790
- if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
1791
-
1792
- global.fs = Object.assign({}, fs, {
1793
- // Hack around a Unicode bug in node: https://github.com/nodejs/node/issues/24550
1794
- write(fd, buf, offset, length, position, callback) {
1795
- if (offset === 0 && length === buf.length && position === null) {
1796
- if (fd === process.stdout.fd) {
1765
+ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, null, function* () {
1766
+ let wasm;
1767
+ if (wasmModule) {
1768
+ wasm = wasmModule;
1769
+ } else {
1770
+ let res = yield fetch(wasmURL);
1771
+ if (!res.ok)
1772
+ throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1773
+ wasm = yield res.arrayBuffer();
1774
+ }
1775
+ let worker;
1776
+ if (useWorker) {
1777
+ 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 var __async = (__this, __arguments, generator) => {\n return new Promise((resolve, reject) => {\n var fulfilled = (value) => {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n };\n var rejected = (value) => {\n try {\n step(generator.throw(value));\n } catch (e) {\n reject(e);\n }\n };\n var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n step((generator = generator.apply(__this, __arguments)).next());\n });\n };\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 run(instance) {\n return __async(this, null, function* () {\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 yield this._exitPromise;\n });\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" });
1778
+ worker = new Worker(URL.createObjectURL(blob));
1779
+ } else {
1780
+ let onmessage = ((postMessage) => {
1781
+ // Copyright 2018 The Go Authors. All rights reserved.
1782
+ // Use of this source code is governed by a BSD-style
1783
+ // license that can be found in the LICENSE file.
1784
+ var __async = (__this, __arguments, generator) => {
1785
+ return new Promise((resolve, reject) => {
1786
+ var fulfilled = (value) => {
1797
1787
  try {
1798
- process.stdout.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf));
1799
- } catch (err) {
1800
- callback(err, 0, null);
1788
+ step(generator.next(value));
1789
+ } catch (e) {
1790
+ reject(e);
1801
1791
  }
1802
- return;
1803
- }
1804
- if (fd === process.stderr.fd) {
1792
+ };
1793
+ var rejected = (value) => {
1805
1794
  try {
1806
- process.stderr.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf));
1807
- } catch (err) {
1808
- callback(err, 0, null);
1795
+ step(generator.throw(value));
1796
+ } catch (e) {
1797
+ reject(e);
1798
+ }
1799
+ };
1800
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1801
+ step((generator = generator.apply(__this, __arguments)).next());
1802
+ });
1803
+ };
1804
+ let onmessage;
1805
+ let globalThis = {};
1806
+ for (let o = self; o; o = Object.getPrototypeOf(o))
1807
+ for (let k of Object.getOwnPropertyNames(o))
1808
+ if (!(k in globalThis))
1809
+ Object.defineProperty(globalThis, k, { get: () => self[k] });
1810
+ "use strict";
1811
+ (() => {
1812
+ const enosys = () => {
1813
+ const err = new Error("not implemented");
1814
+ err.code = "ENOSYS";
1815
+ return err;
1816
+ };
1817
+ if (!globalThis.fs) {
1818
+ let outputBuf = "";
1819
+ globalThis.fs = {
1820
+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
1821
+ writeSync(fd, buf) {
1822
+ outputBuf += decoder.decode(buf);
1823
+ const nl = outputBuf.lastIndexOf("\n");
1824
+ if (nl != -1) {
1825
+ console.log(outputBuf.substr(0, nl));
1826
+ outputBuf = outputBuf.substr(nl + 1);
1827
+ }
1828
+ return buf.length;
1829
+ },
1830
+ write(fd, buf, offset, length, position, callback) {
1831
+ if (offset !== 0 || length !== buf.length || position !== null) {
1832
+ callback(enosys());
1833
+ return;
1834
+ }
1835
+ const n = this.writeSync(fd, buf);
1836
+ callback(null, n);
1837
+ },
1838
+ chmod(path, mode, callback) {
1839
+ callback(enosys());
1840
+ },
1841
+ chown(path, uid, gid, callback) {
1842
+ callback(enosys());
1843
+ },
1844
+ close(fd, callback) {
1845
+ callback(enosys());
1846
+ },
1847
+ fchmod(fd, mode, callback) {
1848
+ callback(enosys());
1849
+ },
1850
+ fchown(fd, uid, gid, callback) {
1851
+ callback(enosys());
1852
+ },
1853
+ fstat(fd, callback) {
1854
+ callback(enosys());
1855
+ },
1856
+ fsync(fd, callback) {
1857
+ callback(null);
1858
+ },
1859
+ ftruncate(fd, length, callback) {
1860
+ callback(enosys());
1861
+ },
1862
+ lchown(path, uid, gid, callback) {
1863
+ callback(enosys());
1864
+ },
1865
+ link(path, link, callback) {
1866
+ callback(enosys());
1867
+ },
1868
+ lstat(path, callback) {
1869
+ callback(enosys());
1870
+ },
1871
+ mkdir(path, perm, callback) {
1872
+ callback(enosys());
1873
+ },
1874
+ open(path, flags, mode, callback) {
1875
+ callback(enosys());
1876
+ },
1877
+ read(fd, buffer, offset, length, position, callback) {
1878
+ callback(enosys());
1879
+ },
1880
+ readdir(path, callback) {
1881
+ callback(enosys());
1882
+ },
1883
+ readlink(path, callback) {
1884
+ callback(enosys());
1885
+ },
1886
+ rename(from, to, callback) {
1887
+ callback(enosys());
1888
+ },
1889
+ rmdir(path, callback) {
1890
+ callback(enosys());
1891
+ },
1892
+ stat(path, callback) {
1893
+ callback(enosys());
1894
+ },
1895
+ symlink(path, link, callback) {
1896
+ callback(enosys());
1897
+ },
1898
+ truncate(path, length, callback) {
1899
+ callback(enosys());
1900
+ },
1901
+ unlink(path, callback) {
1902
+ callback(enosys());
1903
+ },
1904
+ utimes(path, atime, mtime, callback) {
1905
+ callback(enosys());
1906
+ }
1907
+ };
1908
+ }
1909
+ if (!globalThis.process) {
1910
+ globalThis.process = {
1911
+ getuid() {
1912
+ return -1;
1913
+ },
1914
+ getgid() {
1915
+ return -1;
1916
+ },
1917
+ geteuid() {
1918
+ return -1;
1919
+ },
1920
+ getegid() {
1921
+ return -1;
1922
+ },
1923
+ getgroups() {
1924
+ throw enosys();
1925
+ },
1926
+ pid: -1,
1927
+ ppid: -1,
1928
+ umask() {
1929
+ throw enosys();
1930
+ },
1931
+ cwd() {
1932
+ throw enosys();
1933
+ },
1934
+ chdir() {
1935
+ throw enosys();
1936
+ }
1937
+ };
1938
+ }
1939
+ if (!globalThis.crypto) {
1940
+ throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
1941
+ }
1942
+ if (!globalThis.performance) {
1943
+ throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
1944
+ }
1945
+ if (!globalThis.TextEncoder) {
1946
+ throw new Error("globalThis.TextEncoder is not available, polyfill required");
1947
+ }
1948
+ if (!globalThis.TextDecoder) {
1949
+ throw new Error("globalThis.TextDecoder is not available, polyfill required");
1950
+ }
1951
+ const encoder = new TextEncoder("utf-8");
1952
+ const decoder = new TextDecoder("utf-8");
1953
+ globalThis.Go = class {
1954
+ constructor() {
1955
+ this.argv = ["js"];
1956
+ this.env = {};
1957
+ this.exit = (code) => {
1958
+ if (code !== 0) {
1959
+ console.warn("exit code:", code);
1960
+ }
1961
+ };
1962
+ this._exitPromise = new Promise((resolve) => {
1963
+ this._resolveExitPromise = resolve;
1964
+ });
1965
+ this._pendingEvent = null;
1966
+ this._scheduledTimeouts = /* @__PURE__ */ new Map();
1967
+ this._nextCallbackTimeoutID = 1;
1968
+ const setInt64 = (addr, v) => {
1969
+ this.mem.setUint32(addr + 0, v, true);
1970
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
1971
+ };
1972
+ const getInt64 = (addr) => {
1973
+ const low = this.mem.getUint32(addr + 0, true);
1974
+ const high = this.mem.getInt32(addr + 4, true);
1975
+ return low + high * 4294967296;
1976
+ };
1977
+ const loadValue = (addr) => {
1978
+ const f = this.mem.getFloat64(addr, true);
1979
+ if (f === 0) {
1980
+ return void 0;
1981
+ }
1982
+ if (!isNaN(f)) {
1983
+ return f;
1984
+ }
1985
+ const id = this.mem.getUint32(addr, true);
1986
+ return this._values[id];
1987
+ };
1988
+ const storeValue = (addr, v) => {
1989
+ const nanHead = 2146959360;
1990
+ if (typeof v === "number" && v !== 0) {
1991
+ if (isNaN(v)) {
1992
+ this.mem.setUint32(addr + 4, nanHead, true);
1993
+ this.mem.setUint32(addr, 0, true);
1994
+ return;
1995
+ }
1996
+ this.mem.setFloat64(addr, v, true);
1997
+ return;
1998
+ }
1999
+ if (v === void 0) {
2000
+ this.mem.setFloat64(addr, 0, true);
2001
+ return;
2002
+ }
2003
+ let id = this._ids.get(v);
2004
+ if (id === void 0) {
2005
+ id = this._idPool.pop();
2006
+ if (id === void 0) {
2007
+ id = this._values.length;
2008
+ }
2009
+ this._values[id] = v;
2010
+ this._goRefCounts[id] = 0;
2011
+ this._ids.set(v, id);
2012
+ }
2013
+ this._goRefCounts[id]++;
2014
+ let typeFlag = 0;
2015
+ switch (typeof v) {
2016
+ case "object":
2017
+ if (v !== null) {
2018
+ typeFlag = 1;
2019
+ }
2020
+ break;
2021
+ case "string":
2022
+ typeFlag = 2;
2023
+ break;
2024
+ case "symbol":
2025
+ typeFlag = 3;
2026
+ break;
2027
+ case "function":
2028
+ typeFlag = 4;
2029
+ break;
2030
+ }
2031
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
2032
+ this.mem.setUint32(addr, id, true);
2033
+ };
2034
+ const loadSlice = (addr) => {
2035
+ const array = getInt64(addr + 0);
2036
+ const len = getInt64(addr + 8);
2037
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
2038
+ };
2039
+ const loadSliceOfValues = (addr) => {
2040
+ const array = getInt64(addr + 0);
2041
+ const len = getInt64(addr + 8);
2042
+ const a = new Array(len);
2043
+ for (let i = 0; i < len; i++) {
2044
+ a[i] = loadValue(array + i * 8);
2045
+ }
2046
+ return a;
2047
+ };
2048
+ const loadString = (addr) => {
2049
+ const saddr = getInt64(addr + 0);
2050
+ const len = getInt64(addr + 8);
2051
+ return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
2052
+ };
2053
+ const timeOrigin = Date.now() - performance.now();
2054
+ this.importObject = {
2055
+ go: {
2056
+ "runtime.wasmExit": (sp) => {
2057
+ sp >>>= 0;
2058
+ const code = this.mem.getInt32(sp + 8, true);
2059
+ this.exited = true;
2060
+ delete this._inst;
2061
+ delete this._values;
2062
+ delete this._goRefCounts;
2063
+ delete this._ids;
2064
+ delete this._idPool;
2065
+ this.exit(code);
2066
+ },
2067
+ "runtime.wasmWrite": (sp) => {
2068
+ sp >>>= 0;
2069
+ const fd = getInt64(sp + 8);
2070
+ const p = getInt64(sp + 16);
2071
+ const n = this.mem.getInt32(sp + 24, true);
2072
+ globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
2073
+ },
2074
+ "runtime.resetMemoryDataView": (sp) => {
2075
+ sp >>>= 0;
2076
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2077
+ },
2078
+ "runtime.nanotime1": (sp) => {
2079
+ sp >>>= 0;
2080
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
2081
+ },
2082
+ "runtime.walltime": (sp) => {
2083
+ sp >>>= 0;
2084
+ const msec = new Date().getTime();
2085
+ setInt64(sp + 8, msec / 1e3);
2086
+ this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
2087
+ },
2088
+ "runtime.scheduleTimeoutEvent": (sp) => {
2089
+ sp >>>= 0;
2090
+ const id = this._nextCallbackTimeoutID;
2091
+ this._nextCallbackTimeoutID++;
2092
+ this._scheduledTimeouts.set(id, setTimeout(() => {
2093
+ this._resume();
2094
+ while (this._scheduledTimeouts.has(id)) {
2095
+ console.warn("scheduleTimeoutEvent: missed timeout event");
2096
+ this._resume();
2097
+ }
2098
+ }, getInt64(sp + 8) + 1));
2099
+ this.mem.setInt32(sp + 16, id, true);
2100
+ },
2101
+ "runtime.clearTimeoutEvent": (sp) => {
2102
+ sp >>>= 0;
2103
+ const id = this.mem.getInt32(sp + 8, true);
2104
+ clearTimeout(this._scheduledTimeouts.get(id));
2105
+ this._scheduledTimeouts.delete(id);
2106
+ },
2107
+ "runtime.getRandomData": (sp) => {
2108
+ sp >>>= 0;
2109
+ crypto.getRandomValues(loadSlice(sp + 8));
2110
+ },
2111
+ "syscall/js.finalizeRef": (sp) => {
2112
+ sp >>>= 0;
2113
+ const id = this.mem.getUint32(sp + 8, true);
2114
+ this._goRefCounts[id]--;
2115
+ if (this._goRefCounts[id] === 0) {
2116
+ const v = this._values[id];
2117
+ this._values[id] = null;
2118
+ this._ids.delete(v);
2119
+ this._idPool.push(id);
2120
+ }
2121
+ },
2122
+ "syscall/js.stringVal": (sp) => {
2123
+ sp >>>= 0;
2124
+ storeValue(sp + 24, loadString(sp + 8));
2125
+ },
2126
+ "syscall/js.valueGet": (sp) => {
2127
+ sp >>>= 0;
2128
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
2129
+ sp = this._inst.exports.getsp() >>> 0;
2130
+ storeValue(sp + 32, result);
2131
+ },
2132
+ "syscall/js.valueSet": (sp) => {
2133
+ sp >>>= 0;
2134
+ Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
2135
+ },
2136
+ "syscall/js.valueDelete": (sp) => {
2137
+ sp >>>= 0;
2138
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
2139
+ },
2140
+ "syscall/js.valueIndex": (sp) => {
2141
+ sp >>>= 0;
2142
+ storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
2143
+ },
2144
+ "syscall/js.valueSetIndex": (sp) => {
2145
+ sp >>>= 0;
2146
+ Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
2147
+ },
2148
+ "syscall/js.valueCall": (sp) => {
2149
+ sp >>>= 0;
2150
+ try {
2151
+ const v = loadValue(sp + 8);
2152
+ const m = Reflect.get(v, loadString(sp + 16));
2153
+ const args = loadSliceOfValues(sp + 32);
2154
+ const result = Reflect.apply(m, v, args);
2155
+ sp = this._inst.exports.getsp() >>> 0;
2156
+ storeValue(sp + 56, result);
2157
+ this.mem.setUint8(sp + 64, 1);
2158
+ } catch (err) {
2159
+ sp = this._inst.exports.getsp() >>> 0;
2160
+ storeValue(sp + 56, err);
2161
+ this.mem.setUint8(sp + 64, 0);
2162
+ }
2163
+ },
2164
+ "syscall/js.valueInvoke": (sp) => {
2165
+ sp >>>= 0;
2166
+ try {
2167
+ const v = loadValue(sp + 8);
2168
+ const args = loadSliceOfValues(sp + 16);
2169
+ const result = Reflect.apply(v, void 0, args);
2170
+ sp = this._inst.exports.getsp() >>> 0;
2171
+ storeValue(sp + 40, result);
2172
+ this.mem.setUint8(sp + 48, 1);
2173
+ } catch (err) {
2174
+ sp = this._inst.exports.getsp() >>> 0;
2175
+ storeValue(sp + 40, err);
2176
+ this.mem.setUint8(sp + 48, 0);
2177
+ }
2178
+ },
2179
+ "syscall/js.valueNew": (sp) => {
2180
+ sp >>>= 0;
2181
+ try {
2182
+ const v = loadValue(sp + 8);
2183
+ const args = loadSliceOfValues(sp + 16);
2184
+ const result = Reflect.construct(v, args);
2185
+ sp = this._inst.exports.getsp() >>> 0;
2186
+ storeValue(sp + 40, result);
2187
+ this.mem.setUint8(sp + 48, 1);
2188
+ } catch (err) {
2189
+ sp = this._inst.exports.getsp() >>> 0;
2190
+ storeValue(sp + 40, err);
2191
+ this.mem.setUint8(sp + 48, 0);
2192
+ }
2193
+ },
2194
+ "syscall/js.valueLength": (sp) => {
2195
+ sp >>>= 0;
2196
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
2197
+ },
2198
+ "syscall/js.valuePrepareString": (sp) => {
2199
+ sp >>>= 0;
2200
+ const str = encoder.encode(String(loadValue(sp + 8)));
2201
+ storeValue(sp + 16, str);
2202
+ setInt64(sp + 24, str.length);
2203
+ },
2204
+ "syscall/js.valueLoadString": (sp) => {
2205
+ sp >>>= 0;
2206
+ const str = loadValue(sp + 8);
2207
+ loadSlice(sp + 16).set(str);
2208
+ },
2209
+ "syscall/js.valueInstanceOf": (sp) => {
2210
+ sp >>>= 0;
2211
+ this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
2212
+ },
2213
+ "syscall/js.copyBytesToGo": (sp) => {
2214
+ sp >>>= 0;
2215
+ const dst = loadSlice(sp + 8);
2216
+ const src = loadValue(sp + 32);
2217
+ if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
2218
+ this.mem.setUint8(sp + 48, 0);
2219
+ return;
2220
+ }
2221
+ const toCopy = src.subarray(0, dst.length);
2222
+ dst.set(toCopy);
2223
+ setInt64(sp + 40, toCopy.length);
2224
+ this.mem.setUint8(sp + 48, 1);
2225
+ },
2226
+ "syscall/js.copyBytesToJS": (sp) => {
2227
+ sp >>>= 0;
2228
+ const dst = loadValue(sp + 8);
2229
+ const src = loadSlice(sp + 16);
2230
+ if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
2231
+ this.mem.setUint8(sp + 48, 0);
2232
+ return;
2233
+ }
2234
+ const toCopy = src.subarray(0, dst.length);
2235
+ dst.set(toCopy);
2236
+ setInt64(sp + 40, toCopy.length);
2237
+ this.mem.setUint8(sp + 48, 1);
2238
+ },
2239
+ "debug": (value) => {
2240
+ console.log(value);
2241
+ }
2242
+ }
2243
+ };
2244
+ }
2245
+ run(instance) {
2246
+ return __async(this, null, function* () {
2247
+ if (!(instance instanceof WebAssembly.Instance)) {
2248
+ throw new Error("Go.run: WebAssembly.Instance expected");
2249
+ }
2250
+ this._inst = instance;
2251
+ this.mem = new DataView(this._inst.exports.mem.buffer);
2252
+ this._values = [
2253
+ NaN,
2254
+ 0,
2255
+ null,
2256
+ true,
2257
+ false,
2258
+ globalThis,
2259
+ this
2260
+ ];
2261
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
2262
+ this._ids = /* @__PURE__ */ new Map([
2263
+ [0, 1],
2264
+ [null, 2],
2265
+ [true, 3],
2266
+ [false, 4],
2267
+ [globalThis, 5],
2268
+ [this, 6]
2269
+ ]);
2270
+ this._idPool = [];
2271
+ this.exited = false;
2272
+ let offset = 4096;
2273
+ const strPtr = (str) => {
2274
+ const ptr = offset;
2275
+ const bytes = encoder.encode(str + "\0");
2276
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
2277
+ offset += bytes.length;
2278
+ if (offset % 8 !== 0) {
2279
+ offset += 8 - offset % 8;
2280
+ }
2281
+ return ptr;
2282
+ };
2283
+ const argc = this.argv.length;
2284
+ const argvPtrs = [];
2285
+ this.argv.forEach((arg) => {
2286
+ argvPtrs.push(strPtr(arg));
2287
+ });
2288
+ argvPtrs.push(0);
2289
+ const keys = Object.keys(this.env).sort();
2290
+ keys.forEach((key) => {
2291
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
2292
+ });
2293
+ argvPtrs.push(0);
2294
+ const argv = offset;
2295
+ argvPtrs.forEach((ptr) => {
2296
+ this.mem.setUint32(offset, ptr, true);
2297
+ this.mem.setUint32(offset + 4, 0, true);
2298
+ offset += 8;
2299
+ });
2300
+ const wasmMinDataAddr = 4096 + 8192;
2301
+ if (offset >= wasmMinDataAddr) {
2302
+ throw new Error("total length of command line and environment variables exceeds limit");
2303
+ }
2304
+ this._inst.exports.run(argc, argv);
2305
+ if (this.exited) {
2306
+ this._resolveExitPromise();
2307
+ }
2308
+ yield this._exitPromise;
2309
+ });
2310
+ }
2311
+ _resume() {
2312
+ if (this.exited) {
2313
+ throw new Error("Go program has already exited");
1809
2314
  }
2315
+ this._inst.exports.resume();
2316
+ if (this.exited) {
2317
+ this._resolveExitPromise();
2318
+ }
2319
+ }
2320
+ _makeFuncWrapper(id) {
2321
+ const go = this;
2322
+ return function() {
2323
+ const event = { id, this: this, args: arguments };
2324
+ go._pendingEvent = event;
2325
+ go._resume();
2326
+ return event.result;
2327
+ };
2328
+ }
2329
+ };
2330
+ })();
2331
+ onmessage = ({ data: wasm }) => {
2332
+ let decoder = new TextDecoder();
2333
+ let fs = globalThis.fs;
2334
+ let stderr = "";
2335
+ fs.writeSync = (fd, buffer) => {
2336
+ if (fd === 1) {
2337
+ postMessage(buffer);
2338
+ } else if (fd === 2) {
2339
+ stderr += decoder.decode(buffer);
2340
+ let parts = stderr.split("\n");
2341
+ if (parts.length > 1)
2342
+ console.log(parts.slice(0, -1).join("\n"));
2343
+ stderr = parts[parts.length - 1];
2344
+ } else {
2345
+ throw new Error("Bad write");
2346
+ }
2347
+ return buffer.length;
2348
+ };
2349
+ let stdin = [];
2350
+ let resumeStdin;
2351
+ let stdinPos = 0;
2352
+ onmessage = ({ data }) => {
2353
+ if (data.length > 0) {
2354
+ stdin.push(data);
2355
+ if (resumeStdin)
2356
+ resumeStdin();
2357
+ }
2358
+ };
2359
+ fs.read = (fd, buffer, offset, length, position, callback) => {
2360
+ if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {
2361
+ throw new Error("Bad read");
2362
+ }
2363
+ if (stdin.length === 0) {
2364
+ resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);
1810
2365
  return;
1811
2366
  }
2367
+ let first = stdin[0];
2368
+ let count = Math.max(0, Math.min(length, first.length - stdinPos));
2369
+ buffer.set(first.subarray(stdinPos, stdinPos + count), offset);
2370
+ stdinPos += count;
2371
+ if (stdinPos === first.length) {
2372
+ stdin.shift();
2373
+ stdinPos = 0;
2374
+ }
2375
+ callback(null, count);
2376
+ };
2377
+ let go = new globalThis.Go();
2378
+ go.argv = ["", `--service=${"0.14.42"}`];
2379
+ if (wasm instanceof WebAssembly.Module) {
2380
+ WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2381
+ } else {
2382
+ WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
1812
2383
  }
1813
- fs.write(fd, buf, offset, length, position, callback);
1814
- },
1815
- });
1816
-
1817
- }
1818
- }
1819
-
1820
- const enosys = () => {
1821
- const err = new Error("not implemented");
1822
- err.code = "ENOSYS";
1823
- return err;
1824
- };
1825
-
1826
- if (!global.fs) {
1827
- let outputBuf = "";
1828
- global.fs = {
1829
- constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
1830
- writeSync(fd, buf) {
1831
- outputBuf += decoder.decode(buf);
1832
- const nl = outputBuf.lastIndexOf("\\n");
1833
- if (nl != -1) {
1834
- console.log(outputBuf.substr(0, nl));
1835
- outputBuf = outputBuf.substr(nl + 1);
1836
- }
1837
- return buf.length;
1838
- },
1839
- write(fd, buf, offset, length, position, callback) {
1840
- if (offset !== 0 || length !== buf.length || position !== null) {
1841
- callback(enosys());
1842
- return;
1843
- }
1844
- const n = this.writeSync(fd, buf);
1845
- callback(null, n);
1846
- },
1847
- chmod(path, mode, callback) { callback(enosys()); },
1848
- chown(path, uid, gid, callback) { callback(enosys()); },
1849
- close(fd, callback) { callback(enosys()); },
1850
- fchmod(fd, mode, callback) { callback(enosys()); },
1851
- fchown(fd, uid, gid, callback) { callback(enosys()); },
1852
- fstat(fd, callback) { callback(enosys()); },
1853
- fsync(fd, callback) { callback(null); },
1854
- ftruncate(fd, length, callback) { callback(enosys()); },
1855
- lchown(path, uid, gid, callback) { callback(enosys()); },
1856
- link(path, link, callback) { callback(enosys()); },
1857
- lstat(path, callback) { callback(enosys()); },
1858
- mkdir(path, perm, callback) { callback(enosys()); },
1859
- open(path, flags, mode, callback) { callback(enosys()); },
1860
- read(fd, buffer, offset, length, position, callback) { callback(enosys()); },
1861
- readdir(path, callback) { callback(enosys()); },
1862
- readlink(path, callback) { callback(enosys()); },
1863
- rename(from, to, callback) { callback(enosys()); },
1864
- rmdir(path, callback) { callback(enosys()); },
1865
- stat(path, callback) { callback(enosys()); },
1866
- symlink(path, link, callback) { callback(enosys()); },
1867
- truncate(path, length, callback) { callback(enosys()); },
1868
- unlink(path, callback) { callback(enosys()); },
1869
- utimes(path, atime, mtime, callback) { callback(enosys()); },
1870
- };
1871
- }
1872
-
1873
- if (!global.process) {
1874
- global.process = {
1875
- getuid() { return -1; },
1876
- getgid() { return -1; },
1877
- geteuid() { return -1; },
1878
- getegid() { return -1; },
1879
- getgroups() { throw enosys(); },
1880
- pid: -1,
1881
- ppid: -1,
1882
- umask() { throw enosys(); },
1883
- cwd() { throw enosys(); },
1884
- chdir() { throw enosys(); },
1885
- }
1886
- }
1887
-
1888
- if (!global.crypto && global.require) {
1889
- const nodeCrypto = require("crypto");
1890
- global.crypto = {
1891
- getRandomValues(b) {
1892
- nodeCrypto.randomFillSync(b);
1893
- },
1894
- };
1895
- }
1896
- if (!global.crypto) {
1897
- throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");
1898
- }
1899
-
1900
- if (!global.performance) {
1901
- global.performance = {
1902
- now() {
1903
- const [sec, nsec] = process.hrtime();
1904
- return sec * 1000 + nsec / 1000000;
1905
- },
1906
- };
1907
- }
1908
-
1909
- if (!global.TextEncoder && global.require) {
1910
- global.TextEncoder = require("util").TextEncoder;
1911
- }
1912
- if (!global.TextEncoder) {
1913
- throw new Error("global.TextEncoder is not available, polyfill required");
1914
- }
1915
-
1916
- if (!global.TextDecoder && global.require) {
1917
- global.TextDecoder = require("util").TextDecoder;
1918
- }
1919
- if (!global.TextDecoder) {
1920
- throw new Error("global.TextDecoder is not available, polyfill required");
1921
- }
1922
-
1923
-
1924
- // Make sure Go sees the shadowed "fs" global
1925
- const { fs } = global;
1926
-
1927
-
1928
- const encoder = new TextEncoder("utf-8");
1929
- const decoder = new TextDecoder("utf-8");
1930
-
1931
- global.Go = class {
1932
- constructor() {
1933
- this.argv = ["js"];
1934
- this.env = {};
1935
- this.exit = (code) => {
1936
- if (code !== 0) {
1937
- console.warn("exit code:", code);
1938
- }
1939
- };
1940
- this._exitPromise = new Promise((resolve) => {
1941
- this._resolveExitPromise = resolve;
1942
- });
1943
- this._pendingEvent = null;
1944
- this._scheduledTimeouts = new Map();
1945
- this._nextCallbackTimeoutID = 1;
1946
-
1947
- const setInt64 = (addr, v) => {
1948
- this.mem.setUint32(addr + 0, v, true);
1949
- this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
1950
- }
1951
-
1952
- const getInt64 = (addr) => {
1953
- const low = this.mem.getUint32(addr + 0, true);
1954
- const high = this.mem.getInt32(addr + 4, true);
1955
- return low + high * 4294967296;
1956
- }
1957
-
1958
- const loadValue = (addr) => {
1959
- const f = this.mem.getFloat64(addr, true);
1960
- if (f === 0) {
1961
- return undefined;
1962
- }
1963
- if (!isNaN(f)) {
1964
- return f;
1965
- }
1966
-
1967
- const id = this.mem.getUint32(addr, true);
1968
- return this._values[id];
1969
- }
1970
-
1971
- const storeValue = (addr, v) => {
1972
- const nanHead = 0x7FF80000;
1973
-
1974
- if (typeof v === "number" && v !== 0) {
1975
- if (isNaN(v)) {
1976
- this.mem.setUint32(addr + 4, nanHead, true);
1977
- this.mem.setUint32(addr, 0, true);
1978
- return;
1979
- }
1980
- this.mem.setFloat64(addr, v, true);
1981
- return;
1982
- }
1983
-
1984
- if (v === undefined) {
1985
- this.mem.setFloat64(addr, 0, true);
1986
- return;
1987
- }
1988
-
1989
- let id = this._ids.get(v);
1990
- if (id === undefined) {
1991
- id = this._idPool.pop();
1992
- if (id === undefined) {
1993
- id = this._values.length;
1994
- }
1995
- this._values[id] = v;
1996
- this._goRefCounts[id] = 0;
1997
- this._ids.set(v, id);
1998
- }
1999
- this._goRefCounts[id]++;
2000
- let typeFlag = 0;
2001
- switch (typeof v) {
2002
- case "object":
2003
- if (v !== null) {
2004
- typeFlag = 1;
2005
- }
2006
- break;
2007
- case "string":
2008
- typeFlag = 2;
2009
- break;
2010
- case "symbol":
2011
- typeFlag = 3;
2012
- break;
2013
- case "function":
2014
- typeFlag = 4;
2015
- break;
2016
- }
2017
- this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
2018
- this.mem.setUint32(addr, id, true);
2019
- }
2020
-
2021
- const loadSlice = (addr) => {
2022
- const array = getInt64(addr + 0);
2023
- const len = getInt64(addr + 8);
2024
- return new Uint8Array(this._inst.exports.mem.buffer, array, len);
2025
- }
2026
-
2027
- const loadSliceOfValues = (addr) => {
2028
- const array = getInt64(addr + 0);
2029
- const len = getInt64(addr + 8);
2030
- const a = new Array(len);
2031
- for (let i = 0; i < len; i++) {
2032
- a[i] = loadValue(array + i * 8);
2033
- }
2034
- return a;
2035
- }
2036
-
2037
- const loadString = (addr) => {
2038
- const saddr = getInt64(addr + 0);
2039
- const len = getInt64(addr + 8);
2040
- return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
2041
- }
2042
-
2043
- const timeOrigin = Date.now() - performance.now();
2044
- this.importObject = {
2045
- go: {
2046
- // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
2047
- // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
2048
- // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
2049
- // This changes the SP, thus we have to update the SP used by the imported function.
2050
-
2051
- // func wasmExit(code int32)
2052
- "runtime.wasmExit": (sp) => {
2053
- sp >>>= 0;
2054
- const code = this.mem.getInt32(sp + 8, true);
2055
- this.exited = true;
2056
- delete this._inst;
2057
- delete this._values;
2058
- delete this._goRefCounts;
2059
- delete this._ids;
2060
- delete this._idPool;
2061
- this.exit(code);
2062
- },
2063
-
2064
- // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
2065
- "runtime.wasmWrite": (sp) => {
2066
- sp >>>= 0;
2067
- const fd = getInt64(sp + 8);
2068
- const p = getInt64(sp + 16);
2069
- const n = this.mem.getInt32(sp + 24, true);
2070
- fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
2071
- },
2072
-
2073
- // func resetMemoryDataView()
2074
- "runtime.resetMemoryDataView": (sp) => {
2075
- sp >>>= 0;
2076
- this.mem = new DataView(this._inst.exports.mem.buffer);
2077
- },
2078
-
2079
- // func nanotime1() int64
2080
- "runtime.nanotime1": (sp) => {
2081
- sp >>>= 0;
2082
- setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
2083
- },
2084
-
2085
- // func walltime() (sec int64, nsec int32)
2086
- "runtime.walltime": (sp) => {
2087
- sp >>>= 0;
2088
- const msec = (new Date).getTime();
2089
- setInt64(sp + 8, msec / 1000);
2090
- this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
2091
- },
2092
-
2093
- // func scheduleTimeoutEvent(delay int64) int32
2094
- "runtime.scheduleTimeoutEvent": (sp) => {
2095
- sp >>>= 0;
2096
- const id = this._nextCallbackTimeoutID;
2097
- this._nextCallbackTimeoutID++;
2098
- this._scheduledTimeouts.set(id, setTimeout(
2099
- () => {
2100
- this._resume();
2101
- while (this._scheduledTimeouts.has(id)) {
2102
- // for some reason Go failed to register the timeout event, log and try again
2103
- // (temporary workaround for https://github.com/golang/go/issues/28975)
2104
- console.warn("scheduleTimeoutEvent: missed timeout event");
2105
- this._resume();
2106
- }
2107
- },
2108
- getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early
2109
- ));
2110
- this.mem.setInt32(sp + 16, id, true);
2111
- },
2112
-
2113
- // func clearTimeoutEvent(id int32)
2114
- "runtime.clearTimeoutEvent": (sp) => {
2115
- sp >>>= 0;
2116
- const id = this.mem.getInt32(sp + 8, true);
2117
- clearTimeout(this._scheduledTimeouts.get(id));
2118
- this._scheduledTimeouts.delete(id);
2119
- },
2120
-
2121
- // func getRandomData(r []byte)
2122
- "runtime.getRandomData": (sp) => {
2123
- sp >>>= 0;
2124
- crypto.getRandomValues(loadSlice(sp + 8));
2125
- },
2126
-
2127
- // func finalizeRef(v ref)
2128
- "syscall/js.finalizeRef": (sp) => {
2129
- sp >>>= 0;
2130
- const id = this.mem.getUint32(sp + 8, true);
2131
- this._goRefCounts[id]--;
2132
- if (this._goRefCounts[id] === 0) {
2133
- const v = this._values[id];
2134
- this._values[id] = null;
2135
- this._ids.delete(v);
2136
- this._idPool.push(id);
2137
- }
2138
- },
2139
-
2140
- // func stringVal(value string) ref
2141
- "syscall/js.stringVal": (sp) => {
2142
- sp >>>= 0;
2143
- storeValue(sp + 24, loadString(sp + 8));
2144
- },
2145
-
2146
- // func valueGet(v ref, p string) ref
2147
- "syscall/js.valueGet": (sp) => {
2148
- sp >>>= 0;
2149
- const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
2150
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2151
- storeValue(sp + 32, result);
2152
- },
2153
-
2154
- // func valueSet(v ref, p string, x ref)
2155
- "syscall/js.valueSet": (sp) => {
2156
- sp >>>= 0;
2157
- Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
2158
- },
2159
-
2160
- // func valueDelete(v ref, p string)
2161
- "syscall/js.valueDelete": (sp) => {
2162
- sp >>>= 0;
2163
- Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
2164
- },
2165
-
2166
- // func valueIndex(v ref, i int) ref
2167
- "syscall/js.valueIndex": (sp) => {
2168
- sp >>>= 0;
2169
- storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
2170
- },
2171
-
2172
- // valueSetIndex(v ref, i int, x ref)
2173
- "syscall/js.valueSetIndex": (sp) => {
2174
- sp >>>= 0;
2175
- Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
2176
- },
2177
-
2178
- // func valueCall(v ref, m string, args []ref) (ref, bool)
2179
- "syscall/js.valueCall": (sp) => {
2180
- sp >>>= 0;
2181
- try {
2182
- const v = loadValue(sp + 8);
2183
- const m = Reflect.get(v, loadString(sp + 16));
2184
- const args = loadSliceOfValues(sp + 32);
2185
- const result = Reflect.apply(m, v, args);
2186
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2187
- storeValue(sp + 56, result);
2188
- this.mem.setUint8(sp + 64, 1);
2189
- } catch (err) {
2190
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2191
- storeValue(sp + 56, err);
2192
- this.mem.setUint8(sp + 64, 0);
2193
- }
2194
- },
2195
-
2196
- // func valueInvoke(v ref, args []ref) (ref, bool)
2197
- "syscall/js.valueInvoke": (sp) => {
2198
- sp >>>= 0;
2199
- try {
2200
- const v = loadValue(sp + 8);
2201
- const args = loadSliceOfValues(sp + 16);
2202
- const result = Reflect.apply(v, undefined, args);
2203
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2204
- storeValue(sp + 40, result);
2205
- this.mem.setUint8(sp + 48, 1);
2206
- } catch (err) {
2207
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2208
- storeValue(sp + 40, err);
2209
- this.mem.setUint8(sp + 48, 0);
2210
- }
2211
- },
2212
-
2213
- // func valueNew(v ref, args []ref) (ref, bool)
2214
- "syscall/js.valueNew": (sp) => {
2215
- sp >>>= 0;
2216
- try {
2217
- const v = loadValue(sp + 8);
2218
- const args = loadSliceOfValues(sp + 16);
2219
- const result = Reflect.construct(v, args);
2220
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2221
- storeValue(sp + 40, result);
2222
- this.mem.setUint8(sp + 48, 1);
2223
- } catch (err) {
2224
- sp = this._inst.exports.getsp() >>> 0; // see comment above
2225
- storeValue(sp + 40, err);
2226
- this.mem.setUint8(sp + 48, 0);
2227
- }
2228
- },
2229
-
2230
- // func valueLength(v ref) int
2231
- "syscall/js.valueLength": (sp) => {
2232
- sp >>>= 0;
2233
- setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
2234
- },
2235
-
2236
- // valuePrepareString(v ref) (ref, int)
2237
- "syscall/js.valuePrepareString": (sp) => {
2238
- sp >>>= 0;
2239
- const str = encoder.encode(String(loadValue(sp + 8)));
2240
- storeValue(sp + 16, str);
2241
- setInt64(sp + 24, str.length);
2242
- },
2243
-
2244
- // valueLoadString(v ref, b []byte)
2245
- "syscall/js.valueLoadString": (sp) => {
2246
- sp >>>= 0;
2247
- const str = loadValue(sp + 8);
2248
- loadSlice(sp + 16).set(str);
2249
- },
2250
-
2251
- // func valueInstanceOf(v ref, t ref) bool
2252
- "syscall/js.valueInstanceOf": (sp) => {
2253
- sp >>>= 0;
2254
- this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
2255
- },
2256
-
2257
- // func copyBytesToGo(dst []byte, src ref) (int, bool)
2258
- "syscall/js.copyBytesToGo": (sp) => {
2259
- sp >>>= 0;
2260
- const dst = loadSlice(sp + 8);
2261
- const src = loadValue(sp + 32);
2262
- if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
2263
- this.mem.setUint8(sp + 48, 0);
2264
- return;
2265
- }
2266
- const toCopy = src.subarray(0, dst.length);
2267
- dst.set(toCopy);
2268
- setInt64(sp + 40, toCopy.length);
2269
- this.mem.setUint8(sp + 48, 1);
2270
- },
2271
-
2272
- // func copyBytesToJS(dst ref, src []byte) (int, bool)
2273
- "syscall/js.copyBytesToJS": (sp) => {
2274
- sp >>>= 0;
2275
- const dst = loadValue(sp + 8);
2276
- const src = loadSlice(sp + 16);
2277
- if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
2278
- this.mem.setUint8(sp + 48, 0);
2279
- return;
2280
- }
2281
- const toCopy = src.subarray(0, dst.length);
2282
- dst.set(toCopy);
2283
- setInt64(sp + 40, toCopy.length);
2284
- this.mem.setUint8(sp + 48, 1);
2285
- },
2286
-
2287
- "debug": (value) => {
2288
- console.log(value);
2289
- },
2290
- }
2291
- };
2292
- }
2293
-
2294
- async run(instance) {
2295
- if (!(instance instanceof WebAssembly.Instance)) {
2296
- throw new Error("Go.run: WebAssembly.Instance expected");
2297
- }
2298
- this._inst = instance;
2299
- this.mem = new DataView(this._inst.exports.mem.buffer);
2300
- this._values = [ // JS values that Go currently has references to, indexed by reference id
2301
- NaN,
2302
- 0,
2303
- null,
2304
- true,
2305
- false,
2306
- global,
2307
- this,
2308
- ];
2309
- this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
2310
- this._ids = new Map([ // mapping from JS values to reference ids
2311
- [0, 1],
2312
- [null, 2],
2313
- [true, 3],
2314
- [false, 4],
2315
- [global, 5],
2316
- [this, 6],
2317
- ]);
2318
- this._idPool = []; // unused ids that have been garbage collected
2319
- this.exited = false; // whether the Go program has exited
2320
-
2321
- // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
2322
- let offset = 4096;
2323
-
2324
- const strPtr = (str) => {
2325
- const ptr = offset;
2326
- const bytes = encoder.encode(str + "\\0");
2327
- new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
2328
- offset += bytes.length;
2329
- if (offset % 8 !== 0) {
2330
- offset += 8 - (offset % 8);
2331
- }
2332
- return ptr;
2333
- };
2334
-
2335
- const argc = this.argv.length;
2336
-
2337
- const argvPtrs = [];
2338
- this.argv.forEach((arg) => {
2339
- argvPtrs.push(strPtr(arg));
2340
- });
2341
- argvPtrs.push(0);
2342
-
2343
- const keys = Object.keys(this.env).sort();
2344
- keys.forEach((key) => {
2345
- argvPtrs.push(strPtr(\`\${key}=\${this.env[key]}\`));
2346
- });
2347
- argvPtrs.push(0);
2348
-
2349
- const argv = offset;
2350
- argvPtrs.forEach((ptr) => {
2351
- this.mem.setUint32(offset, ptr, true);
2352
- this.mem.setUint32(offset + 4, 0, true);
2353
- offset += 8;
2354
- });
2355
-
2356
- // The linker guarantees global data starts from at least wasmMinDataAddr.
2357
- // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
2358
- const wasmMinDataAddr = 4096 + 8192;
2359
- if (offset >= wasmMinDataAddr) {
2360
- throw new Error("total length of command line and environment variables exceeds limit");
2361
- }
2362
-
2363
- this._inst.exports.run(argc, argv);
2364
- if (this.exited) {
2365
- this._resolveExitPromise();
2366
- }
2367
- await this._exitPromise;
2368
- }
2369
-
2370
- _resume() {
2371
- if (this.exited) {
2372
- throw new Error("Go program has already exited");
2373
- }
2374
- this._inst.exports.resume();
2375
- if (this.exited) {
2376
- this._resolveExitPromise();
2377
- }
2378
- }
2379
-
2380
- _makeFuncWrapper(id) {
2381
- const go = this;
2382
- return function () {
2383
- const event = { id: id, this: this, args: arguments };
2384
- go._pendingEvent = event;
2385
- go._resume();
2386
- return event.result;
2387
- };
2388
- }
2389
- }
2390
-
2391
- if (
2392
- typeof module !== "undefined" &&
2393
- global.require &&
2394
- global.require.main === module &&
2395
- global.process &&
2396
- global.process.versions &&
2397
- !global.process.versions.electron
2398
- ) {
2399
- if (process.argv.length < 3) {
2400
- console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
2401
- process.exit(1);
2402
- }
2403
-
2404
- const go = new Go();
2405
- go.argv = process.argv.slice(2);
2406
- go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
2407
- go.exit = process.exit;
2408
- WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
2409
- process.on("exit", (code) => { // Node.js exits if no event handler is pending
2410
- if (code === 0 && !go.exited) {
2411
- // deadlock, make Go print error and stack traces
2412
- go._pendingEvent = { id: 0 };
2413
- go._resume();
2414
- }
2415
- });
2416
- return go.run(result.instance);
2417
- }).catch((err) => {
2418
- console.error(err);
2419
- process.exit(1);
2420
- });
2421
- }
2422
- })();
2423
- onmessage = ({ data: wasm }) => {
2424
- let decoder = new TextDecoder();
2425
- let fs = global.fs;
2426
- let stderr = "";
2427
- fs.writeSync = (fd, buffer) => {
2428
- if (fd === 1) {
2429
- postMessage(buffer);
2430
- } else if (fd === 2) {
2431
- stderr += decoder.decode(buffer);
2432
- let parts = stderr.split("\\n");
2433
- if (parts.length > 1)
2434
- console.log(parts.slice(0, -1).join("\\n"));
2435
- stderr = parts[parts.length - 1];
2436
- } else {
2437
- throw new Error("Bad write");
2438
- }
2439
- return buffer.length;
2440
- };
2441
- let stdin = [];
2442
- let resumeStdin;
2443
- let stdinPos = 0;
2444
- onmessage = ({ data }) => {
2445
- if (data.length > 0) {
2446
- stdin.push(data);
2447
- if (resumeStdin)
2448
- resumeStdin();
2449
- }
2450
- };
2451
- fs.read = (fd, buffer, offset, length, position, callback) => {
2452
- if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {
2453
- throw new Error("Bad read");
2454
- }
2455
- if (stdin.length === 0) {
2456
- resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);
2457
- return;
2458
- }
2459
- let first = stdin[0];
2460
- let count = Math.max(0, Math.min(length, first.length - stdinPos));
2461
- buffer.set(first.subarray(stdinPos, stdinPos + count), offset);
2462
- stdinPos += count;
2463
- if (stdinPos === first.length) {
2464
- stdin.shift();
2465
- stdinPos = 0;
2466
- }
2467
- callback(null, count);
2468
- };
2469
- let go = new global.Go();
2470
- go.argv = ["", \`--service=\${"0.14.23"}\`];
2471
- WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
2472
- };}`;
2473
- let worker;
2474
- if (useWorker) {
2475
- let blob = new Blob([code], { type: "text/javascript" });
2476
- worker = new Worker(URL.createObjectURL(blob));
2477
- } else {
2478
- let fn = new Function("postMessage", code + `var onmessage; return m => onmessage(m)`);
2479
- let onmessage = fn((data) => worker.onmessage({ data }));
2384
+ };
2385
+ return (m) => onmessage(m);
2386
+ })((data) => worker.onmessage({ data }));
2480
2387
  worker = {
2481
2388
  onmessage: null,
2482
- postMessage: (data) => onmessage({ data }),
2389
+ postMessage: (data) => setTimeout(() => onmessage({ data })),
2483
2390
  terminate() {
2484
2391
  }
2485
2392
  };
@@ -2502,7 +2409,7 @@ onmessage = ({ data: wasm }) => {
2502
2409
  options,
2503
2410
  isTTY: false,
2504
2411
  defaultWD: "/",
2505
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2412
+ callback: (err, res) => err ? reject(err) : resolve(res)
2506
2413
  })),
2507
2414
  transform: (input, options) => new Promise((resolve, reject) => service.transform({
2508
2415
  callName: "transform",
@@ -2518,24 +2425,23 @@ onmessage = ({ data: wasm }) => {
2518
2425
  callback(null);
2519
2426
  }
2520
2427
  },
2521
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2428
+ callback: (err, res) => err ? reject(err) : resolve(res)
2522
2429
  })),
2523
2430
  formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
2524
2431
  callName: "formatMessages",
2525
2432
  refs: null,
2526
2433
  messages,
2527
2434
  options,
2528
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2435
+ callback: (err, res) => err ? reject(err) : resolve(res)
2529
2436
  })),
2530
2437
  analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
2531
2438
  callName: "analyzeMetafile",
2532
2439
  refs: null,
2533
2440
  metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
2534
2441
  options,
2535
- callback: (err, res2) => err ? reject(err) : resolve(res2)
2442
+ callback: (err, res) => err ? reject(err) : resolve(res)
2536
2443
  }))
2537
2444
  };
2538
2445
  });
2539
2446
  var browser_default = browser_exports;
2540
- module.exports = __toCommonJS(browser_exports);
2541
2447
  })(typeof module==="object"?module:{set exports(x){(typeof self!=="undefined"?self:this).esbuild=x}});