gofront 1.8.0 → 1.9.0
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.
- package/README.md +3 -3
- package/package.json +5 -4
- package/src/backend/js/expressions.js +849 -371
- package/src/backend/js/index.js +241 -147
- package/src/backend/js/natives.js +383 -0
- package/src/backend/js/runtime.js +512 -2547
- package/src/backend/js/statements.js +506 -103
- package/src/backend/js/stdlib/index.js +45 -93
- package/src/backend/js/templ.js +32 -45
- package/src/backend/js/type-info.js +177 -13
- package/src/backend/shared/fixed-float.js +20 -0
- package/src/backend/shared/fmt-types.js +63 -171
- package/src/backend/shared/host-unicode.js +36 -0
- package/src/backend/wasm/boundary.js +490 -965
- package/src/backend/wasm/emit-builtins.js +643 -256
- package/src/backend/wasm/emit-exprs.js +124 -57
- package/src/backend/wasm/emit-maps.js +17 -367
- package/src/backend/wasm/emit-stmts.js +325 -75
- package/src/backend/wasm/emit.js +104 -13
- package/src/backend/wasm/globals.js +47 -8
- package/src/backend/wasm/glue.js +2 -4
- package/src/backend/wasm/index.js +36 -530
- package/src/backend/wasm/method-expr.js +12 -1
- package/src/backend/wasm/module-emitter.js +92 -717
- package/src/backend/wasm/monomorph.js +103 -6
- package/src/backend/wasm/natives.js +596 -0
- package/src/backend/wasm/prescan.js +5 -153
- package/src/backend/wasm/prune-funcs.js +89 -0
- package/src/backend/wasm/stdlib/index.js +2 -32
- package/src/backend/wasm/types.js +68 -20
- package/src/backend/wasm/variadic.js +3 -3
- package/src/cli/cli-core.js +5 -1
- package/src/cli/test-runner.js +115 -342
- package/src/compiler.js +108 -130
- package/src/lexer/lexer.js +105 -11
- package/src/lexer/templ-lexer.js +61 -18
- package/src/lexer/tokens.js +1 -0
- package/src/link/stdlib.js +354 -132
- package/src/link/type-names.js +148 -0
- package/src/link/wasm.js +30 -6
- package/src/lower/bounds.js +153 -0
- package/src/lower/captures.js +92 -33
- package/src/lower/embedding.js +32 -3
- package/src/lower/errors-as.js +196 -0
- package/src/lower/fmt-formatters.js +905 -0
- package/src/lower/functions.js +2 -0
- package/src/lower/gen-types.js +274 -0
- package/src/lower/index.js +7 -1
- package/src/lower/json-codecs.js +228 -247
- package/src/lower/ownership.js +25 -7
- package/src/lower/reachability.js +69 -51
- package/src/lower/walk.js +12 -0
- package/src/parser/declarations.js +28 -5
- package/src/parser/expressions.js +86 -16
- package/src/parser/statements.js +1 -0
- package/src/parser/templ.js +44 -5
- package/src/parser/types.js +1 -0
- package/src/resolver.js +1 -2
- package/src/typechecker/assignability.js +124 -11
- package/src/typechecker/const-fold.js +70 -27
- package/src/typechecker/constants.js +32 -6
- package/src/typechecker/expressions.js +326 -98
- package/src/typechecker/index.js +208 -33
- package/src/typechecker/init-order.js +136 -40
- package/src/typechecker/operand-text.js +40 -0
- package/src/typechecker/resolve.js +192 -36
- package/src/typechecker/statements.js +122 -11
- package/src/typechecker/stdlib/excluded.js +9 -5
- package/src/typechecker/stdlib/index.js +25 -9
- package/src/typechecker/termination.js +10 -1
- package/src/typechecker/types.js +203 -573
- package/stdlib/bytes/buffer.go +479 -0
- package/stdlib/bytes/bytes.go +1010 -0
- package/stdlib/bytes/reader.go +161 -0
- package/stdlib/context/context.go +115 -0
- package/stdlib/crypto/rand/rand.go +34 -0
- package/stdlib/crypto/sha256/sha256.go +249 -0
- package/stdlib/encoding/base64/base64.go +331 -0
- package/stdlib/encoding/binary/binary.go +332 -0
- package/stdlib/encoding/hex/hex.go +140 -0
- package/stdlib/encoding/json/json.go +62 -0
- package/stdlib/errors/errors.go +174 -0
- package/stdlib/fmt/errors.go +110 -0
- package/stdlib/fmt/format.go +732 -0
- package/stdlib/fmt/print.go +1232 -0
- package/stdlib/gom/gom.go +293 -0
- package/stdlib/html/html.go +251 -0
- package/stdlib/internal/fmtrt/fmtrt.go +163 -0
- package/stdlib/internal/jsonrt/dec.go +171 -38
- package/stdlib/internal/jsonrt/enc.go +186 -36
- package/stdlib/internal/jsonrt/scanner.go +17 -8
- package/stdlib/io/io.go +157 -1
- package/stdlib/maps/maps.go +131 -0
- package/stdlib/math/bits/bits.go +507 -0
- package/stdlib/math/extra.go +16 -14
- package/stdlib/math/math.go +439 -0
- package/stdlib/math/rand/rand.go +297 -0
- package/stdlib/os/os.go +93 -0
- package/stdlib/path/filepath/filepath.go +47 -0
- package/stdlib/path/path.go +394 -0
- package/stdlib/regexp/regexp.go +231 -0
- package/stdlib/slices/slices.go +526 -0
- package/stdlib/slices/sort.go +209 -0
- package/stdlib/slices/zsort_cmp.go +480 -0
- package/stdlib/slices/zsort_ordered.go +482 -0
- package/stdlib/sort/sort.go +391 -452
- package/stdlib/sort/zsort_func.go +480 -0
- package/stdlib/sort/zsort_iface.go +480 -0
- package/stdlib/strconv/float.go +1699 -0
- package/stdlib/strconv/isprint.go +752 -0
- package/stdlib/strconv/quote.go +235 -50
- package/stdlib/strconv/strconv.go +616 -0
- package/stdlib/strings/builder.go +95 -0
- package/stdlib/strings/reader.go +163 -0
- package/stdlib/strings/replacer.go +102 -0
- package/stdlib/strings/strings.go +807 -0
- package/stdlib/sync/sync.go +268 -0
- package/stdlib/testing/async_js.go +61 -0
- package/stdlib/testing/benchmark.go +297 -0
- package/stdlib/testing/testing.go +523 -0
- package/stdlib/time/duration.go +233 -0
- package/stdlib/time/format.go +745 -0
- package/stdlib/time/parse.go +790 -0
- package/stdlib/time/sleep_js.go +63 -0
- package/stdlib/time/time.go +834 -0
- package/stdlib/unicode/unicode.go +141 -3
- package/stdlib/unicode/utf8/utf8.go +464 -0
- package/src/backend/js/fmt-runtime.js +0 -573
- package/src/backend/js/stdlib/base64.js +0 -12
- package/src/backend/js/stdlib/binary.js +0 -102
- package/src/backend/js/stdlib/bits.js +0 -119
- package/src/backend/js/stdlib/builder.js +0 -98
- package/src/backend/js/stdlib/bytes.js +0 -368
- package/src/backend/js/stdlib/errors.js +0 -45
- package/src/backend/js/stdlib/fmt.js +0 -517
- package/src/backend/js/stdlib/gom.js +0 -155
- package/src/backend/js/stdlib/hex.js +0 -17
- package/src/backend/js/stdlib/html.js +0 -20
- package/src/backend/js/stdlib/io.js +0 -137
- package/src/backend/js/stdlib/json.js +0 -1167
- package/src/backend/js/stdlib/maps.js +0 -37
- package/src/backend/js/stdlib/math.js +0 -85
- package/src/backend/js/stdlib/os.js +0 -13
- package/src/backend/js/stdlib/path.js +0 -48
- package/src/backend/js/stdlib/rand.js +0 -32
- package/src/backend/js/stdlib/regexp.js +0 -54
- package/src/backend/js/stdlib/sha256.js +0 -12
- package/src/backend/js/stdlib/shared.js +0 -17
- package/src/backend/js/stdlib/simd.js +0 -34
- package/src/backend/js/stdlib/slices.js +0 -107
- package/src/backend/js/stdlib/sort.js +0 -30
- package/src/backend/js/stdlib/strconv.js +0 -79
- package/src/backend/js/stdlib/strings.js +0 -301
- package/src/backend/js/stdlib/sync.js +0 -13
- package/src/backend/js/stdlib/testing.js +0 -41
- package/src/backend/js/stdlib/time.js +0 -152
- package/src/backend/js/stdlib/unicode.js +0 -25
- package/src/backend/js/stdlib/utf8.js +0 -26
- package/src/backend/wasm/stdlib/bytes.js +0 -6716
- package/src/backend/wasm/stdlib/core.js +0 -10278
- package/src/backend/wasm/stdlib/io.js +0 -3578
- package/src/backend/wasm/stdlib/packages.js +0 -2402
- package/src/backend/wasm/stdlib/pure.js +0 -720
- package/src/backend/wasm/stdlib/time.js +0 -2229
- package/src/typechecker/stdlib/core.js +0 -1079
- package/src/typechecker/stdlib/extended.js +0 -1210
- package/stdlib/bytes/iter.go +0 -192
- package/stdlib/bytes/search.go +0 -240
- package/stdlib/bytes/split.go +0 -218
- package/stdlib/errors/overlay.go +0 -12
- package/stdlib/maps/iter.go +0 -65
- package/stdlib/slices/extra.go +0 -73
- package/stdlib/slices/iter.go +0 -113
- package/stdlib/strings/extra.go +0 -35
- package/stdlib/strings/iter.go +0 -122
- package/stdlib/sync/extra.go +0 -105
- package/stdlib/unicode/utf8/bytes.go +0 -239
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { HELPER_FMT_LOOP, HELPER_FMT_UTIL } from "./fmt-runtime.js";
|
|
2
|
-
|
|
3
1
|
// Runtime helpers emitted by the code generator when the corresponding feature is used.
|
|
4
2
|
// Each export is a single JS statement (var __x = __x || function(...){...};) so that
|
|
5
3
|
// multiple compiled files bundled together can safely repeat the declaration.
|
|
@@ -9,6 +7,30 @@ export const HELPER_LEN = `var __len = __len || function(a) {
|
|
|
9
7
|
return a?.length ?? 0;
|
|
10
8
|
};`;
|
|
11
9
|
|
|
10
|
+
// string -> []byte: UTF-8, except that a lone surrogate U+DC80-U+DCFF (a raw
|
|
11
|
+
// byte from a \xNN escape) encodes as that single byte.
|
|
12
|
+
export const HELPER_U8ENC = `var __u8e = __u8e || new TextEncoder();
|
|
13
|
+
var __u8enc = __u8enc || function(s) {
|
|
14
|
+
const e = __u8e;
|
|
15
|
+
if (s.isWellFormed()) return e.encode(s);
|
|
16
|
+
const out = [];
|
|
17
|
+
for (let i = 0; i < s.length; i++) {
|
|
18
|
+
const c = s.charCodeAt(i);
|
|
19
|
+
if (c >= 0xdc80 && c <= 0xdcff && !(i > 0 && (s.charCodeAt(i - 1) & 0xfc00) === 0xd800)) { out.push(c - 0xdc00); continue; }
|
|
20
|
+
const cp = s.codePointAt(i);
|
|
21
|
+
if (cp > 0xffff) i++;
|
|
22
|
+
for (const b of e.encode(String.fromCodePoint(cp))) out.push(b);
|
|
23
|
+
}
|
|
24
|
+
return Uint8Array.from(out);
|
|
25
|
+
};`;
|
|
26
|
+
|
|
27
|
+
// []byte -> string: UTF-8 with U+FFFD for invalid bytes. A typed array is
|
|
28
|
+
// decoded in place; anything else is copied into one first.
|
|
29
|
+
export const HELPER_U8DEC = `var __u8d = __u8d || null;
|
|
30
|
+
var __u8dec = __u8dec || function(b) {
|
|
31
|
+
return (__u8d ??= new TextDecoder()).decode(ArrayBuffer.isView(b) ? b : new Uint8Array(b));
|
|
32
|
+
};`;
|
|
33
|
+
|
|
12
34
|
// Slice views (Go's `b[lo:hi:max]` shares the backing store). A view of a
|
|
13
35
|
// plain array is a Proxy over an empty `__SV` array that holds the backing
|
|
14
36
|
// array `b`, offset `o`, length `n` and capacity `c`: Array.isArray, length,
|
|
@@ -198,20 +220,46 @@ var __mkslice = __mkslice || function(n, b) {
|
|
|
198
220
|
return __slice(b, 0, n);
|
|
199
221
|
};`;
|
|
200
222
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
223
|
+
// `make([]T, n, cap)` argument checks with Go's messages: a negative length is
|
|
224
|
+
// a len panic, a negative capacity (or one below the length) a cap panic.
|
|
225
|
+
export const HELPER_MKLEN = `var __mkn = __mkn || function(n) {
|
|
226
|
+
if (!(n >= 0)) throw new Error("runtime error: makeslice: len out of range");
|
|
227
|
+
return n;
|
|
228
|
+
};
|
|
229
|
+
var __mkc = __mkc || function(c) {
|
|
230
|
+
if (!(c >= 0)) throw new Error("runtime error: makeslice: cap out of range");
|
|
231
|
+
return c;
|
|
232
|
+
};`;
|
|
233
|
+
|
|
234
|
+
// string(rune): an out-of-range rune or a surrogate is U+FFFD.
|
|
235
|
+
export const HELPER_RUNESTR = `var __rstr = __rstr || function(c) {
|
|
236
|
+
return String.fromCodePoint(c >= 0 && c <= 0x10ffff && !(c >= 0xd800 && c <= 0xdfff) ? c : 0xfffd);
|
|
237
|
+
};`;
|
|
238
|
+
|
|
239
|
+
export const HELPER_APPEND = `var __tn = __tn || function(c) {
|
|
240
|
+
return Object.hasOwn(c, "__tnil") ? c.__tnil : Object.defineProperty(c, "__tnil", { value: Object.defineProperty(new c(0), "__nilt", { value: true }) }).__tnil;
|
|
241
|
+
};
|
|
242
|
+
// Append the elements of the array-like b to a typed array.
|
|
243
|
+
var __tapp = __tapp || function(a, b) {
|
|
244
|
+
const c = __tcap.get(a);
|
|
245
|
+
if (c !== undefined && a.length + b.length <= c) {
|
|
246
|
+
const r = new a.constructor(a.buffer, a.byteOffset, a.length + b.length);
|
|
247
|
+
r.set(b, a.length);
|
|
248
|
+
if (c > r.length) __tcap.set(r, c);
|
|
249
|
+
return r;
|
|
214
250
|
}
|
|
251
|
+
// Grow with spare capacity so repeated appends cost O(1) amortized.
|
|
252
|
+
const n = a.length + b.length;
|
|
253
|
+
const cap = Math.max(n, a.length * 2);
|
|
254
|
+
const res = new a.constructor(new a.constructor(cap).buffer, 0, n);
|
|
255
|
+
res.set(a);
|
|
256
|
+
res.set(b, a.length);
|
|
257
|
+
__tcap.set(res, cap);
|
|
258
|
+
return res;
|
|
259
|
+
};
|
|
260
|
+
var __append = __append || function(a, ...b) {
|
|
261
|
+
if (b.length === 0) return a !== null && a !== undefined && a.__nilt === true ? null : a;
|
|
262
|
+
if (a && ArrayBuffer.isView(a)) return __tapp(a, b);
|
|
215
263
|
const s = a ? a[__sv] : undefined;
|
|
216
264
|
if (s !== undefined && s.n + b.length <= s.c) {
|
|
217
265
|
for (let i = 0; i < b.length; i++) s.b[s.o + s.n + i] = b[i];
|
|
@@ -226,24 +274,20 @@ export const HELPER_APPEND = `var __append = __append || function(a, ...b) {
|
|
|
226
274
|
}
|
|
227
275
|
}
|
|
228
276
|
return a ? [...a, ...b] : b;
|
|
277
|
+
};
|
|
278
|
+
// append(a, b...) of a typed array with one source: no argument spread.
|
|
279
|
+
var __appendv = __appendv || function(a, b) {
|
|
280
|
+
if (b.length === 0) return a !== null && a !== undefined && a.__nilt === true ? null : a;
|
|
281
|
+
return __tapp(a, b);
|
|
229
282
|
};`;
|
|
230
283
|
|
|
231
|
-
|
|
284
|
+
// `s = append(s, x)` in the json codecs, where the slice is a local that no
|
|
285
|
+
// other slice shares: a plain array grows in place. A view with spare
|
|
286
|
+
// capacity, a reslice copy or a typed array takes the general __append.
|
|
287
|
+
export const HELPER_PUSHS =
|
|
288
|
+
"var __pushs = __pushs || function(a, x) { if (a == null) return [x]; if (!Array.isArray(a) || a[__sv] !== undefined || a[__rcap] !== undefined) return __append(a, x); a.push(x); return a; };";
|
|
232
289
|
|
|
233
|
-
|
|
234
|
-
// comparator reads the live slice, so elements are moved as it runs
|
|
235
|
-
// (binary insertion: O(n log n) compares, O(n^2) moves, fine for typed arrays).
|
|
236
|
-
export const HELPER_SORT_SLICE = `var __sortSlice = __sortSlice || function(s, less) {
|
|
237
|
-
if (!s) return;
|
|
238
|
-
for (let i = 1; i < s.length; i++) {
|
|
239
|
-
let lo = 0, hi = i;
|
|
240
|
-
while (lo < hi) { const mid = (lo + hi) >>> 1; if (less(i, mid)) hi = mid; else lo = mid + 1; }
|
|
241
|
-
if (lo === i) continue;
|
|
242
|
-
const v = s[i];
|
|
243
|
-
for (let k = i; k > lo; k--) s[k] = s[k - 1];
|
|
244
|
-
s[lo] = v;
|
|
245
|
-
}
|
|
246
|
-
};`;
|
|
290
|
+
export const HELPER_S = "var __s = __s || function(a) { return a || []; };";
|
|
247
291
|
|
|
248
292
|
// Copy of a struct value whose class is not statically known.
|
|
249
293
|
export const HELPER_SCLONE = `var __sclone = __sclone || function(x) {
|
|
@@ -289,9 +333,9 @@ export const HELPER_GEQ = `var __geq = __geq || function(z, a, b) {
|
|
|
289
333
|
|
|
290
334
|
// Interface boxing: tag struct values (__v) vs struct pointers (__p) so type
|
|
291
335
|
// switches can tell T from *T; tags are non-enumerable so __equal/JSON ignore them.
|
|
292
|
-
export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields) {
|
|
336
|
+
export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields, fresh) {
|
|
293
337
|
if (x === null || typeof x !== "object") return x;
|
|
294
|
-
const c = typeof x.__clone === "function" ? x.__clone() : Object.assign(Object.create(Object.getPrototypeOf(x)), x);
|
|
338
|
+
const c = fresh === true ? x : typeof x.__clone === "function" ? x.__clone() : Object.assign(Object.create(Object.getPrototypeOf(x)), x);
|
|
295
339
|
Object.defineProperty(c, "__v", { value: true, configurable: true });
|
|
296
340
|
if (Array.isArray(ptrFields)) {
|
|
297
341
|
for (const f of ptrFields) {
|
|
@@ -306,61 +350,18 @@ export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields) {
|
|
|
306
350
|
}
|
|
307
351
|
}
|
|
308
352
|
}
|
|
309
|
-
for (const k
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
353
|
+
for (const k in c) {
|
|
354
|
+
const v = c[k];
|
|
355
|
+
if (v !== null && typeof v === "object" && !Array.isArray(v) && !ArrayBuffer.isView(v)) {
|
|
356
|
+
if (!v.__v && !v.__p && Object.isExtensible(v) && (!Array.isArray(ptrFields) || !ptrFields.includes(k))) {
|
|
357
|
+
Object.defineProperty(v, "__v", { value: true, configurable: true });
|
|
313
358
|
}
|
|
314
359
|
}
|
|
315
360
|
}
|
|
316
361
|
return c;
|
|
317
362
|
};
|
|
318
|
-
var __buffer_proto = __buffer_proto || {
|
|
319
|
-
Write(d) {
|
|
320
|
-
this._lastOp = 0;
|
|
321
|
-
for (let i = 0; i < d.length; i++) this._buf.push(d[i]);
|
|
322
|
-
return [d.length, null];
|
|
323
|
-
},
|
|
324
|
-
WriteString(s) {
|
|
325
|
-
this._lastOp = 0;
|
|
326
|
-
const bytes = new TextEncoder().encode(s);
|
|
327
|
-
for (let i = 0; i < bytes.length; i++) this._buf.push(bytes[i]);
|
|
328
|
-
return [bytes.length, null];
|
|
329
|
-
},
|
|
330
|
-
Read(p) {
|
|
331
|
-
if (!this._buf || this._buf.length === 0) return [0, typeof __io_eof !== "undefined" ? __io_eof : "EOF"];
|
|
332
|
-
const n = Math.min(p.length, this._buf.length);
|
|
333
|
-
for (let i = 0; i < n; i++) p[i] = this._buf.shift();
|
|
334
|
-
if (n > 0) { this._lastOp = 1; this._lastByte = p[n - 1]; } else { this._lastOp = 0; }
|
|
335
|
-
return [n, null];
|
|
336
|
-
},
|
|
337
|
-
String() {
|
|
338
|
-
return new TextDecoder().decode(new Uint8Array(this._buf));
|
|
339
|
-
},
|
|
340
|
-
Reset() {
|
|
341
|
-
this._buf = [];
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var __builder_proto = __builder_proto || {
|
|
345
|
-
Write(d) {
|
|
346
|
-
this._buf += new TextDecoder().decode(new Uint8Array(d));
|
|
347
|
-
return [d.length, null];
|
|
348
|
-
},
|
|
349
|
-
WriteString(s) {
|
|
350
|
-
this._buf += s;
|
|
351
|
-
return [new TextEncoder().encode(s).length, null];
|
|
352
|
-
},
|
|
353
|
-
String() {
|
|
354
|
-
return this._buf;
|
|
355
|
-
},
|
|
356
|
-
Reset() {
|
|
357
|
-
this._buf = "";
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
363
|
var __ifp = __ifp || function(x, ptrFields, seen) {
|
|
361
364
|
if (x === null || typeof x !== "object") return x;
|
|
362
|
-
if (Array.isArray(x._buf) && typeof x.Write !== "function") Object.assign(x, __buffer_proto);
|
|
363
|
-
else if (typeof x._buf === "string" && typeof x.WriteString !== "function") Object.assign(x, __builder_proto);
|
|
364
365
|
if (x.__p !== true && Object.isExtensible(x))
|
|
365
366
|
Object.defineProperty(x, "__p", { value: true, configurable: true, writable: true });
|
|
366
367
|
if (Array.isArray(ptrFields)) {
|
|
@@ -381,6 +382,31 @@ var __ifp = __ifp || function(x, ptrFields, seen) {
|
|
|
381
382
|
}
|
|
382
383
|
return x;
|
|
383
384
|
};
|
|
385
|
+
var __mknil = __mknil || function(C) {
|
|
386
|
+
const s = Object.create(C.prototype);
|
|
387
|
+
Object.defineProperty(s, "__nilp", { value: true });
|
|
388
|
+
Object.defineProperty(s, "__p", { value: true });
|
|
389
|
+
const vm = C.__vm || [];
|
|
390
|
+
for (const k of Object.getOwnPropertyNames(C.prototype)) {
|
|
391
|
+
const f = C.prototype[k];
|
|
392
|
+
if (k === "constructor" || k === "toString" || k.startsWith("__") || typeof f !== "function") continue;
|
|
393
|
+
Object.defineProperty(s, k, { value: vm.includes(k)
|
|
394
|
+
? function() { throw new Error("runtime error: invalid memory address or nil pointer dereference"); }
|
|
395
|
+
: function(...a) { return f.apply(null, a); } });
|
|
396
|
+
}
|
|
397
|
+
Object.defineProperty(C, "__nil", { value: s });
|
|
398
|
+
return s;
|
|
399
|
+
};
|
|
400
|
+
var __ifn = __ifn || function(x, C) {
|
|
401
|
+
return x === null ? (Object.hasOwn(C, "__nil") ? C.__nil : __mknil(C)) : x;
|
|
402
|
+
};
|
|
403
|
+
var __pbs = __pbs || function(p) {
|
|
404
|
+
var e = p !== null && typeof p === "object" ? p.value : undefined;
|
|
405
|
+
return e !== null && typeof e === "object" && e.value === e ? e : p;
|
|
406
|
+
};
|
|
407
|
+
var __unnil = __unnil || function(x) {
|
|
408
|
+
return x != null && x.__nilp === true ? null : x;
|
|
409
|
+
};
|
|
384
410
|
var __ifm = __ifm || function(x) {
|
|
385
411
|
if (x === null || x === undefined) return x;
|
|
386
412
|
if (typeof x !== "object") return x;
|
|
@@ -412,33 +438,134 @@ var __ifps = __ifps || function(x) {
|
|
|
412
438
|
Object.defineProperty(x, "__ptr_slice", { value: true, configurable: true });
|
|
413
439
|
}
|
|
414
440
|
return x;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
441
|
+
};
|
|
442
|
+
var __ity = __ity || function(x, t, ptr) {
|
|
443
|
+
// The frozen nil map cannot carry a tag: a copy of it keeps its map type.
|
|
444
|
+
if (x !== null && x !== undefined && x.__nilm === true && x.__t === undefined)
|
|
445
|
+
return Object.freeze(Object.defineProperties({}, { __map: { value: true }, __nilm: { value: true }, __t: { value: t } }));
|
|
446
|
+
if (x === null || x === undefined) {
|
|
447
|
+
// A nil slice keeps its type as an empty tagged array (not a nil interface).
|
|
448
|
+
if (!ptr && t.charCodeAt(0) !== 91) return x;
|
|
449
|
+
const n = ptr ? {} : [];
|
|
450
|
+
if (!ptr) Object.defineProperty(n, "__nils", { value: true });
|
|
451
|
+
Object.defineProperty(n, "__nilp", { value: true });
|
|
452
|
+
Object.defineProperty(n, "__t", { value: t });
|
|
453
|
+
return n;
|
|
454
|
+
}
|
|
455
|
+
if ((typeof x === "object" || typeof x === "function") && Object.isExtensible(x))
|
|
456
|
+
Object.defineProperty(x, "__t", { value: t, configurable: true, writable: true });
|
|
423
457
|
return x;
|
|
458
|
+
};
|
|
459
|
+
var __isty = __isty || function(v, t, k, c, n) {
|
|
460
|
+
if (v === null || v === undefined || (typeof v !== "object" && typeof v !== "function")) return false;
|
|
461
|
+
if (k === "func") return typeof v === "function" && (v.__t === undefined || t === "" || v.__t === t);
|
|
462
|
+
if (v.__t !== undefined && t !== "") return v.__t === t;
|
|
463
|
+
if (v.__nilp === true) return false;
|
|
464
|
+
if (k === "named" || k === "struct") return false;
|
|
465
|
+
if (k === "ptr") {
|
|
466
|
+
if (!(typeof v === "object" && "value" in v && v.value !== v && typeof v.__gfUnbox !== "function" && !(v instanceof Array))) return false;
|
|
467
|
+
// An untagged pointer (to a type parameter's variable): the pointee's
|
|
468
|
+
// shape picks the pointer type; a nil slice or map is decoded as an any.
|
|
469
|
+
if (t.charCodeAt(0) === 42) {
|
|
470
|
+
var pt = t.slice(1), pe = v.value;
|
|
471
|
+
if (pe === null || pe === undefined) return pt === "interface {}";
|
|
472
|
+
if (typeof pe === "number") return pt === "float64";
|
|
473
|
+
if (typeof pe === "string") return pt === "string";
|
|
474
|
+
if (typeof pe === "boolean") return pt === "bool";
|
|
475
|
+
if (typeof pe === "bigint") return pt === "int64";
|
|
476
|
+
if (ArrayBuffer.isView(pe)) return pt.startsWith("[]");
|
|
477
|
+
if (typeof pe === "object" && !Array.isArray(pe)) return pt === "interface {}";
|
|
478
|
+
}
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
if (k === "map") return typeof v === "object" && (v.__map === true || Object.getPrototypeOf(v) === Object.prototype);
|
|
482
|
+
if (k === "array") return Array.isArray(v) && v.length === n;
|
|
483
|
+
if (c) return v instanceof c;
|
|
484
|
+
if (!Array.isArray(v)) return false;
|
|
485
|
+
// An untagged array (a value of a type parameter's type): its first element
|
|
486
|
+
// must at least have the shape of the tag's element type.
|
|
487
|
+
if (k === "slice" && v.length > 0 && t.startsWith("[]")) {
|
|
488
|
+
var x = t.slice(2), e = v[0];
|
|
489
|
+
if (x === "bool") return typeof e === "boolean";
|
|
490
|
+
if (x === "string") return typeof e === "string";
|
|
491
|
+
if (x === "int64" || x === "uint64") return typeof e === "bigint";
|
|
492
|
+
if (/^(u?int(8|16|32)?|uintptr|float(32|64))$/.test(x)) return typeof e === "number";
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
};
|
|
496
|
+
var __dtn = __dtn || function(v) {
|
|
497
|
+
if (v === null || v === undefined) return "nil";
|
|
498
|
+
switch (typeof v) {
|
|
499
|
+
case "string": return "string";
|
|
500
|
+
case "boolean": return "bool";
|
|
501
|
+
case "number": return Number.isInteger(v) ? "int" : "float64";
|
|
502
|
+
case "bigint": return "int64";
|
|
503
|
+
}
|
|
504
|
+
if (v.__t !== undefined) return v.__t;
|
|
505
|
+
if (Array.isArray(v)) return "[]interface {}";
|
|
506
|
+
const c = v.constructor;
|
|
507
|
+
if (c && c !== Object && typeof c.name === "string" && c.name !== "") {
|
|
508
|
+
const ptr = c.name.endsWith("$Ptr");
|
|
509
|
+
const n = ptr ? c.name.slice(0, -4) : c.name;
|
|
510
|
+
const i = n.indexOf("$$");
|
|
511
|
+
const q = i < 0 ? "main." + n : n.slice(i + 2) + "." + n.slice(0, i);
|
|
512
|
+
return (ptr || v.__v !== true && typeof v.__gfUnbox !== "function" ? "*" : "") + q;
|
|
513
|
+
}
|
|
514
|
+
return typeof v === "function" ? "func()" : "map[string]interface {}";
|
|
515
|
+
};
|
|
516
|
+
var __tafail = __tafail || function(src, v, target, methods) {
|
|
517
|
+
if (methods) {
|
|
518
|
+
if (v === null || v === undefined) return new Error("interface conversion: interface is nil, not " + target);
|
|
519
|
+
const m = methods.find((n) => typeof v[n] !== "function") ?? methods[0];
|
|
520
|
+
return new Error("interface conversion: " + __dtn(v) + " is not " + target + ": missing method " + m);
|
|
521
|
+
}
|
|
522
|
+
return new Error("interface conversion: " + src + " is " + __dtn(v) + ", not " + target);
|
|
424
523
|
};`;
|
|
425
524
|
|
|
426
525
|
// Nil-interface method call guard (strict mode only): matches Go's panic
|
|
427
526
|
// message instead of a JS TypeError.
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
export const HELPER_SHIFT = `var
|
|
527
|
+
// 64-bit shifts: count is converted to BigInt; negative count panics;
|
|
528
|
+
// wraps with BigInt.asIntN / BigInt.asUintN.
|
|
529
|
+
export const HELPER_SHIFT = `var __shc = __shc || function(n) {
|
|
431
530
|
if (n < 0) throw new Error("runtime error: negative shift amount");
|
|
432
|
-
|
|
433
|
-
|
|
531
|
+
return n;
|
|
532
|
+
};
|
|
533
|
+
var __shl64 = __shl64 || function(x, n, u) {
|
|
534
|
+
var b = BigInt(n);
|
|
535
|
+
if (b < 0n) throw new Error("runtime error: negative shift amount");
|
|
536
|
+
if (typeof x === "bigint") {
|
|
537
|
+
if (b >= 64n) return 0n;
|
|
538
|
+
var bx = u ? BigInt.asUintN(64, x) : BigInt.asIntN(64, x);
|
|
539
|
+
var r = bx << b;
|
|
540
|
+
return u ? BigInt.asUintN(64, r) : BigInt.asIntN(64, r);
|
|
541
|
+
}
|
|
542
|
+
if (b >= 64n) return 0;
|
|
543
|
+
var nb = Number(b);
|
|
544
|
+
var r = x * 2 ** nb;
|
|
434
545
|
if (Number.isSafeInteger(r)) return r;
|
|
435
|
-
|
|
436
|
-
return Number(u ? BigInt.asUintN(64,
|
|
546
|
+
var bxx = BigInt(Math.trunc(x)) << b;
|
|
547
|
+
return Number(u ? BigInt.asUintN(64, bxx) : BigInt.asIntN(64, bxx));
|
|
437
548
|
};
|
|
438
549
|
var __shr64 = __shr64 || function(x, n, u) {
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
|
|
550
|
+
var b = BigInt(n);
|
|
551
|
+
if (b < 0n) throw new Error("runtime error: negative shift amount");
|
|
552
|
+
if (typeof x === "bigint") {
|
|
553
|
+
var bx = u ? BigInt.asUintN(64, x) : BigInt.asIntN(64, x);
|
|
554
|
+
if (b >= 64n) return u || bx >= 0n ? 0n : -1n;
|
|
555
|
+
var r = bx >> b;
|
|
556
|
+
return u ? BigInt.asUintN(64, r) : BigInt.asIntN(64, r);
|
|
557
|
+
}
|
|
558
|
+
if (b >= 64n) return u || x >= 0 ? 0 : -1;
|
|
559
|
+
return Math.floor(x / 2 ** Number(b));
|
|
560
|
+
};`;
|
|
561
|
+
|
|
562
|
+
export const HELPER_TO64 = `var __to_i64 = __to_i64 || function(v) {
|
|
563
|
+
if (typeof v === "bigint") return BigInt.asIntN(64, v);
|
|
564
|
+
return Number.isFinite(v) ? BigInt.asIntN(64, BigInt(Math.trunc(v))) : -9223372036854775808n;
|
|
565
|
+
};
|
|
566
|
+
var __to_u64 = __to_u64 || function(v) {
|
|
567
|
+
if (typeof v === "bigint") return BigInt.asUintN(64, v);
|
|
568
|
+
return Number.isFinite(v) ? BigInt.asUintN(64, BigInt(Math.trunc(v))) : 9223372036854775808n;
|
|
442
569
|
};`;
|
|
443
570
|
|
|
444
571
|
export const HELPER_NIL_CALL = `var __nilcall = __nilcall || function(x) {
|
|
@@ -473,27 +600,87 @@ var __zn = __zn || (() => null);
|
|
|
473
600
|
var __z0 = __z0 || (() => 0);
|
|
474
601
|
var __zs = __zs || (() => "");
|
|
475
602
|
var __zf = __zf || (() => false);
|
|
603
|
+
var __z64 = __z64 || Object.assign(() => 0n, { k: "int64" });
|
|
604
|
+
var __zu64 = __zu64 || Object.assign(() => 0n, { k: "uint64" });
|
|
605
|
+
var __tbox = __tbox || function(f, x) {
|
|
606
|
+
return f && f.b ? f.b(x) : x;
|
|
607
|
+
};
|
|
476
608
|
var __ti = __ti || function(f, k, id, is, u, b, fb) {
|
|
477
609
|
const g = () => f();
|
|
478
610
|
g.k = k; g.id = id; g.is = is; g.u = u; g.b = b; g.fb = fb;
|
|
479
611
|
return g;
|
|
480
612
|
};
|
|
613
|
+
var __tar = __tar || function(f, op, a, b) {
|
|
614
|
+
const k = f?.k;
|
|
615
|
+
const dz = () => { throw new Error("runtime error: integer divide by zero"); };
|
|
616
|
+
const ns = () => { throw new Error("runtime error: negative shift amount"); };
|
|
617
|
+
if (typeof a === "bigint") {
|
|
618
|
+
const sh = op === "<<" || op === ">>";
|
|
619
|
+
if (sh) { b = Number(b); if (b < 0) ns(); }
|
|
620
|
+
else if (typeof b !== "bigint") b = BigInt(b);
|
|
621
|
+
const w = k === "uint64" ? (v) => BigInt.asUintN(64, v) : (v) => BigInt.asIntN(64, v);
|
|
622
|
+
switch (op) {
|
|
623
|
+
case "+": return w(a + b);
|
|
624
|
+
case "-": return w(a - b);
|
|
625
|
+
case "*": return w(a * b);
|
|
626
|
+
case "/": return b === 0n ? dz() : w(a / b);
|
|
627
|
+
case "%": return b === 0n ? dz() : w(a % b);
|
|
628
|
+
case "&": return w(a & b);
|
|
629
|
+
case "|": return w(a | b);
|
|
630
|
+
case "^": return w(a ^ b);
|
|
631
|
+
case "&^": return w(a & ~b);
|
|
632
|
+
case "<<": return b >= 64 ? 0n : w(a << BigInt(b));
|
|
633
|
+
default: return b >= 64 ? (k === "uint64" || a >= 0n ? 0n : -1n) : w(a >> BigInt(b));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
let bits = 0, signed = true;
|
|
637
|
+
switch (k) {
|
|
638
|
+
case "int8": bits = 8; break;
|
|
639
|
+
case "int16": bits = 16; break;
|
|
640
|
+
case "int32": case "rune": bits = 32; break;
|
|
641
|
+
case "uint8": case "byte": bits = 8; signed = false; break;
|
|
642
|
+
case "uint16": bits = 16; signed = false; break;
|
|
643
|
+
case "uint32": bits = 32; signed = false; break;
|
|
644
|
+
}
|
|
645
|
+
const w = bits === 0 ? (v) => v
|
|
646
|
+
: bits === 32 ? (signed ? (v) => v | 0 : (v) => v >>> 0)
|
|
647
|
+
: signed ? (v) => (v << (32 - bits)) >> (32 - bits)
|
|
648
|
+
: (v) => v & ((1 << bits) - 1);
|
|
649
|
+
const int = bits !== 0 || k === "int" || k === "uint" || k === "uintptr";
|
|
650
|
+
switch (op) {
|
|
651
|
+
case "+": return k === "float32" ? Math.fround(a + b) : w(a + b);
|
|
652
|
+
case "-": return k === "float32" ? Math.fround(a - b) : w(a - b);
|
|
653
|
+
case "*": return k === "float32" ? Math.fround(a * b) : bits === 0 ? a * b : w(Math.imul(a, b));
|
|
654
|
+
case "/": return int ? (b === 0 ? dz() : w(Math.trunc(a / b))) : k === "float32" ? Math.fround(a / b) : a / b;
|
|
655
|
+
case "%": return int && b === 0 ? dz() : w(a % b);
|
|
656
|
+
case "&": return bits === 0 ? a & b : w(a & b);
|
|
657
|
+
case "|": return bits === 0 ? a | b : w(a | b);
|
|
658
|
+
case "^": return bits === 0 ? a ^ b : w(a ^ b);
|
|
659
|
+
case "&^": return bits === 0 ? a & ~b : w(a & ~b);
|
|
660
|
+
}
|
|
661
|
+
b = Number(b);
|
|
662
|
+
if (b < 0) ns();
|
|
663
|
+
if (bits === 0) return op === "<<" ? a << b : a >> b;
|
|
664
|
+
if (b >= bits) return op === ">>" && signed && a < 0 ? -1 : 0;
|
|
665
|
+
return op === "<<" ? w(a << b) : signed ? a >> b : a >>> b;
|
|
666
|
+
};
|
|
481
667
|
var __tid = __tid || function(...ids) {
|
|
482
668
|
return ids.every((i) => i !== undefined) ? ids.join(",") : undefined;
|
|
483
669
|
};
|
|
484
670
|
var __tconv = __tconv || function(f, v) {
|
|
485
|
-
v = typeof v === "bigint" ? Number(v) : v;
|
|
486
671
|
switch (f?.k) {
|
|
487
|
-
case "
|
|
488
|
-
case "
|
|
489
|
-
case "
|
|
490
|
-
case "
|
|
491
|
-
case "
|
|
492
|
-
case "
|
|
493
|
-
case "
|
|
494
|
-
case "
|
|
495
|
-
case "
|
|
496
|
-
|
|
672
|
+
case "int64": return typeof v === "bigint" ? BigInt.asIntN(64, v) : (typeof v === "number" ? BigInt.asIntN(64, BigInt(Math.trunc(v))) : v);
|
|
673
|
+
case "uint64": return typeof v === "bigint" ? BigInt.asUintN(64, v) : (typeof v === "number" ? BigInt.asUintN(64, BigInt(Math.trunc(v))) : v);
|
|
674
|
+
case "int": case "uint": case "uintptr": return Math.trunc(Number(typeof v === "bigint" ? Number(v) : v));
|
|
675
|
+
case "int8": return (Number(typeof v === "bigint" ? Number(v) : v) << 24) >> 24;
|
|
676
|
+
case "int16": return (Number(typeof v === "bigint" ? Number(v) : v) << 16) >> 16;
|
|
677
|
+
case "int32": case "rune": return Number(typeof v === "bigint" ? Number(v) : v) | 0;
|
|
678
|
+
case "uint8": case "byte": return Number(typeof v === "bigint" ? Number(v) : v) & 0xFF;
|
|
679
|
+
case "uint16": return Number(typeof v === "bigint" ? Number(v) : v) & 0xFFFF;
|
|
680
|
+
case "uint32": return Number(typeof v === "bigint" ? Number(v) : v) >>> 0;
|
|
681
|
+
case "float32": return Math.fround(Number(typeof v === "bigint" ? Number(v) : v));
|
|
682
|
+
case "float64": return Number(typeof v === "bigint" ? Number(v) : v);
|
|
683
|
+
default: return typeof v === "number" && f && (f() === 0n || typeof f() === "bigint") ? BigInt(v) : v;
|
|
497
684
|
}
|
|
498
685
|
};`;
|
|
499
686
|
|
|
@@ -502,7 +689,7 @@ var __tconv = __tconv || function(f, v) {
|
|
|
502
689
|
// write goes through `__mw`, which panics with Go's message.
|
|
503
690
|
export const HELPER_NIL_MAP = `var __nilmap = __nilmap || Object.freeze(Object.defineProperties({}, { __map: { value: true }, __nilm: { value: true } }));
|
|
504
691
|
var __mw = __mw || function(m) {
|
|
505
|
-
if (m == null || m ===
|
|
692
|
+
if (m == null || m.__nilm === true) throw new Error("assignment to entry in nil map");
|
|
506
693
|
return m;
|
|
507
694
|
};
|
|
508
695
|
var __isnm = __isnm || function(m) {
|
|
@@ -520,14 +707,52 @@ var __isnm = __isnm || function(m) {
|
|
|
520
707
|
// through `toString` to an injective encoding, and the key value is kept in
|
|
521
708
|
// a table so ranging and fmt can recover it.
|
|
522
709
|
export const HELPER_STRUCT_KEY = `var __kt = __kt || new Map();
|
|
710
|
+
var __kcl = __kcl || function(o) {
|
|
711
|
+
if (o === null || typeof o !== "object") return o;
|
|
712
|
+
if (typeof o.__clone === "function") return o.__clone();
|
|
713
|
+
if (ArrayBuffer.isView(o)) return o.slice();
|
|
714
|
+
if (Array.isArray(o)) return o.map(__kcl);
|
|
715
|
+
const c = Object.create(Object.getPrototypeOf(o));
|
|
716
|
+
for (const f of Object.keys(o)) c[f] = __kcl(o[f]);
|
|
717
|
+
return c;
|
|
718
|
+
};
|
|
523
719
|
var __sk = __sk || function(o) {
|
|
524
|
-
const s = "\\u0001" + JSON.stringify(o, (k, v) => typeof v === "bigint" ? v.toString() + "n" : v);
|
|
525
|
-
if (!__kt.has(s)) __kt.set(s,
|
|
720
|
+
const s = "\\u0001" + JSON.stringify(o, (k, v) => typeof v === "bigint" ? v.toString() + "n" : typeof v === "number" && !Number.isFinite(v) ? { $f: String(v) } : v);
|
|
721
|
+
if (!__kt.has(s)) __kt.set(s, __kcl(o));
|
|
722
|
+
return s;
|
|
723
|
+
};
|
|
724
|
+
// Pointer keys compare by identity: a per-object id (a pointer to an element
|
|
725
|
+
// is its container plus index) keys the property, and the pointer is kept
|
|
726
|
+
// in the table so ranging and fmt can recover it.
|
|
727
|
+
var __pids = __pids || new WeakMap();
|
|
728
|
+
var __pidn = __pidn || { n: 0 };
|
|
729
|
+
var __pid = __pid || function(o) {
|
|
730
|
+
let id = __pids.get(o);
|
|
731
|
+
if (id === undefined) __pids.set(o, id = ++__pidn.n);
|
|
732
|
+
return id;
|
|
733
|
+
};
|
|
734
|
+
var __pk = __pk || function(p) {
|
|
735
|
+
if (p === null || p === undefined) return "\\u0001nil";
|
|
736
|
+
const s = "\\u0001*" + (p.__target !== undefined && p.__target !== null ? __pid(p.__target) + ":" + p.__index : __pid(p));
|
|
737
|
+
if (!__kt.has(s)) __kt.set(s, p);
|
|
526
738
|
return s;
|
|
527
739
|
};
|
|
528
|
-
var __ik = __ik || function(k) {
|
|
740
|
+
var __ik = __ik || function(k, tag) {
|
|
529
741
|
const t = typeof k;
|
|
742
|
+
if (k === null || k === undefined) return "\\u0001nil";
|
|
743
|
+
if (tag !== undefined) {
|
|
744
|
+
if (tag === "*") return __pk(k);
|
|
745
|
+
if (tag.charCodeAt(0) === 33) throw new Error("runtime error: hash of unhashable type " + tag.slice(1));
|
|
746
|
+
if (t === "number" || t === "bigint") {
|
|
747
|
+
const s = "\\u0001" + tag + ":" + String(k);
|
|
748
|
+
if (!__kt.has(s)) __kt.set(s, k);
|
|
749
|
+
return s;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
530
752
|
if (t === "number" || t === "boolean" || t === "bigint") return "\\u0001" + t + ":" + String(k);
|
|
753
|
+
// A slice, map or func in an \`any\` carries its type tag: Go cannot hash it.
|
|
754
|
+
if ((t === "object" || t === "function") && typeof k.__t === "string" && /^(\\[\\]|map\\[|func\\()/.test(k.__t))
|
|
755
|
+
throw new Error("runtime error: hash of unhashable type " + k.__t.replace(/ void$/, ""));
|
|
531
756
|
if (k !== null && t === "object" && typeof k.__gfUnbox === "function" && !k.constructor.name.endsWith("$Ptr")) {
|
|
532
757
|
const v = k.__gfUnbox(), vt = typeof v;
|
|
533
758
|
if (vt === "string" || vt === "number" || vt === "boolean" || vt === "bigint") {
|
|
@@ -548,15 +773,44 @@ var __ikt = __ikt || function(f, k, box) {
|
|
|
548
773
|
var __kd = __kd || function(s, copy) {
|
|
549
774
|
if (typeof s !== "string" || s.charCodeAt(0) !== 1) return s;
|
|
550
775
|
const k = __kt.get(s);
|
|
776
|
+
if (s === "\\u0001nil") return null;
|
|
777
|
+
if (k !== undefined && s.charCodeAt(1) === 42) return k;
|
|
551
778
|
if (k === undefined) {
|
|
552
779
|
if (s.startsWith("\\u0001number:")) return Number(s.slice(8));
|
|
553
780
|
if (s.startsWith("\\u0001boolean:")) return s.slice(9) === "true";
|
|
554
781
|
if (s.startsWith("\\u0001bigint:")) return BigInt(s.slice(8));
|
|
555
782
|
return s;
|
|
556
783
|
}
|
|
557
|
-
return copy
|
|
784
|
+
return copy ? __kcl(k) : k;
|
|
785
|
+
};
|
|
786
|
+
var __kdt = __kdt || function(f, s) {
|
|
787
|
+
if (typeof s !== "string") return s;
|
|
788
|
+
const z = f?.();
|
|
789
|
+
switch (typeof z) {
|
|
790
|
+
case "number": return Number(s);
|
|
791
|
+
case "bigint": return BigInt(s);
|
|
792
|
+
case "boolean": return s === "true";
|
|
793
|
+
case "string": return s;
|
|
794
|
+
default: return __kd(s, true);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
// Interface keys of different dynamic types sort by type first: nil, named
|
|
798
|
+
// types, strings, bools, numbers.
|
|
799
|
+
var __krank = __krank || function(v) {
|
|
800
|
+
if (v === null || v === undefined) return 0;
|
|
801
|
+
const t = typeof v;
|
|
802
|
+
if (t === "object" && typeof v.__gfUnbox === "function") return 1;
|
|
803
|
+
return t === "string" ? 2 : t === "boolean" ? 3 : t === "number" || t === "bigint" ? 4 : 5;
|
|
558
804
|
};
|
|
559
805
|
var __kcmp = __kcmp || function(a, b) {
|
|
806
|
+
const ra = __krank(a), rb = __krank(b);
|
|
807
|
+
if (ra !== rb) return ra - rb;
|
|
808
|
+
if (ra === 1) {
|
|
809
|
+
const na = a.constructor.name, nb = b.constructor.name;
|
|
810
|
+
if (na !== nb) return na < nb ? -1 : 1;
|
|
811
|
+
a = a.__gfUnbox();
|
|
812
|
+
b = b.__gfUnbox();
|
|
813
|
+
}
|
|
560
814
|
if (a !== null && b !== null && typeof a === "object" && typeof b === "object") {
|
|
561
815
|
for (const f of Object.keys(a)) {
|
|
562
816
|
const c = __kcmp(a[f], b[f]);
|
|
@@ -572,6 +826,7 @@ var __kcmp = __kcmp || function(a, b) {
|
|
|
572
826
|
export const HELPER_IFEQ = `var __ifeq = __ifeq || function(a, b) {
|
|
573
827
|
if (a === b) return true;
|
|
574
828
|
if (a === null || a === undefined || b === null || b === undefined) return a == null && b == null;
|
|
829
|
+
if (a.__nilp === true && b.__nilp === true && a.__t !== undefined) return a.__t === b.__t;
|
|
575
830
|
if (typeof a === "object" && typeof b === "object" && a.constructor === b.constructor && typeof a.__gfUnbox === "function") {
|
|
576
831
|
return a.__gfUnbox() === b.__gfUnbox();
|
|
577
832
|
}
|
|
@@ -630,6 +885,9 @@ export const HELPER_PTREQ = `var __ptreq = __ptreq || function __ptreq(a, b) {
|
|
|
630
885
|
// currently running its defers; `armed` is set right before a deferred
|
|
631
886
|
// function is invoked and consumed by that function's prologue, so recover()
|
|
632
887
|
// only takes effect when called directly by the deferred function (Go spec).
|
|
888
|
+
// panic(v): a string panics with that message; any other value is kept in
|
|
889
|
+
// the thrown error's pv field so recover() returns it unchanged (an error's
|
|
890
|
+
// message is its Error()).
|
|
633
891
|
export const HELPER_PANIC = `var __gopanic = __gopanic || { stack: [], armed: false };
|
|
634
892
|
var __runDefers = __runDefers || function(defers, frame) {
|
|
635
893
|
for (let i = defers.length - 1; i >= 0; i--) {
|
|
@@ -646,1187 +904,50 @@ var __runDefers = __runDefers || function(defers, frame) {
|
|
|
646
904
|
if (!frame.pn.recovered) throw frame.pn.err;
|
|
647
905
|
}
|
|
648
906
|
};
|
|
907
|
+
var __gopanicv = __gopanicv || function(v) {
|
|
908
|
+
if (typeof v === "string") {
|
|
909
|
+
// The value rides in pv so recover() returns the string itself, never a
|
|
910
|
+
// runtime error value, however the message reads.
|
|
911
|
+
const se = new Error(v);
|
|
912
|
+
se.pv = { v };
|
|
913
|
+
throw se;
|
|
914
|
+
}
|
|
915
|
+
let msg;
|
|
916
|
+
try { msg = typeof v?.Error === "function" ? v.Error() : String(v); } catch { msg = String(v); }
|
|
917
|
+
const e = new Error(msg);
|
|
918
|
+
e.pv = { v };
|
|
919
|
+
throw e;
|
|
920
|
+
};
|
|
649
921
|
var __recover = __recover || function(ok) {
|
|
650
922
|
if (!ok) return null;
|
|
651
923
|
const s = __gopanic.stack;
|
|
652
924
|
const top = s.length > 0 ? s[s.length - 1] : null;
|
|
653
925
|
if (top === null || top.recovered) return null;
|
|
654
926
|
top.recovered = true;
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
const ptrSet = new WeakSet();
|
|
665
|
-
let ptrCounter = 1;
|
|
666
|
-
const getPtr = (o) => {
|
|
667
|
-
let p = ptrMap.get(o);
|
|
668
|
-
if (!p) {
|
|
669
|
-
p = "0x" + (ptrCounter++).toString(16);
|
|
670
|
-
ptrMap.set(o, p);
|
|
671
|
-
}
|
|
672
|
-
return p;
|
|
673
|
-
};
|
|
674
|
-
const markPtr = (o) => {
|
|
675
|
-
if (o !== null && typeof o === "object") ptrSet.add(o);
|
|
676
|
-
};
|
|
677
|
-
// el: o is a value element of a slice, array or map or a struct value field
|
|
678
|
-
// (per the static descriptor), so the __p tag left by an earlier &x does not
|
|
679
|
-
// make it a pointer; only the container's own pointer marking does.
|
|
680
|
-
const isPointer = (o, el) => {
|
|
681
|
-
return o !== null && typeof o === "object" && ((o.__p === true && !el) || ptrSet.has(o));
|
|
682
|
-
};
|
|
683
|
-
const isExported = (k) => /^\\p{Lu}/u.test(k);
|
|
684
|
-
// %#v never calls String (nor, in Go, Error); the Error dispatch stays as it
|
|
685
|
-
// was before Stringer support.
|
|
686
|
-
let sharp = false;
|
|
687
|
-
// The method fmt calls on val: Error before String, and a pointer-receiver
|
|
688
|
-
// method (listed in the class's __pr) only for a pointer, as Go's method sets.
|
|
689
|
-
// __pe maps Error/String to the embedded interface field that provides it.
|
|
690
|
-
const stringMethod = (val, el) => {
|
|
691
|
-
for (const name of sharp ? ["Error"] : ["Error", "String"]) {
|
|
692
|
-
if (typeof val[name] === "function") {
|
|
693
|
-
if (val[name].length !== 0) continue;
|
|
694
|
-
if (!sharp && val.__pr !== undefined && val.__pr.includes(name) && !isPointer(val, el)) continue;
|
|
695
|
-
return name;
|
|
696
|
-
}
|
|
697
|
-
const pe = sharp ? undefined : val.__pe?.[name];
|
|
698
|
-
if (pe !== undefined && typeof val[pe]?.[name] === "function") return name;
|
|
699
|
-
}
|
|
700
|
-
return "";
|
|
701
|
-
};
|
|
702
|
-
// A nil *T boxed in an interface (a named non-struct type) has no value to call
|
|
703
|
-
// a value-receiver method on: fmt prints <nil>, as Go does after recovering.
|
|
704
|
-
const callMethod = (val, name) => {
|
|
705
|
-
if (typeof val[name] !== "function") return val[val.__pe[name]][name]();
|
|
706
|
-
if (typeof val.__gfUnbox !== "function" || val.__gfUnbox() !== null) return val[name]();
|
|
707
|
-
try { return val[name](); } catch (e) { return "<nil>"; }
|
|
708
|
-
};
|
|
709
|
-
// Errors from errors.New/Errorf and the stdlib are plain runtime objects, not
|
|
710
|
-
// instances of a user class; they print their message wherever they are.
|
|
711
|
-
const isRuntimeError = (val) => {
|
|
712
|
-
const proto = Object.getPrototypeOf(val);
|
|
713
|
-
return (proto === null || Object.getPrototypeOf(proto) === null) && typeof val.Error === "function" && val.Error.length === 0;
|
|
714
|
-
};
|
|
715
|
-
// ro: val was reached through an unexported field, where Go cannot call
|
|
716
|
-
// methods on user types. fd: descriptor of val's type when it is not carried
|
|
717
|
-
// by val itself (raw named values and the elements of slices and maps).
|
|
718
|
-
// el: val is a value element or value field, see isPointer.
|
|
719
|
-
// A value can have two descriptors: the Stringer one (see _fmtDesc) and the
|
|
720
|
-
// static type (fmt-types.js, set by __ft). fd is either one, or { $both, t, s }
|
|
721
|
-
// holding both, so typed formatting and Stringer dispatch compose.
|
|
722
|
-
const both = __fmtu.both;
|
|
723
|
-
const formatV = (val, isPlus, isTopLevel, ro, fd, el) => {
|
|
724
|
-
if (typeof __FT !== "undefined" && val instanceof __FT) {
|
|
725
|
-
if (val.t?.n === "time.Duration") {
|
|
726
|
-
return typeof __durationString === "function" ? __durationString(val.v) : String(val.v);
|
|
727
|
-
}
|
|
728
|
-
return formatV(val.v, isPlus, isTopLevel, ro, both(val.t, val.v?.__fd), el);
|
|
729
|
-
}
|
|
730
|
-
const [td, sdesc] = __fmtu.split(fd);
|
|
731
|
-
if (td?.n === "time.Duration") {
|
|
732
|
-
return typeof __durationString === "function" ? __durationString(val) : String(val);
|
|
733
|
-
}
|
|
734
|
-
if (sdesc?.b && !ro && !(val instanceof sdesc.b)) val = new sdesc.b(val);
|
|
735
|
-
if (sdesc?.m === 1 && (val === null || val === undefined)) return "map[]";
|
|
736
|
-
if (sdesc?.np !== undefined && (val === null || val === undefined)) val = sdesc.np;
|
|
737
|
-
if (val === null || val === undefined) return "<nil>";
|
|
738
|
-
if (typeof val === "boolean") return String(val);
|
|
739
|
-
if (typeof val === "number" && td) {
|
|
740
|
-
const fb = __fmtu.baseOf(td);
|
|
741
|
-
if (fb?.k === "b" && __fmtu.isFloatN(fb.n)) return __fmtu.fmtFloat(val, "g", {}, 0, false, -1, false, fb.n === "float32");
|
|
742
|
-
}
|
|
743
|
-
if (typeof val === "number" && Math.abs(val) >= 9007199254740992 && Math.abs(val) < 18446744073709551616 && Number.isInteger(val)) return BigInt(val).toString();
|
|
744
|
-
if (typeof val === "number" || typeof val === "bigint") return Object.is(val, -0) ? "-0" : String(val);
|
|
745
|
-
if (typeof val === "string") return val;
|
|
746
|
-
if (typeof val === "object") {
|
|
747
|
-
if (val._d instanceof Date) {
|
|
748
|
-
return typeof __timeFmt === "function" ? __timeFmt(val, "2006-01-02 15:04:05.999999999 -0700 MST") : String(val._d);
|
|
749
|
-
}
|
|
750
|
-
if ("re" in val && "im" in val) {
|
|
751
|
-
const isNeg = val.im < 0 || Object.is(val.im, -0);
|
|
752
|
-
const sign = isNeg ? "" : "+";
|
|
753
|
-
const imStr = Object.is(val.im, -0) ? "-0" : String(val.im);
|
|
754
|
-
const reStr = Object.is(val.re, -0) ? "-0" : String(val.re);
|
|
755
|
-
return "(" + reStr + sign + imStr + "i)";
|
|
756
|
-
}
|
|
757
|
-
const sm = ro ? (isRuntimeError(val) ? "Error" : "") : stringMethod(val, el);
|
|
758
|
-
if (sm) return String(callMethod(val, sm));
|
|
759
|
-
if (typeof val.__gfUnbox === "function") return formatV(val.__gfUnbox(), isPlus, isTopLevel, ro);
|
|
760
|
-
// fd is either a Stringer descriptor (see _fmtDesc) or, for operands that
|
|
761
|
-
// carry their static type, a type descriptor (fmt-types.js); sd is the
|
|
762
|
-
// latter with pointers and named types resolved.
|
|
763
|
-
const sd = td ? __fmtu.baseOf(td.k === "ptr" ? td.e : td) : null;
|
|
764
|
-
const cd = sdesc ?? val.__fd;
|
|
765
|
-
if (Array.isArray(val) || ArrayBuffer.isView(val)) {
|
|
766
|
-
const isElemPtr = val.__ptr_slice === true;
|
|
767
|
-
const pf = val.__ptr_fields;
|
|
768
|
-
const parts = [];
|
|
769
|
-
for (let j = 0; j < val.length; j++) {
|
|
770
|
-
const item = val[j];
|
|
771
|
-
if (isElemPtr && item !== null && typeof item === "object") {
|
|
772
|
-
markPtr(item);
|
|
773
|
-
} else if (Array.isArray(pf) && item !== null && typeof item === "object") {
|
|
774
|
-
for (const f of pf) {
|
|
775
|
-
if (f.indexOf(".") !== -1) {
|
|
776
|
-
const fparts = f.split(".");
|
|
777
|
-
let cur = item;
|
|
778
|
-
for (let k = 0; k < fparts.length - 1; k++) cur = cur?.[fparts[k]];
|
|
779
|
-
const last = fparts[fparts.length - 1];
|
|
780
|
-
if (cur?.[last] !== null && typeof cur?.[last] === "object") markPtr(cur[last]);
|
|
781
|
-
} else if (item[f] !== null && typeof item[f] === "object") {
|
|
782
|
-
markPtr(item[f]);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
parts.push(formatV(item, isPlus, false, ro, both(sd?.e, cd?.e), cd?.e?.sv === 1));
|
|
787
|
-
}
|
|
788
|
-
return "[" + parts.join(" ") + "]";
|
|
789
|
-
}
|
|
790
|
-
if (val instanceof Map || val.__map === true || sdesc?.m === 1) {
|
|
791
|
-
const isElemPtr = val.__ptr_map === true;
|
|
792
|
-
const parts = [];
|
|
793
|
-
if (val instanceof Map) {
|
|
794
|
-
// Keys of a type with String()/Error() sort by their raw value, as in Go.
|
|
795
|
-
const raw = (k) => (k !== null && typeof k === "object" && typeof k.__gfUnbox === "function" ? k.__gfUnbox() : k);
|
|
796
|
-
const entries = Array.from(val.entries()).sort(([a], [b]) => {
|
|
797
|
-
const k1 = raw(a), k2 = raw(b);
|
|
798
|
-
if (typeof k1 === "number" && typeof k2 === "number") return k1 - k2;
|
|
799
|
-
// Struct and array keys compare field by field, as in Go.
|
|
800
|
-
if (k1 !== null && k2 !== null && typeof k1 === "object" && typeof k2 === "object" && !k1.__p && !k2.__p) {
|
|
801
|
-
const cmp = (x, y) => {
|
|
802
|
-
if (x !== null && y !== null && typeof x === "object" && typeof y === "object") {
|
|
803
|
-
for (const f of Object.keys(x)) {
|
|
804
|
-
const c = cmp(x[f], y[f]);
|
|
805
|
-
if (c !== 0) return c;
|
|
806
|
-
}
|
|
807
|
-
return 0;
|
|
808
|
-
}
|
|
809
|
-
return x < y ? -1 : x > y ? 1 : 0;
|
|
810
|
-
};
|
|
811
|
-
return cmp(k1, k2);
|
|
812
|
-
}
|
|
813
|
-
const na = Number(k1), nb = Number(k2);
|
|
814
|
-
if (!Number.isNaN(na) && !Number.isNaN(nb)) return na - nb;
|
|
815
|
-
return String(k1).localeCompare(String(k2));
|
|
816
|
-
});
|
|
817
|
-
for (const [k, v] of entries) {
|
|
818
|
-
if (isElemPtr && v !== null && typeof v === "object") {
|
|
819
|
-
markPtr(v);
|
|
820
|
-
}
|
|
821
|
-
parts.push(formatV(k, isPlus, false, ro, both(sd?.key, cd?.k), cd?.k?.sv === 1) + ":" + formatV(v, isPlus, false, ro, both(sd?.val, cd?.v), cd?.v?.sv === 1));
|
|
822
|
-
}
|
|
823
|
-
} else {
|
|
824
|
-
const keys = Object.keys(val).sort((a, b) => {
|
|
825
|
-
// Struct keys (encoded, see __sk) sort field by field, as in Go.
|
|
826
|
-
if (a.charCodeAt(0) === 1 && b.charCodeAt(0) === 1 && typeof __kd === "function")
|
|
827
|
-
return __kcmp(__kd(a), __kd(b));
|
|
828
|
-
const na = Number(a), nb = Number(b);
|
|
829
|
-
if (!Number.isNaN(na) && !Number.isNaN(nb)) return na - nb;
|
|
830
|
-
if (a[0] === "{" && b[0] === "{") {
|
|
831
|
-
// Struct keys (their %v text) sort field by field, as in Go.
|
|
832
|
-
const ta = a.slice(1, -1).split(/[ {}]+/), tb = b.slice(1, -1).split(/[ {}]+/);
|
|
833
|
-
for (let i = 0; i < ta.length && i < tb.length; i++) {
|
|
834
|
-
if (ta[i] === tb[i]) continue;
|
|
835
|
-
const x = Number(ta[i]), y = Number(tb[i]);
|
|
836
|
-
if (ta[i] !== "" && tb[i] !== "" && !Number.isNaN(x) && !Number.isNaN(y)) return x - y;
|
|
837
|
-
return ta[i].localeCompare(tb[i]);
|
|
838
|
-
}
|
|
839
|
-
return ta.length - tb.length;
|
|
840
|
-
}
|
|
841
|
-
return a.localeCompare(b);
|
|
842
|
-
});
|
|
843
|
-
for (const k of keys) {
|
|
844
|
-
const v = val[k];
|
|
845
|
-
if (isElemPtr && v !== null && typeof v === "object") {
|
|
846
|
-
markPtr(v);
|
|
847
|
-
}
|
|
848
|
-
const kv = k.charCodeAt(0) === 1 && typeof __kd === "function" ? __kd(k) : ((sd && __fmtu.isNumKey(sd.key)) || cd?.k?.n) ? Number(k) : k;
|
|
849
|
-
parts.push(formatV(kv, isPlus, false, ro, both(sd?.key, cd?.k), cd?.k?.sv === 1) + ":" + formatV(v, isPlus, false, ro, both(sd?.val, cd?.v), cd?.v?.sv === 1));
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
return "map[" + parts.join(" ") + "]";
|
|
853
|
-
}
|
|
854
|
-
if ("value" in val && (val.__box === true || (!val.__struct && !("__v" in val) && Object.keys(val).length === 1 && (val.constructor === Object || !val.constructor || val.constructor?.name === "Object")))) {
|
|
855
|
-
return getPtr(val);
|
|
856
|
-
}
|
|
857
|
-
const isPtr = isPointer(val, el);
|
|
858
|
-
if (isPtr) {
|
|
859
|
-
if (!isTopLevel) {
|
|
860
|
-
return getPtr(val);
|
|
861
|
-
}
|
|
862
|
-
getPtr(val);
|
|
863
|
-
}
|
|
864
|
-
const prefix = isPtr ? "&{" : "{";
|
|
865
|
-
const keys = __fmtu.keys(val);
|
|
866
|
-
const parts = [];
|
|
867
|
-
const ff = typeof val.__ff === "function" ? val.__ff() : (sdesc?.ff ?? null);
|
|
868
|
-
for (const k of keys) {
|
|
869
|
-
const fk = both(sd?.f?.find((x) => x[0] === k)?.[1], ff?.[k]);
|
|
870
|
-
const fv = formatV(val[k], isPlus, false, ro || !isExported(k), fk, ff?.[k]?.sv === 1);
|
|
871
|
-
parts.push(isPlus ? k + ":" + fv : fv);
|
|
872
|
-
}
|
|
873
|
-
return prefix + parts.join(" ") + "}";
|
|
874
|
-
}
|
|
875
|
-
// A func value prints as an address; the targets share one fixed text.
|
|
876
|
-
if (typeof val === "function") return "0x1";
|
|
877
|
-
return String(val);
|
|
878
|
-
};
|
|
879
|
-
` +
|
|
880
|
-
HELPER_FMT_LOOP;
|
|
881
|
-
|
|
882
|
-
// fmt.Sprint/Print/Append: a space goes between two operands when neither is a
|
|
883
|
-
// string; `ln` (Sprintln, Println, Appendln) separates always and ends with a newline.
|
|
884
|
-
export const HELPER_SPRINT = `var __sprint = __sprint || function(ln, ...a) {
|
|
885
|
-
const isStr = (x) => typeof x === "string" || (x !== null && typeof x === "object" && typeof x.__gfUnbox === "function" && typeof x.__gfUnbox() === "string");
|
|
886
|
-
let f = "";
|
|
887
|
-
for (let i = 0; i < a.length; i++) {
|
|
888
|
-
if (i > 0 && (ln || (!isStr(a[i - 1]) && !isStr(a[i])))) f += " ";
|
|
889
|
-
f += "%v";
|
|
890
|
-
}
|
|
891
|
-
return __sprintf(ln ? f + "\\n" : f, ...a);
|
|
927
|
+
const e = top.err;
|
|
928
|
+
if (e && e.pv) return e.pv.v;
|
|
929
|
+
// A JS TypeError from using null as a pointer is Go's nil dereference.
|
|
930
|
+
if (e && e.name === "TypeError" && /of null|undefined or null/.test(e.message))
|
|
931
|
+
return __error("runtime error: invalid memory address or nil pointer dereference");
|
|
932
|
+
const msg = e?.message ?? String(e);
|
|
933
|
+
// A Go runtime panic recovers as an error value (runtime.Error).
|
|
934
|
+
if (/^(runtime error: |assignment to entry in nil map$|interface conversion: )/.test(msg)) return __error(msg);
|
|
935
|
+
return msg;
|
|
892
936
|
};`;
|
|
893
937
|
|
|
938
|
+
// A runtime error value (\`fmt.Errorf\`, parse failures, io.EOF). A wrapped
|
|
939
|
+
// cause is exposed through \`Unwrap() error\`; an array of causes (several %w
|
|
940
|
+
// verbs) through \`Unwrap() []error\`, tagged \`__multi\` so type assertions tell
|
|
941
|
+
// the two apart.
|
|
894
942
|
export const HELPER_ERROR = `var __error = __error || function(msg, cause) {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
export const HELPER_PATH_ERROR = `var __path_err_bad_pattern = __path_err_bad_pattern || __error("syntax error in pattern");`;
|
|
902
|
-
|
|
903
|
-
export const HELPER_IO_EOF = `var __io_eof = __io_eof || __error("EOF");`;
|
|
904
|
-
|
|
905
|
-
export const HELPER_OS = `var __os_buf = "";
|
|
906
|
-
var __os_write = __os_write || function(s, isErr) {
|
|
907
|
-
if (typeof process !== "undefined" && process?.stdout?.write) {
|
|
908
|
-
process.stdout.write(s);
|
|
909
|
-
return [s.length, null];
|
|
910
|
-
}
|
|
911
|
-
__os_buf += s;
|
|
912
|
-
const nl = __os_buf.lastIndexOf(String.fromCharCode(10));
|
|
913
|
-
if (nl >= 0) {
|
|
914
|
-
const fn = (isErr && typeof console.error === "function") ? console.error : console.log;
|
|
915
|
-
fn(__os_buf.slice(0, nl));
|
|
916
|
-
__os_buf = __os_buf.slice(nl + 1);
|
|
917
|
-
}
|
|
918
|
-
return [s.length, null];
|
|
919
|
-
};
|
|
920
|
-
var __os_file = __os_file || class {
|
|
921
|
-
constructor(fd) { this.fd = fd; }
|
|
922
|
-
WriteString(s) { return __os_write(s, this.fd === 2); }
|
|
923
|
-
Write(b) {
|
|
924
|
-
const s = typeof b === "string" ? b : new TextDecoder().decode(b);
|
|
925
|
-
__os_write(s, this.fd === 2);
|
|
926
|
-
const n = typeof b === "string" ? s.length : (b?.byteLength ?? b?.length ?? s.length);
|
|
927
|
-
return [n, null];
|
|
928
|
-
}
|
|
929
|
-
Read(b) { return [0, typeof __io_eof !== "undefined" ? __io_eof : __error("EOF")]; }
|
|
930
|
-
Close() { return null; }
|
|
931
|
-
};
|
|
932
|
-
var __os_stdout = __os_stdout || new __os_file(1);
|
|
933
|
-
var __os_stderr = __os_stderr || new __os_file(2);
|
|
934
|
-
var __os_stdin = __os_stdin || new __os_file(0);
|
|
935
|
-
`;
|
|
936
|
-
|
|
937
|
-
export const HELPER_ERROR_IS = `var __errorIs = __errorIs || function __errorIs(err, target) {
|
|
938
|
-
if (err === null || err === undefined) return false;
|
|
939
|
-
if (err === target) return true;
|
|
940
|
-
if (typeof err === "object" && typeof target === "object" && target !== null &&
|
|
941
|
-
typeof err.__gfUnbox === "function" && err.constructor === target.constructor &&
|
|
942
|
-
err.__gfUnbox() === target.__gfUnbox()) return true;
|
|
943
|
-
if (typeof err === "object" && typeof target === "object" &&
|
|
944
|
-
err._msg !== undefined && target._msg !== undefined &&
|
|
945
|
-
err._msg === target._msg) return true;
|
|
946
|
-
if (typeof err.Is === "function" && err.Is(target)) return true;
|
|
947
|
-
if (Array.isArray(err._errs)) {
|
|
948
|
-
for (const sub of err._errs) {
|
|
949
|
-
if (__errorIs(sub, target)) return true;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
if (typeof err.Unwrap === "function") {
|
|
953
|
-
const unwrapped = err.Unwrap();
|
|
954
|
-
if (Array.isArray(unwrapped)) {
|
|
955
|
-
for (const sub of unwrapped) {
|
|
956
|
-
if (__errorIs(sub, target)) return true;
|
|
957
|
-
}
|
|
958
|
-
} else if (unwrapped !== null && unwrapped !== undefined) {
|
|
959
|
-
if (__errorIs(unwrapped, target)) return true;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
if (err._cause !== undefined && err._cause !== null) {
|
|
963
|
-
return __errorIs(err._cause, target);
|
|
964
|
-
}
|
|
965
|
-
return false;
|
|
966
|
-
};`;
|
|
967
|
-
|
|
968
|
-
export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, target, matcher, extract) {
|
|
969
|
-
if (err === null || err === undefined || target === null || typeof target !== "object") return false;
|
|
970
|
-
let cur = err;
|
|
971
|
-
while (cur !== null && cur !== undefined) {
|
|
972
|
-
const unboxed = cur?.value ?? cur;
|
|
973
|
-
if (typeof cur.As === "function" && cur.As(target)) return true;
|
|
974
|
-
if (matcher ? matcher(unboxed) : (unboxed !== err && typeof unboxed === "object" && !("_msg" in unboxed && "_cause" in unboxed))) {
|
|
975
|
-
if ("value" in target) {
|
|
976
|
-
target.value = extract ? extract(unboxed) : unboxed;
|
|
977
|
-
} else {
|
|
978
|
-
Object.assign(target, unboxed);
|
|
979
|
-
}
|
|
980
|
-
return true;
|
|
981
|
-
}
|
|
982
|
-
if (Array.isArray(cur._errs)) {
|
|
983
|
-
for (const sub of cur._errs) {
|
|
984
|
-
if (__errorAs(sub, target, matcher, extract)) return true;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
if (typeof cur.Unwrap === "function") {
|
|
988
|
-
const unwrapped = cur.Unwrap();
|
|
989
|
-
if (Array.isArray(unwrapped)) {
|
|
990
|
-
for (const sub of unwrapped) {
|
|
991
|
-
if (__errorAs(sub, target, matcher, extract)) return true;
|
|
992
|
-
}
|
|
993
|
-
} else if (unwrapped !== null && unwrapped !== undefined) {
|
|
994
|
-
if (__errorAs(unwrapped, target, matcher, extract)) return true;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
cur = cur?._cause ?? null;
|
|
998
|
-
}
|
|
999
|
-
return false;
|
|
1000
|
-
};`;
|
|
1001
|
-
|
|
1002
|
-
export const HELPER_ERROR_JOIN = `var __errorJoin = __errorJoin || function(...errs) {
|
|
1003
|
-
const filtered = [];
|
|
1004
|
-
for (const e of errs) {
|
|
1005
|
-
if (Array.isArray(e)) {
|
|
1006
|
-
for (const sub of e) if (sub !== null && sub !== undefined) filtered.push(sub);
|
|
1007
|
-
} else if (e !== null && e !== undefined) {
|
|
1008
|
-
filtered.push(e);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
if (filtered.length === 0) return null;
|
|
1012
|
-
const msg = filtered.map(e => (typeof e === "object" && typeof e.Error === "function") ? e.Error() : String(e)).join("\\n");
|
|
1013
|
-
const joined = __error(msg);
|
|
1014
|
-
joined._errs = filtered;
|
|
1015
|
-
joined.Unwrap = function() { return filtered; };
|
|
1016
|
-
joined.Unwrap.__multi = true;
|
|
1017
|
-
return joined;
|
|
1018
|
-
};`;
|
|
1019
|
-
|
|
1020
|
-
// Go-semantics strconv parsers shared by the JS backend and the wasm runtime
|
|
1021
|
-
// imports (boundary.js), so both targets agree. Each parser returns
|
|
1022
|
-
// [value, errorMessage | null]; integer values are BigInt (the wasm side
|
|
1023
|
-
// needs i64, the JS side converts with Number()).
|
|
1024
|
-
export const HELPER_STRCONV = `var __strconv_atoi = __strconv_atoi || function(s) {
|
|
1025
|
-
if (!/^[+-]?[0-9]+$/.test(s)) return [0n, 'strconv.Atoi: parsing "' + s + '": invalid syntax'];
|
|
1026
|
-
const v = BigInt(s);
|
|
1027
|
-
if (v > 9223372036854775807n || v < -9223372036854775808n) {
|
|
1028
|
-
return [v > 0n ? 9223372036854775807n : -9223372036854775808n, 'strconv.Atoi: parsing "' + s + '": value out of range'];
|
|
1029
|
-
}
|
|
1030
|
-
return [v, null];
|
|
1031
|
-
};
|
|
1032
|
-
var __strconv_parse_int = __strconv_parse_int || function(s, base, bits) {
|
|
1033
|
-
let str = s, neg = false;
|
|
1034
|
-
if (str[0] === "-" || str[0] === "+") { neg = str[0] === "-"; str = str.slice(1); }
|
|
1035
|
-
if (base === 0) {
|
|
1036
|
-
if (/^0[xX]/.test(str)) { base = 16; str = str.slice(2); }
|
|
1037
|
-
else if (/^0[bB]/.test(str)) { base = 2; str = str.slice(2); }
|
|
1038
|
-
else if (/^0[oO]/.test(str)) { base = 8; str = str.slice(2); }
|
|
1039
|
-
else if (/^0[0-9]/.test(str)) { base = 8; str = str.slice(1); }
|
|
1040
|
-
else base = 10;
|
|
1041
|
-
str = str.replaceAll("_", "");
|
|
1042
|
-
}
|
|
1043
|
-
if (base < 2 || base > 36) return [0n, 'strconv.ParseInt: parsing "' + s + '": invalid base ' + base];
|
|
1044
|
-
const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base);
|
|
1045
|
-
if (str === "" || [...str.toLowerCase()].some((c) => !digits.includes(c))) {
|
|
1046
|
-
return [0n, 'strconv.ParseInt: parsing "' + s + '": invalid syntax'];
|
|
1047
|
-
}
|
|
1048
|
-
let v = 0n; const B = BigInt(base);
|
|
1049
|
-
for (const c of str.toLowerCase()) v = v * B + BigInt(digits.indexOf(c));
|
|
1050
|
-
if (neg) v = -v;
|
|
1051
|
-
const w = bits === 0 ? 64 : bits;
|
|
1052
|
-
const max = (1n << BigInt(w - 1)) - 1n, min = -(1n << BigInt(w - 1));
|
|
1053
|
-
if (v > max || v < min) return [v > max ? max : min, 'strconv.ParseInt: parsing "' + s + '": value out of range'];
|
|
1054
|
-
return [v, null];
|
|
1055
|
-
};
|
|
1056
|
-
var __strconv_parse_uint = __strconv_parse_uint || function(s, base, bits) {
|
|
1057
|
-
let str = s;
|
|
1058
|
-
if (str[0] === "+") { str = str.slice(1); }
|
|
1059
|
-
if (str[0] === "-") {
|
|
1060
|
-
return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid syntax'];
|
|
1061
|
-
}
|
|
1062
|
-
if (base === 0) {
|
|
1063
|
-
if (/^0[xX]/.test(str)) { base = 16; str = str.slice(2); }
|
|
1064
|
-
else if (/^0[bB]/.test(str)) { base = 2; str = str.slice(2); }
|
|
1065
|
-
else if (/^0[oO]/.test(str)) { base = 8; str = str.slice(2); }
|
|
1066
|
-
else if (/^0[0-9]/.test(str)) { base = 8; str = str.slice(1); }
|
|
1067
|
-
else base = 10;
|
|
1068
|
-
str = str.replaceAll("_", "");
|
|
1069
|
-
}
|
|
1070
|
-
if (base < 2 || base > 36) return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid base ' + base];
|
|
1071
|
-
const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base);
|
|
1072
|
-
if (str === "" || [...str.toLowerCase()].some((c) => !digits.includes(c))) {
|
|
1073
|
-
return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid syntax'];
|
|
1074
|
-
}
|
|
1075
|
-
let v = 0n; const B = BigInt(base);
|
|
1076
|
-
for (const c of str.toLowerCase()) v = v * B + BigInt(digits.indexOf(c));
|
|
1077
|
-
const w = bits === 0 ? 64 : bits;
|
|
1078
|
-
const max = w >= 64 ? 18446744073709551615n : (1n << BigInt(w)) - 1n;
|
|
1079
|
-
if (v > max) return [max, 'strconv.ParseUint: parsing "' + s + '": value out of range'];
|
|
1080
|
-
return [v, null];
|
|
1081
|
-
};
|
|
1082
|
-
var __strconv_parse_float = __strconv_parse_float || function(s) {
|
|
1083
|
-
const str = s.replaceAll("_", "");
|
|
1084
|
-
if (/^[+-]?(inf|infinity)$/i.test(str)) return [str[0] === "-" ? -Infinity : Infinity, null];
|
|
1085
|
-
if (/^[+-]?nan$/i.test(str)) return [NaN, null];
|
|
1086
|
-
if (str === "" || !/^[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?$|^[+-]?0[xX][0-9a-fA-F]+$/.test(str)) {
|
|
1087
|
-
return [0, 'strconv.ParseFloat: parsing "' + s + '": invalid syntax'];
|
|
1088
|
-
}
|
|
1089
|
-
return [Number(str), null];
|
|
1090
|
-
};
|
|
1091
|
-
var __strconv_parse_bool = __strconv_parse_bool || function(s) {
|
|
1092
|
-
if (["1", "t", "T", "TRUE", "true", "True"].includes(s)) return [true, null];
|
|
1093
|
-
if (["0", "f", "F", "FALSE", "false", "False"].includes(s)) return [false, null];
|
|
1094
|
-
return [false, 'strconv.ParseBool: parsing "' + s + '": invalid syntax'];
|
|
1095
|
-
};
|
|
1096
|
-
var __strconv_format_float = __strconv_format_float || function(f, fmtc, prec) {
|
|
1097
|
-
const c = String.fromCharCode(fmtc);
|
|
1098
|
-
if (!Number.isFinite(f)) return f !== f ? "NaN" : (f > 0 ? "+Inf" : "-Inf");
|
|
1099
|
-
if (c === "f") return prec < 0 ? String(f) : f.toFixed(prec);
|
|
1100
|
-
if (c === "e" || c === "E") {
|
|
1101
|
-
const r = prec < 0 ? f.toExponential() : f.toExponential(prec);
|
|
1102
|
-
const o = r.replace(/e([+-])(\\d)$/, "e$10$2");
|
|
1103
|
-
return c === "E" ? o.toUpperCase() : o;
|
|
1104
|
-
}
|
|
1105
|
-
if (c === "g" || c === "G") {
|
|
1106
|
-
const r = prec < 0 ? String(f) : f.toPrecision(prec);
|
|
1107
|
-
return c === "G" ? r.toUpperCase() : r;
|
|
1108
|
-
}
|
|
1109
|
-
return String(f);
|
|
1110
|
-
};`;
|
|
1111
|
-
|
|
1112
|
-
export const HELPER_PATH_CLEAN = `var __pathClean = __pathClean || function(p) {
|
|
1113
|
-
if (!p) return ".";
|
|
1114
|
-
const abs = p.startsWith("/");
|
|
1115
|
-
const parts = p.split("/").reduce((acc, s) => {
|
|
1116
|
-
if (s === "" || s === ".") return acc;
|
|
1117
|
-
if (s === "..") {
|
|
1118
|
-
if (acc.length && acc[acc.length - 1] !== "..") acc.pop();
|
|
1119
|
-
else if (!abs) acc.push("..");
|
|
1120
|
-
} else acc.push(s);
|
|
1121
|
-
return acc;
|
|
1122
|
-
}, []);
|
|
1123
|
-
return (abs ? "/" : "") + (parts.join("/") || ".");
|
|
1124
|
-
};
|
|
1125
|
-
var __pathMatch = __pathMatch || function(pat, name) {
|
|
1126
|
-
let rx = "^";
|
|
1127
|
-
let hasErr = false;
|
|
1128
|
-
let i = 0;
|
|
1129
|
-
while (i < pat.length) {
|
|
1130
|
-
const c = pat[i];
|
|
1131
|
-
if (c === "\\\\") {
|
|
1132
|
-
if (i + 1 >= pat.length) { hasErr = true; break; }
|
|
1133
|
-
const next = pat[++i];
|
|
1134
|
-
if (/[.^$*+?()|{}\\[\\]\\\\]/.test(next)) rx += "\\\\" + next;
|
|
1135
|
-
else rx += next;
|
|
1136
|
-
i++;
|
|
1137
|
-
} else if (c === "*") {
|
|
1138
|
-
rx += "[^/]*";
|
|
1139
|
-
i++;
|
|
1140
|
-
} else if (c === "?") {
|
|
1141
|
-
rx += "[^/]";
|
|
1142
|
-
i++;
|
|
1143
|
-
} else if (c === "[") {
|
|
1144
|
-
i++;
|
|
1145
|
-
let negated = false;
|
|
1146
|
-
if (i < pat.length && pat[i] === "^") {
|
|
1147
|
-
negated = true;
|
|
1148
|
-
i++;
|
|
1149
|
-
}
|
|
1150
|
-
if (i >= pat.length || pat[i] === "]") {
|
|
1151
|
-
return [false, true];
|
|
1152
|
-
}
|
|
1153
|
-
let classContent = "";
|
|
1154
|
-
let closed = false;
|
|
1155
|
-
while (i < pat.length) {
|
|
1156
|
-
let ch = pat[i];
|
|
1157
|
-
if (ch === "]") {
|
|
1158
|
-
closed = true;
|
|
1159
|
-
i++;
|
|
1160
|
-
break;
|
|
1161
|
-
}
|
|
1162
|
-
if (ch === "\\\\") {
|
|
1163
|
-
if (i + 1 >= pat.length) { hasErr = true; break; }
|
|
1164
|
-
ch = pat[++i];
|
|
1165
|
-
}
|
|
1166
|
-
if (ch === "/") {
|
|
1167
|
-
return [false, true];
|
|
1168
|
-
}
|
|
1169
|
-
i++;
|
|
1170
|
-
if (i + 1 < pat.length && pat[i] === "-" && pat[i + 1] !== "]") {
|
|
1171
|
-
i++;
|
|
1172
|
-
let end = pat[i];
|
|
1173
|
-
if (end === "\\\\") {
|
|
1174
|
-
if (i + 1 >= pat.length) { hasErr = true; break; }
|
|
1175
|
-
end = pat[++i];
|
|
1176
|
-
}
|
|
1177
|
-
if (end === "/") return [false, true];
|
|
1178
|
-
i++;
|
|
1179
|
-
if (ch.charCodeAt(0) > end.charCodeAt(0)) return [false, true];
|
|
1180
|
-
if (ch.charCodeAt(0) <= 47 && 47 <= end.charCodeAt(0)) return [false, true];
|
|
1181
|
-
const isSpec = (c) => c === "-" || c === "^" || c === "\\\\" || c === "[" || c === "]";
|
|
1182
|
-
const escCh = isSpec(ch) ? "\\\\" + ch : ch;
|
|
1183
|
-
const escEnd = isSpec(end) ? "\\\\" + end : end;
|
|
1184
|
-
classContent += escCh + "-" + escEnd;
|
|
1185
|
-
} else {
|
|
1186
|
-
const isSpec = (c) => c === "-" || c === "^" || c === "\\\\" || c === "[" || c === "]";
|
|
1187
|
-
const escCh = isSpec(ch) ? "\\\\" + ch : ch;
|
|
1188
|
-
classContent += escCh;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
if (!closed || hasErr) return [false, true];
|
|
1192
|
-
if (negated) {
|
|
1193
|
-
rx += "[^/" + classContent + "]";
|
|
1194
|
-
} else {
|
|
1195
|
-
rx += "[" + classContent + "]";
|
|
1196
|
-
}
|
|
1197
|
-
} else if (/[.^$*+?()|{}\\[\\]\\\\]/.test(c)) {
|
|
1198
|
-
rx += "\\\\" + c;
|
|
1199
|
-
i++;
|
|
1200
|
-
} else {
|
|
1201
|
-
rx += c;
|
|
1202
|
-
i++;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
if (hasErr) return [false, true];
|
|
1206
|
-
try {
|
|
1207
|
-
const re = new RegExp(rx + "$");
|
|
1208
|
-
return [re.test(name), false];
|
|
1209
|
-
} catch (e) {
|
|
1210
|
-
return [false, true];
|
|
1211
|
-
}
|
|
1212
|
-
};`;
|
|
1213
|
-
|
|
1214
|
-
export const HELPER_TIME_FMT = `var __timeLocalDt = __timeLocalDt || function(t) {
|
|
1215
|
-
const dt = t instanceof Date ? t : (t?._d ?? t);
|
|
1216
|
-
if (typeof t?._offset === "number") {
|
|
1217
|
-
return new Date(dt.getTime() + t._offset * 1000);
|
|
1218
|
-
}
|
|
1219
|
-
return null;
|
|
1220
|
-
};
|
|
1221
|
-
var __timeYear = __timeYear || function(t) {
|
|
1222
|
-
var ld = __timeLocalDt(t);
|
|
1223
|
-
return ld ? ld.getUTCFullYear() : (t instanceof Date ? t : t._d).getFullYear();
|
|
1224
|
-
};
|
|
1225
|
-
var __timeMonth = __timeMonth || function(t) {
|
|
1226
|
-
var ld = __timeLocalDt(t);
|
|
1227
|
-
return (ld ? ld.getUTCMonth() : (t instanceof Date ? t : t._d).getMonth()) + 1;
|
|
1228
|
-
};
|
|
1229
|
-
var __timeDay = __timeDay || function(t) {
|
|
1230
|
-
var ld = __timeLocalDt(t);
|
|
1231
|
-
return ld ? ld.getUTCDate() : (t instanceof Date ? t : t._d).getDate();
|
|
1232
|
-
};
|
|
1233
|
-
var __timeHour = __timeHour || function(t) {
|
|
1234
|
-
var ld = __timeLocalDt(t);
|
|
1235
|
-
return ld ? ld.getUTCHours() : (t instanceof Date ? t : t._d).getHours();
|
|
1236
|
-
};
|
|
1237
|
-
var __timeMinute = __timeMinute || function(t) {
|
|
1238
|
-
var ld = __timeLocalDt(t);
|
|
1239
|
-
return ld ? ld.getUTCMinutes() : (t instanceof Date ? t : t._d).getMinutes();
|
|
1240
|
-
};
|
|
1241
|
-
var __timeSecond = __timeSecond || function(t) {
|
|
1242
|
-
var ld = __timeLocalDt(t);
|
|
1243
|
-
return ld ? ld.getUTCSeconds() : (t instanceof Date ? t : t._d).getSeconds();
|
|
1244
|
-
};
|
|
1245
|
-
var __timeWeekday = __timeWeekday || function(t) {
|
|
1246
|
-
var ld = __timeLocalDt(t);
|
|
1247
|
-
return ld ? ld.getUTCDay() : (t instanceof Date ? t : t._d).getDay();
|
|
1248
|
-
};
|
|
1249
|
-
var __timeDate = __timeDate || function(t) {
|
|
1250
|
-
var ld = __timeLocalDt(t);
|
|
1251
|
-
var dt = t instanceof Date ? t : t._d;
|
|
1252
|
-
return ld ? [ld.getUTCFullYear(), ld.getUTCMonth() + 1, ld.getUTCDate()] : [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()];
|
|
1253
|
-
};
|
|
1254
|
-
var __timeClock = __timeClock || function(t) {
|
|
1255
|
-
var ld = __timeLocalDt(t);
|
|
1256
|
-
var dt = t instanceof Date ? t : t._d;
|
|
1257
|
-
return ld ? [ld.getUTCHours(), ld.getUTCMinutes(), ld.getUTCSeconds()] : [dt.getHours(), dt.getMinutes(), dt.getSeconds()];
|
|
1258
|
-
};
|
|
1259
|
-
var __timeFmt = __timeFmt || function(d, layout) {
|
|
1260
|
-
const dt = d instanceof Date ? d : (d?._d ?? d);
|
|
1261
|
-
const hasOff = typeof d?._offset === "number" || typeof d?._loc?._offset === "number";
|
|
1262
|
-
const offSec = typeof d?._offset === "number" ? d._offset : (d?._loc?._offset ?? 0);
|
|
1263
|
-
const localDt = hasOff ? new Date(dt.getTime() + offSec * 1000) : null;
|
|
1264
|
-
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
1265
|
-
const DAYS = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
|
|
1266
|
-
const MONTHS = ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
|
1267
|
-
const getFullYear = () => localDt ? localDt.getUTCFullYear() : dt.getFullYear();
|
|
1268
|
-
const getMonth = () => localDt ? localDt.getUTCMonth() : dt.getMonth();
|
|
1269
|
-
const getDate = () => localDt ? localDt.getUTCDate() : dt.getDate();
|
|
1270
|
-
const getDay = () => localDt ? localDt.getUTCDay() : dt.getDay();
|
|
1271
|
-
const getHours = () => localDt ? localDt.getUTCHours() : dt.getHours();
|
|
1272
|
-
const getMinutes = () => localDt ? localDt.getUTCMinutes() : dt.getMinutes();
|
|
1273
|
-
const getSeconds = () => localDt ? localDt.getUTCSeconds() : dt.getSeconds();
|
|
1274
|
-
const getMilliseconds = () => localDt ? localDt.getUTCMilliseconds() : dt.getMilliseconds();
|
|
1275
|
-
const getTimezoneOffset = () => hasOff ? Math.round(-offSec / 60) : dt.getTimezoneOffset();
|
|
1276
|
-
return layout.replace(/2006|06|Monday|Mon|January|Jan|01|02|15|PM|pm|03|04|05|Z07:00|-07:00|-0700|MST|\\.(?:0+|9+)|1|2|3|4|5/g, t => {
|
|
1277
|
-
if (t.startsWith(".")) {
|
|
1278
|
-
const isZeroPad = t.includes("0");
|
|
1279
|
-
const maxLen = t.length - 1;
|
|
1280
|
-
const ms = getMilliseconds();
|
|
1281
|
-
let frac = pad(ms, 3);
|
|
1282
|
-
if (d?._ns) {
|
|
1283
|
-
frac += String(d._ns).padStart(6, "0");
|
|
1284
|
-
}
|
|
1285
|
-
if (maxLen > frac.length) frac = frac.padEnd(maxLen, "0");
|
|
1286
|
-
else frac = frac.slice(0, maxLen);
|
|
1287
|
-
if (!isZeroPad) {
|
|
1288
|
-
frac = frac.replace(/0+$/, "");
|
|
1289
|
-
return frac.length > 0 ? "." + frac : "";
|
|
1290
|
-
} else {
|
|
1291
|
-
return "." + frac;
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
switch (t) {
|
|
1295
|
-
case "2006": return getFullYear();
|
|
1296
|
-
case "06": return String(getFullYear()).slice(-2);
|
|
1297
|
-
case "Monday": return DAYS[getDay()];
|
|
1298
|
-
case "Mon": return DAYS[getDay()].slice(0, 3);
|
|
1299
|
-
case "January": return MONTHS[getMonth()];
|
|
1300
|
-
case "Jan": return MONTHS[getMonth()].slice(0, 3);
|
|
1301
|
-
case "01": return pad(getMonth() + 1);
|
|
1302
|
-
case "1": return String(getMonth() + 1);
|
|
1303
|
-
case "02": return pad(getDate());
|
|
1304
|
-
case "2": return String(getDate());
|
|
1305
|
-
case "15": return pad(getHours());
|
|
1306
|
-
case "PM": return getHours() < 12 ? "AM" : "PM";
|
|
1307
|
-
case "pm": return getHours() < 12 ? "am" : "pm";
|
|
1308
|
-
case "03": return pad(getHours() % 12 || 12);
|
|
1309
|
-
case "3": return String(getHours() % 12 || 12);
|
|
1310
|
-
case "04": return pad(getMinutes());
|
|
1311
|
-
case "4": return String(getMinutes());
|
|
1312
|
-
case "05": return pad(getSeconds());
|
|
1313
|
-
case "5": return String(getSeconds());
|
|
1314
|
-
case "Z07:00": {
|
|
1315
|
-
const o = -getTimezoneOffset();
|
|
1316
|
-
return o === 0 ? "Z" : (o > 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + ":" + pad(Math.abs(o) % 60);
|
|
1317
|
-
}
|
|
1318
|
-
case "-07:00": {
|
|
1319
|
-
const o = -getTimezoneOffset();
|
|
1320
|
-
return (o >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + ":" + pad(Math.abs(o) % 60);
|
|
1321
|
-
}
|
|
1322
|
-
case "-0700": {
|
|
1323
|
-
const o = -getTimezoneOffset();
|
|
1324
|
-
return (o >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + pad(Math.abs(o) % 60);
|
|
1325
|
-
}
|
|
1326
|
-
case "MST": return d?._loc ? d._loc._name : (hasOff && offSec === 0 ? "UTC" : "LOCAL");
|
|
1327
|
-
default: return t;
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
};
|
|
1331
|
-
var __timeTruncate = __timeTruncate || function(t, d) {
|
|
1332
|
-
d = BigInt(d);
|
|
1333
|
-
if (d <= 0n) return t;
|
|
1334
|
-
var nano = BigInt(t._d.getTime()) * 1000000n + BigInt(t._ns || 0);
|
|
1335
|
-
var dt = nano + 62135596800000000000n;
|
|
1336
|
-
var r = dt % d;
|
|
1337
|
-
if (r < 0n) r += d;
|
|
1338
|
-
var newNano = nano - r;
|
|
1339
|
-
var newMs = Number(newNano / 1000000n);
|
|
1340
|
-
var remNs = Number(newNano % 1000000n);
|
|
1341
|
-
if (remNs < 0) { newMs--; remNs += 1000000; }
|
|
1342
|
-
return { _d: new Date(newMs), _offset: t._offset, _loc: t._loc, _ns: remNs };
|
|
1343
|
-
};
|
|
1344
|
-
var __timeRound = __timeRound || function(t, d) {
|
|
1345
|
-
d = BigInt(d);
|
|
1346
|
-
if (d <= 0n) return t;
|
|
1347
|
-
var nano = BigInt(t._d.getTime()) * 1000000n + BigInt(t._ns || 0);
|
|
1348
|
-
var dt = nano + 62135596800000000000n;
|
|
1349
|
-
var r = dt % d;
|
|
1350
|
-
if (r < 0n) r += d;
|
|
1351
|
-
var newNano = (r + r < d) ? (nano - r) : (nano + d - r);
|
|
1352
|
-
var newMs = Number(newNano / 1000000n);
|
|
1353
|
-
var remNs = Number(newNano % 1000000n);
|
|
1354
|
-
if (remNs < 0) { newMs--; remNs += 1000000; }
|
|
1355
|
-
return { _d: new Date(newMs), _offset: t._offset, _loc: t._loc, _ns: remNs };
|
|
1356
|
-
};
|
|
1357
|
-
var __timeAddDate = __timeAddDate || function(t, years, months, days) {
|
|
1358
|
-
var d = t._d;
|
|
1359
|
-
if (typeof t._offset === "number") {
|
|
1360
|
-
var offSec = t._offset;
|
|
1361
|
-
var localD = new Date(d.getTime() + offSec * 1000);
|
|
1362
|
-
var newLocalD = new Date(Date.UTC(
|
|
1363
|
-
localD.getUTCFullYear() + Number(years),
|
|
1364
|
-
localD.getUTCMonth() + Number(months),
|
|
1365
|
-
localD.getUTCDate() + Number(days),
|
|
1366
|
-
localD.getUTCHours(),
|
|
1367
|
-
localD.getUTCMinutes(),
|
|
1368
|
-
localD.getUTCSeconds(),
|
|
1369
|
-
localD.getUTCMilliseconds()
|
|
1370
|
-
));
|
|
1371
|
-
var newDate = new Date(newLocalD.getTime() - offSec * 1000);
|
|
1372
|
-
return { _d: newDate, _offset: t._offset, _loc: t._loc, _ns: t._ns };
|
|
1373
|
-
}
|
|
1374
|
-
var newDate = new Date(
|
|
1375
|
-
d.getFullYear() + Number(years),
|
|
1376
|
-
d.getMonth() + Number(months),
|
|
1377
|
-
d.getDate() + Number(days),
|
|
1378
|
-
d.getHours(),
|
|
1379
|
-
d.getMinutes(),
|
|
1380
|
-
d.getSeconds(),
|
|
1381
|
-
d.getMilliseconds()
|
|
1382
|
-
);
|
|
1383
|
-
return { _d: newDate, _offset: t._offset, _loc: t._loc, _ns: t._ns };
|
|
1384
|
-
};
|
|
1385
|
-
var __timeYearDay = __timeYearDay || function(t) {
|
|
1386
|
-
var d = t._d;
|
|
1387
|
-
if (typeof t._offset === "number") {
|
|
1388
|
-
var localD = new Date(d.getTime() + t._offset * 1000);
|
|
1389
|
-
var start = new Date(Date.UTC(localD.getUTCFullYear(), 0, 0));
|
|
1390
|
-
return Math.floor((localD.getTime() - start.getTime()) / 86400000);
|
|
1391
|
-
}
|
|
1392
|
-
var start = new Date(d.getFullYear(), 0, 0);
|
|
1393
|
-
return Math.floor((d.getTime() - start.getTime()) / 86400000);
|
|
1394
|
-
};
|
|
1395
|
-
var __timeISOWeek = __timeISOWeek || function(t) {
|
|
1396
|
-
if (typeof t._offset === "number") {
|
|
1397
|
-
var d = new Date(t._d.getTime() + t._offset * 1000);
|
|
1398
|
-
var day = (d.getUTCDay() + 6) % 7;
|
|
1399
|
-
d.setUTCDate(d.getUTCDate() - day + 3);
|
|
1400
|
-
var year = d.getUTCFullYear();
|
|
1401
|
-
var firstThu = new Date(Date.UTC(year, 0, 4));
|
|
1402
|
-
var firstDay = (firstThu.getUTCDay() + 6) % 7;
|
|
1403
|
-
firstThu.setUTCDate(firstThu.getUTCDate() - firstDay + 3);
|
|
1404
|
-
var week = 1 + Math.round((d.getTime() - firstThu.getTime()) / 604800000);
|
|
1405
|
-
return [year, week];
|
|
1406
|
-
}
|
|
1407
|
-
var d = new Date(t._d.getTime());
|
|
1408
|
-
var day = (d.getDay() + 6) % 7;
|
|
1409
|
-
d.setDate(d.getDate() - day + 3);
|
|
1410
|
-
var year = d.getFullYear();
|
|
1411
|
-
var firstThu = new Date(year, 0, 4);
|
|
1412
|
-
var firstDay = (firstThu.getDay() + 6) % 7;
|
|
1413
|
-
firstThu.setDate(firstThu.getDate() - firstDay + 3);
|
|
1414
|
-
var week = 1 + Math.round((d.getTime() - firstThu.getTime()) / 604800000);
|
|
1415
|
-
return [year, week];
|
|
1416
|
-
};
|
|
1417
|
-
var __timeMarshalJSON = __timeMarshalJSON || function(t) {
|
|
1418
|
-
var y = (typeof t._offset === "number") ? new Date(t._d.getTime() + t._offset * 1000).getUTCFullYear() : t._d.getFullYear();
|
|
1419
|
-
if (y < 0 || y > 9999) {
|
|
1420
|
-
return [new Uint8Array(0), typeof __error === "function" ? __error("Time.MarshalJSON: year outside of range [0,9999]") : new Error("Time.MarshalJSON: year outside of range [0,9999]")];
|
|
1421
|
-
}
|
|
1422
|
-
var s = '"' + __timeFmt(t, "2006-01-02T15:04:05.999999999Z07:00") + '"';
|
|
1423
|
-
return [new TextEncoder().encode(s), null];
|
|
1424
|
-
};
|
|
1425
|
-
var __timeMarshalText = __timeMarshalText || function(t) {
|
|
1426
|
-
var y = (typeof t._offset === "number") ? new Date(t._d.getTime() + t._offset * 1000).getUTCFullYear() : t._d.getFullYear();
|
|
1427
|
-
if (y < 0 || y > 9999) {
|
|
1428
|
-
return [new Uint8Array(0), typeof __error === "function" ? __error("Time.MarshalText: year outside of range [0,9999]") : new Error("Time.MarshalText: year outside of range [0,9999]")];
|
|
1429
|
-
}
|
|
1430
|
-
var s = __timeFmt(t, "2006-01-02T15:04:05.999999999Z07:00");
|
|
1431
|
-
return [new TextEncoder().encode(s), null];
|
|
1432
|
-
};
|
|
1433
|
-
var __timeUnmarshalJSON = __timeUnmarshalJSON || function(t, data) {
|
|
1434
|
-
var s = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
1435
|
-
s = s.trim();
|
|
1436
|
-
if (s === "null") return null;
|
|
1437
|
-
if (!s.startsWith('"') || !s.endsWith('"') || s.length < 2) {
|
|
1438
|
-
return typeof __error === "function" ? __error("Time.UnmarshalJSON: input is not a JSON string") : new Error("Time.UnmarshalJSON: input is not a JSON string");
|
|
1439
|
-
}
|
|
1440
|
-
var inner = s.slice(1, -1);
|
|
1441
|
-
var parsed = __timeParse("2006-01-02T15:04:05.999999999Z07:00", inner);
|
|
1442
|
-
if (parsed[1]) parsed = __timeParse("2006-01-02T15:04:05Z07:00", inner);
|
|
1443
|
-
if (parsed[1]) return parsed[1];
|
|
1444
|
-
t._d = parsed[0]._d;
|
|
1445
|
-
t._offset = parsed[0]._offset;
|
|
1446
|
-
t._loc = parsed[0]._loc;
|
|
1447
|
-
t._ns = parsed[0]._ns;
|
|
1448
|
-
return null;
|
|
1449
|
-
};
|
|
1450
|
-
var __timeUnmarshalText = __timeUnmarshalText || function(t, data) {
|
|
1451
|
-
var s = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
1452
|
-
s = s.trim();
|
|
1453
|
-
var parsed = __timeParse("2006-01-02T15:04:05.999999999Z07:00", s);
|
|
1454
|
-
if (parsed[1]) parsed = __timeParse("2006-01-02T15:04:05Z07:00", s);
|
|
1455
|
-
if (parsed[1]) return parsed[1];
|
|
1456
|
-
t._d = parsed[0]._d;
|
|
1457
|
-
t._offset = parsed[0]._offset;
|
|
1458
|
-
t._loc = parsed[0]._loc;
|
|
1459
|
-
t._ns = parsed[0]._ns;
|
|
1460
|
-
return null;
|
|
1461
|
-
};
|
|
1462
|
-
var __timeAfterFunc = __timeAfterFunc || function(d, f) {
|
|
1463
|
-
var timer = {
|
|
1464
|
-
_id: null,
|
|
1465
|
-
_active: true,
|
|
1466
|
-
_f: f,
|
|
1467
|
-
Stop: function() {
|
|
1468
|
-
var act = this._active;
|
|
1469
|
-
if (act) {
|
|
1470
|
-
clearTimeout(this._id);
|
|
1471
|
-
this._active = false;
|
|
1472
|
-
}
|
|
1473
|
-
return act;
|
|
1474
|
-
},
|
|
1475
|
-
Reset: function(newD) {
|
|
1476
|
-
var act = this._active;
|
|
1477
|
-
if (act) clearTimeout(this._id);
|
|
1478
|
-
var self = this;
|
|
1479
|
-
this._active = true;
|
|
1480
|
-
this._id = setTimeout(function() {
|
|
1481
|
-
self._active = false;
|
|
1482
|
-
self._f();
|
|
1483
|
-
}, Math.round(Number(newD) / 1000000));
|
|
1484
|
-
return act;
|
|
1485
|
-
}
|
|
1486
|
-
};
|
|
1487
|
-
timer._id = setTimeout(function() {
|
|
1488
|
-
timer._active = false;
|
|
1489
|
-
timer._f();
|
|
1490
|
-
}, Math.round(Number(d) / 1000000));
|
|
1491
|
-
return timer;
|
|
1492
|
-
};`;
|
|
1493
|
-
|
|
1494
|
-
export const HELPER_TIME_PARSE = `var __timeParse = __timeParse || function(layout, value) {
|
|
1495
|
-
try {
|
|
1496
|
-
const val = String(value);
|
|
1497
|
-
const d = new Date(val);
|
|
1498
|
-
if (isNaN(d.getTime())) throw 0;
|
|
1499
|
-
let offset = undefined;
|
|
1500
|
-
let loc = null;
|
|
1501
|
-
let ns = 0;
|
|
1502
|
-
const m = /\\.(\\d{1,9})/.exec(val);
|
|
1503
|
-
if (m) {
|
|
1504
|
-
const fracStr = m[1].padEnd(9, "0");
|
|
1505
|
-
ns = Number(fracStr.slice(3));
|
|
1506
|
-
}
|
|
1507
|
-
if (val.endsWith("Z") || val.endsWith("z")) {
|
|
1508
|
-
offset = 0;
|
|
1509
|
-
} else {
|
|
1510
|
-
const tzMatch = /([+-])(\\d{2}):?(\\d{2})$/.exec(val);
|
|
1511
|
-
if (tzMatch) {
|
|
1512
|
-
const sign = tzMatch[1] === "+" ? 1 : -1;
|
|
1513
|
-
const offSec = sign * (Number(tzMatch[2]) * 3600 + Number(tzMatch[3]) * 60);
|
|
1514
|
-
offset = offSec;
|
|
1515
|
-
loc = { _name: tzMatch[0], _offset: offSec, String() { return this._name; } };
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
return [{ _d: d, _offset: offset, _loc: loc, _ns: ns }, null];
|
|
1519
|
-
} catch {
|
|
1520
|
-
return [{ _d: new Date(0) }, { Error() { return "parsing time: cannot parse"; }, toString() { return "parsing time: cannot parse"; }, _msg: "parsing time: cannot parse", _cause: null }];
|
|
1521
|
-
}
|
|
1522
|
-
};`;
|
|
1523
|
-
|
|
1524
|
-
export const HELPER_TESTING = `var __GoFront_FailNow = __GoFront_FailNow || class extends Error {
|
|
1525
|
-
constructor() { super("FailNow"); this.name = "__GoFront_FailNow"; }
|
|
1526
|
-
};
|
|
1527
|
-
var __GoFront_SkipNow = __GoFront_SkipNow || class extends Error {
|
|
1528
|
-
constructor() { super("SkipNow"); this.name = "__GoFront_SkipNow"; }
|
|
1529
|
-
};
|
|
1530
|
-
var __GoFront_T = __GoFront_T || class {
|
|
1531
|
-
constructor(name = "", parent = null) {
|
|
1532
|
-
this._name = name;
|
|
1533
|
-
this._parent = parent;
|
|
1534
|
-
this.failed = false;
|
|
1535
|
-
this.skipped = false;
|
|
1536
|
-
this._logs = [];
|
|
1537
|
-
this._cleanups = [];
|
|
1538
|
-
this._start = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1539
|
-
}
|
|
1540
|
-
Name() { return this._name; }
|
|
1541
|
-
Fail() {
|
|
1542
|
-
this.failed = true;
|
|
1543
|
-
if (this._parent) this._parent.Fail();
|
|
1544
|
-
}
|
|
1545
|
-
Failed() { return this.failed; }
|
|
1546
|
-
FailNow() {
|
|
1547
|
-
this.Fail();
|
|
1548
|
-
throw new __GoFront_FailNow();
|
|
1549
|
-
}
|
|
1550
|
-
Log(...args) {
|
|
1551
|
-
const msg = args.map(a => {
|
|
1552
|
-
if (typeof a === "object" && a !== null) {
|
|
1553
|
-
try { return JSON.stringify(a); } catch { return String(a); }
|
|
1554
|
-
}
|
|
1555
|
-
return String(a);
|
|
1556
|
-
}).join(" ");
|
|
1557
|
-
this._logs.push(msg);
|
|
1558
|
-
}
|
|
1559
|
-
Logf(format, ...args) {
|
|
1560
|
-
const msg = typeof __sprintf === "function" ? __sprintf(format, ...args) : format;
|
|
1561
|
-
this._logs.push(msg);
|
|
1562
|
-
}
|
|
1563
|
-
Error(...args) {
|
|
1564
|
-
this.Fail();
|
|
1565
|
-
this.Log(...args);
|
|
1566
|
-
}
|
|
1567
|
-
Errorf(format, ...args) {
|
|
1568
|
-
this.Fail();
|
|
1569
|
-
this.Logf(format, ...args);
|
|
1570
|
-
}
|
|
1571
|
-
Fatal(...args) {
|
|
1572
|
-
this.Log(...args);
|
|
1573
|
-
this.FailNow();
|
|
1574
|
-
}
|
|
1575
|
-
Fatalf(format, ...args) {
|
|
1576
|
-
this.Logf(format, ...args);
|
|
1577
|
-
this.FailNow();
|
|
1578
|
-
}
|
|
1579
|
-
Skip(...args) {
|
|
1580
|
-
this.skipped = true;
|
|
1581
|
-
if (args.length > 0) this.Log(...args);
|
|
1582
|
-
throw new __GoFront_SkipNow();
|
|
1583
|
-
}
|
|
1584
|
-
Skipf(format, ...args) {
|
|
1585
|
-
this.skipped = true;
|
|
1586
|
-
this.Logf(format, ...args);
|
|
1587
|
-
throw new __GoFront_SkipNow();
|
|
1588
|
-
}
|
|
1589
|
-
Skipped() { return this.skipped; }
|
|
1590
|
-
SkipNow() {
|
|
1591
|
-
this.skipped = true;
|
|
1592
|
-
throw new __GoFront_SkipNow();
|
|
1593
|
-
}
|
|
1594
|
-
Helper() {}
|
|
1595
|
-
Parallel() {}
|
|
1596
|
-
Attr(k, v) {}
|
|
1597
|
-
Output() {
|
|
1598
|
-
return {
|
|
1599
|
-
Write(p) {
|
|
1600
|
-
process.stdout.write(typeof p === "string" ? p : Buffer.from(p));
|
|
1601
|
-
return [p.length, null];
|
|
1602
|
-
}
|
|
1603
|
-
};
|
|
1604
|
-
}
|
|
1605
|
-
Deadline() {
|
|
1606
|
-
return [null, false];
|
|
1607
|
-
}
|
|
1608
|
-
Context() {
|
|
1609
|
-
if (!this._ctx) {
|
|
1610
|
-
let canceled = false;
|
|
1611
|
-
this._ctx = {
|
|
1612
|
-
Deadline() { return [null, false]; },
|
|
1613
|
-
Done() { return null; },
|
|
1614
|
-
Err() { return canceled ? new Error("context canceled") : null; },
|
|
1615
|
-
Value(k) { return null; },
|
|
1616
|
-
};
|
|
1617
|
-
this.Cleanup(() => { canceled = true; });
|
|
1618
|
-
}
|
|
1619
|
-
return this._ctx;
|
|
1620
|
-
}
|
|
1621
|
-
Setenv(key, val) {
|
|
1622
|
-
const prev = process.env[key];
|
|
1623
|
-
const hasPrev = Object.prototype.hasOwnProperty.call(process.env, key);
|
|
1624
|
-
process.env[key] = String(val);
|
|
1625
|
-
this.Cleanup(() => {
|
|
1626
|
-
if (hasPrev) process.env[key] = prev;
|
|
1627
|
-
else delete process.env[key];
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
Cleanup(fn) {
|
|
1631
|
-
this._cleanups.push(fn);
|
|
1632
|
-
}
|
|
1633
|
-
_runCleanups() {
|
|
1634
|
-
while (this._cleanups.length > 0) {
|
|
1635
|
-
const fn = this._cleanups.pop();
|
|
1636
|
-
try {
|
|
1637
|
-
fn();
|
|
1638
|
-
} catch (e) {
|
|
1639
|
-
this.Fail();
|
|
1640
|
-
this.Log("panic in cleanup: " + (e?.message ?? String(e)));
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
Run(name, fn) {
|
|
1645
|
-
const subName = this._name ? \`\${this._name}/\${name}\` : name;
|
|
1646
|
-
const subT = new this.constructor(subName, this);
|
|
1647
|
-
if (typeof globalThis.__onSubtestStart === "function") globalThis.__onSubtestStart(subName);
|
|
1648
|
-
let isAsync = false;
|
|
1649
|
-
try {
|
|
1650
|
-
const res = fn(subT);
|
|
1651
|
-
if (res && typeof res.then === "function") {
|
|
1652
|
-
isAsync = true;
|
|
1653
|
-
return res.then(() => {
|
|
1654
|
-
subT._runCleanups();
|
|
1655
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
1656
|
-
return !subT.failed;
|
|
1657
|
-
}).catch(e => {
|
|
1658
|
-
if (e instanceof __GoFront_FailNow) {
|
|
1659
|
-
// expected
|
|
1660
|
-
} else if (e instanceof __GoFront_SkipNow) {
|
|
1661
|
-
// expected
|
|
1662
|
-
} else {
|
|
1663
|
-
subT.Fail();
|
|
1664
|
-
subT.Log("panic: " + (e?.message ?? String(e)));
|
|
1665
|
-
}
|
|
1666
|
-
subT._runCleanups();
|
|
1667
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
1668
|
-
return false;
|
|
1669
|
-
});
|
|
1670
|
-
}
|
|
1671
|
-
} catch (e) {
|
|
1672
|
-
if (e instanceof __GoFront_FailNow) {
|
|
1673
|
-
// expected on FailNow
|
|
1674
|
-
} else if (e instanceof __GoFront_SkipNow) {
|
|
1675
|
-
// expected on Skip
|
|
1676
|
-
} else {
|
|
1677
|
-
subT.Fail();
|
|
1678
|
-
subT.Log("panic: " + (e?.message ?? String(e)));
|
|
1679
|
-
}
|
|
1680
|
-
} finally {
|
|
1681
|
-
if (!isAsync) {
|
|
1682
|
-
subT._runCleanups();
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
1686
|
-
return !subT.failed;
|
|
1687
|
-
}
|
|
1688
|
-
};
|
|
1689
|
-
var __testing_T = __GoFront_T;
|
|
1690
|
-
var __GoFront_B = __GoFront_B || class extends __GoFront_T {
|
|
1691
|
-
constructor(name = "", parent = null) {
|
|
1692
|
-
super(name, parent);
|
|
1693
|
-
this.N = 1;
|
|
1694
|
-
this._bytes = 0n;
|
|
1695
|
-
this._reportAllocs = false;
|
|
1696
|
-
this._timerStart = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1697
|
-
this._elapsedMs = 0;
|
|
1698
|
-
this._timerRunning = true;
|
|
1699
|
-
this._loopStarted = false;
|
|
1700
|
-
}
|
|
1701
|
-
ResetTimer() {
|
|
1702
|
-
this._timerStart = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1703
|
-
this._elapsedMs = 0;
|
|
1704
|
-
}
|
|
1705
|
-
StartTimer() {
|
|
1706
|
-
if (!this._timerRunning) {
|
|
1707
|
-
this._timerStart = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1708
|
-
this._timerRunning = true;
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
StopTimer() {
|
|
1712
|
-
if (this._timerRunning) {
|
|
1713
|
-
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1714
|
-
this._elapsedMs += now - this._timerStart;
|
|
1715
|
-
this._timerRunning = false;
|
|
1716
|
-
}
|
|
943
|
+
const e = { Error() { return msg; }, toString() { return msg; }, _msg: msg, _cause: cause ?? null };
|
|
944
|
+
if (Array.isArray(cause)) {
|
|
945
|
+
e.Unwrap = function() { return cause; };
|
|
946
|
+
e.Unwrap.__multi = true;
|
|
947
|
+
} else if (cause !== undefined && cause !== null) {
|
|
948
|
+
e.Unwrap = function() { return cause; };
|
|
1717
949
|
}
|
|
1718
|
-
|
|
1719
|
-
this._reportAllocs = true;
|
|
1720
|
-
}
|
|
1721
|
-
ReportMetric(n, unit) {}
|
|
1722
|
-
SetBytes(n) {
|
|
1723
|
-
this._bytes = BigInt(n);
|
|
1724
|
-
}
|
|
1725
|
-
Elapsed() {
|
|
1726
|
-
const ms = this._timerRunning
|
|
1727
|
-
? this._elapsedMs + ((typeof performance !== "undefined" ? performance.now() : Date.now()) - this._timerStart)
|
|
1728
|
-
: this._elapsedMs;
|
|
1729
|
-
return BigInt(Math.round(ms * 1e6));
|
|
1730
|
-
}
|
|
1731
|
-
Loop() {
|
|
1732
|
-
if (!this._loopStarted) {
|
|
1733
|
-
this._loopStarted = true;
|
|
1734
|
-
this.ResetTimer();
|
|
1735
|
-
this._loopTargetNs = this._benchDurationNs || 1e9;
|
|
1736
|
-
this._loopIters = 0;
|
|
1737
|
-
this._nextCheck = 1;
|
|
1738
|
-
}
|
|
1739
|
-
if (this.failed || this.skipped) return false;
|
|
1740
|
-
this._loopIters++;
|
|
1741
|
-
this.N = this._loopIters;
|
|
1742
|
-
if (this._loopIters >= this._nextCheck) {
|
|
1743
|
-
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1744
|
-
const elapsedNs = (now - this._timerStart) * 1e6;
|
|
1745
|
-
if (elapsedNs >= this._loopTargetNs || this._loopIters >= 1e9) {
|
|
1746
|
-
this.StopTimer();
|
|
1747
|
-
return false;
|
|
1748
|
-
}
|
|
1749
|
-
const nsPerOp = Math.max(1, elapsedNs / this._loopIters);
|
|
1750
|
-
const remainingNs = this._loopTargetNs - elapsedNs;
|
|
1751
|
-
const addIters = Math.max(1, Math.min(100000, Math.floor(remainingNs / (nsPerOp * 2))));
|
|
1752
|
-
this._nextCheck = this._loopIters + addIters;
|
|
1753
|
-
}
|
|
1754
|
-
return true;
|
|
1755
|
-
}
|
|
1756
|
-
};
|
|
1757
|
-
var __testing_B = __GoFront_B;
|
|
1758
|
-
var __GoFront_M = __GoFront_M || class {
|
|
1759
|
-
constructor(runFn) {
|
|
1760
|
-
this._run = runFn;
|
|
1761
|
-
this._ran = false;
|
|
1762
|
-
this._exitCode = 0;
|
|
1763
|
-
}
|
|
1764
|
-
Run() {
|
|
1765
|
-
this._ran = true;
|
|
1766
|
-
const res = this._run();
|
|
1767
|
-
if (res && typeof res.then === "function") {
|
|
1768
|
-
this._promise = res.then(code => { this._exitCode = code; return code; });
|
|
1769
|
-
return 0;
|
|
1770
|
-
}
|
|
1771
|
-
this._exitCode = res ?? 0;
|
|
1772
|
-
return this._exitCode;
|
|
1773
|
-
}
|
|
1774
|
-
};
|
|
1775
|
-
var __testing_M = __GoFront_M;
|
|
1776
|
-
var __GoFront_BenchmarkResult = __GoFront_BenchmarkResult || class {
|
|
1777
|
-
constructor(b = null) {
|
|
1778
|
-
this.N = b?.N ?? 0;
|
|
1779
|
-
this.T = b ? b.Elapsed() : 0n;
|
|
1780
|
-
this.Bytes = b?._bytes ?? 0n;
|
|
1781
|
-
this.MemAllocs = 0n;
|
|
1782
|
-
this.MemBytes = 0n;
|
|
1783
|
-
this.Extra = new Map();
|
|
1784
|
-
}
|
|
1785
|
-
AllocedBytesPerOp() { return this.N > 0 ? this.MemBytes / BigInt(this.N) : 0n; }
|
|
1786
|
-
AllocsPerOp() { return this.N > 0 ? this.MemAllocs / BigInt(this.N) : 0n; }
|
|
1787
|
-
MemString() { return \`\${this.AllocedBytesPerOp()} B/op\\t\${this.AllocsPerOp()} allocs/op\`; }
|
|
1788
|
-
NsPerOp() { return this.N > 0 ? this.T / BigInt(this.N) : 0n; }
|
|
1789
|
-
String() {
|
|
1790
|
-
const ns = this.NsPerOp();
|
|
1791
|
-
let s = \`\${this.N}\\t\${ns} ns/op\`;
|
|
1792
|
-
if (this.Bytes > 0n && this.T > 0n) {
|
|
1793
|
-
const mbPerSec = (Number(this.Bytes * BigInt(this.N)) / (Number(this.T) / 1e9) / (1024 * 1024)).toFixed(2);
|
|
1794
|
-
s += \`\\t\${mbPerSec} MB/s\`;
|
|
1795
|
-
}
|
|
1796
|
-
return s;
|
|
1797
|
-
}
|
|
1798
|
-
};
|
|
1799
|
-
var __testing_BenchmarkResult = __GoFront_BenchmarkResult;
|
|
1800
|
-
var __testing_Benchmark = __testing_Benchmark || function(fn) {
|
|
1801
|
-
let b = new __GoFront_B("Benchmark");
|
|
1802
|
-
b._benchDurationNs = 1e9;
|
|
1803
|
-
b.N = 1;
|
|
1804
|
-
b.ResetTimer();
|
|
1805
|
-
fn(b);
|
|
1806
|
-
if (!b._loopStarted) {
|
|
1807
|
-
b.StopTimer();
|
|
1808
|
-
b._runCleanups();
|
|
1809
|
-
let n = 1;
|
|
1810
|
-
while (!b.failed && !b.skipped) {
|
|
1811
|
-
const elapsedNs = Number(b.Elapsed());
|
|
1812
|
-
if (elapsedNs >= 1e9 || n >= 1e9) break;
|
|
1813
|
-
let nextN;
|
|
1814
|
-
if (elapsedNs === 0) nextN = n * 100;
|
|
1815
|
-
else nextN = Math.max(n + 1, Math.min(1e9, Math.floor(n * (1e9 / elapsedNs) * 1.2)));
|
|
1816
|
-
if (nextN <= n) break;
|
|
1817
|
-
n = nextN;
|
|
1818
|
-
b = new __GoFront_B("Benchmark");
|
|
1819
|
-
b._benchDurationNs = 1e9;
|
|
1820
|
-
b.N = n;
|
|
1821
|
-
b.ResetTimer();
|
|
1822
|
-
fn(b);
|
|
1823
|
-
b.StopTimer();
|
|
1824
|
-
b._runCleanups();
|
|
1825
|
-
}
|
|
1826
|
-
} else {
|
|
1827
|
-
b._runCleanups();
|
|
1828
|
-
}
|
|
1829
|
-
return new __GoFront_BenchmarkResult(b);
|
|
950
|
+
return e;
|
|
1830
951
|
};`;
|
|
1831
952
|
|
|
1832
953
|
export const HELPER_INJECT_STYLES = `var __injectStyles = __injectStyles || function(css) {
|
|
@@ -1840,1275 +961,119 @@ export const HELPER_INJECT_STYLES = `var __injectStyles = __injectStyles || func
|
|
|
1840
961
|
s.textContent += "\\n" + css;
|
|
1841
962
|
};`;
|
|
1842
963
|
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
};
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
};
|
|
1904
|
-
var
|
|
1905
|
-
var
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
if (
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
var
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
var str = orig.trim();
|
|
1920
|
-
var neg = false;
|
|
1921
|
-
if (str.startsWith("-")) { neg = true; str = str.slice(1); }
|
|
1922
|
-
else if (str.startsWith("+")) { str = str.slice(1); }
|
|
1923
|
-
if (str === "0") return [0, null];
|
|
1924
|
-
if (str === "") return [0, typeof __error === "function" ? __error('time: invalid duration ""') : new Error('time: invalid duration ""')];
|
|
1925
|
-
|
|
1926
|
-
var totalNs = 0n;
|
|
1927
|
-
var re = /^(\\d*(?:\\.\\d+)?)(ns|us|µs|\\u00b5s|\\u03bcs|ms|s|m|h)/;
|
|
1928
|
-
while (str.length > 0) {
|
|
1929
|
-
var m = re.exec(str);
|
|
1930
|
-
if (!m || m[1] === "" || m[1] === ".") {
|
|
1931
|
-
return [0, typeof __error === "function" ? __error('time: invalid duration "' + orig + '"') : new Error('time: invalid duration "' + orig + '"')];
|
|
1932
|
-
}
|
|
1933
|
-
var numStr = m[1];
|
|
1934
|
-
var unitStr = m[2];
|
|
1935
|
-
var unitMult = 1n;
|
|
1936
|
-
if (unitStr === "ns") unitMult = 1n;
|
|
1937
|
-
else if (unitStr === "us" || unitStr === "µs" || unitStr === "\\u00b5s" || unitStr === "\\u03bcs") unitMult = 1000n;
|
|
1938
|
-
else if (unitStr === "ms") unitMult = 1000000n;
|
|
1939
|
-
else if (unitStr === "s") unitMult = 1000000000n;
|
|
1940
|
-
else if (unitStr === "m") unitMult = 60000000000n;
|
|
1941
|
-
else if (unitStr === "h") unitMult = 3600000000000n;
|
|
1942
|
-
|
|
1943
|
-
if (numStr.includes(".")) {
|
|
1944
|
-
var parts = numStr.split(".");
|
|
1945
|
-
var whole = parts[0] ? BigInt(parts[0]) : 0n;
|
|
1946
|
-
var frac = parts[1];
|
|
1947
|
-
var fracScale = Math.pow(10, frac.length);
|
|
1948
|
-
var fracVal = BigInt(Math.round((Number(frac) / fracScale) * Number(unitMult)));
|
|
1949
|
-
totalNs += whole * unitMult + fracVal;
|
|
1950
|
-
} else {
|
|
1951
|
-
totalNs += BigInt(numStr) * unitMult;
|
|
1952
|
-
}
|
|
1953
|
-
str = str.slice(m[0].length);
|
|
1954
|
-
}
|
|
1955
|
-
if (neg) totalNs = -totalNs;
|
|
1956
|
-
return [Number(totalNs), null];
|
|
1957
|
-
};`;
|
|
1958
|
-
|
|
1959
|
-
export const HELPER_SYNC = `var __sync_mutex = __sync_mutex || function() {
|
|
1960
|
-
return { Lock() {}, Unlock() {}, TryLock() { return true; } };
|
|
1961
|
-
};
|
|
1962
|
-
var __sync_rwmutex = __sync_rwmutex || function() {
|
|
1963
|
-
return { Lock() {}, Unlock() {}, RLock() {}, RUnlock() {}, TryLock() { return true; }, TryRLock() { return true; } };
|
|
1964
|
-
};
|
|
1965
|
-
var __sync_once = __sync_once || function() {
|
|
1966
|
-
return { done: 0, Do(f) { if (!this.done) { this.done = 1; f(); } } };
|
|
1967
|
-
};
|
|
1968
|
-
var __sync_waitgroup = __sync_waitgroup || function() {
|
|
1969
|
-
return { counter: 0, Add(d) { this.counter = (this.counter || 0) + d; }, Done() { this.counter = (this.counter || 0) - 1; }, Wait() {} };
|
|
1970
|
-
};`;
|
|
1971
|
-
|
|
1972
|
-
export const HELPER_CRYPTO_RAND = `var __crypto_rand_read = __crypto_rand_read || function(b) {
|
|
1973
|
-
if (!b || b.length === 0) return [0, null];
|
|
1974
|
-
const u8 = ArrayBuffer.isView(b) ? b : new Uint8Array(b.length);
|
|
1975
|
-
const c = typeof crypto !== "undefined" ? crypto : (typeof globalThis !== "undefined" ? globalThis.crypto : null);
|
|
1976
|
-
const CHUNK = 65536;
|
|
1977
|
-
if (c && typeof c.getRandomValues === "function") {
|
|
1978
|
-
for (let offset = 0; offset < u8.length; offset += CHUNK) {
|
|
1979
|
-
const slice = u8.subarray(offset, Math.min(offset + CHUNK, u8.length));
|
|
1980
|
-
c.getRandomValues(slice);
|
|
1981
|
-
}
|
|
1982
|
-
} else {
|
|
1983
|
-
for (let i = 0; i < u8.length; i++) u8[i] = Math.floor(Math.random() * 256);
|
|
1984
|
-
}
|
|
1985
|
-
if (!ArrayBuffer.isView(b)) {
|
|
1986
|
-
for (let i = 0; i < u8.length; i++) b[i] = u8[i];
|
|
1987
|
-
}
|
|
1988
|
-
return [b.length, null];
|
|
1989
|
-
};
|
|
1990
|
-
var __crypto_rand_reader = __crypto_rand_reader || {
|
|
1991
|
-
Read: function(b) { return __crypto_rand_read(b); }
|
|
1992
|
-
};`;
|
|
1993
|
-
|
|
1994
|
-
export const HELPER_SHA256 = `var __sha256 = __sha256 || (function() {
|
|
1995
|
-
const K = [
|
|
1996
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
1997
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
1998
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
1999
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
2000
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
2001
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
2002
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
2003
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
2004
|
-
];
|
|
2005
|
-
function rotr(x, n) { return (x >>> n) | (x << (32 - n)); }
|
|
2006
|
-
function block(H, M) {
|
|
2007
|
-
const W = new Int32Array(64);
|
|
2008
|
-
for (let i = 0; i < 16; i++) {
|
|
2009
|
-
W[i] = (M[i * 4] << 24) | (M[i * 4 + 1] << 16) | (M[i * 4 + 2] << 8) | M[i * 4 + 3];
|
|
2010
|
-
}
|
|
2011
|
-
for (let i = 16; i < 64; i++) {
|
|
2012
|
-
const s0 = rotr(W[i - 15], 7) ^ rotr(W[i - 15], 18) ^ (W[i - 15] >>> 3);
|
|
2013
|
-
const s1 = rotr(W[i - 2], 17) ^ rotr(W[i - 2], 19) ^ (W[i - 2] >>> 10);
|
|
2014
|
-
W[i] = (W[i - 16] + s0 + W[i - 7] + s1) | 0;
|
|
2015
|
-
}
|
|
2016
|
-
let [a, b, c, d, e, f, g, h] = H;
|
|
2017
|
-
for (let i = 0; i < 64; i++) {
|
|
2018
|
-
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
2019
|
-
const ch = (e & f) ^ (~e & g);
|
|
2020
|
-
const t1 = (h + S1 + ch + K[i] + W[i]) | 0;
|
|
2021
|
-
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
2022
|
-
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
2023
|
-
const t2 = (S0 + maj) | 0;
|
|
2024
|
-
h = g; g = f; f = e; e = (d + t1) | 0;
|
|
2025
|
-
d = c; c = b; b = a; a = (t1 + t2) | 0;
|
|
2026
|
-
}
|
|
2027
|
-
H[0] = (H[0] + a) | 0; H[1] = (H[1] + b) | 0; H[2] = (H[2] + c) | 0; H[3] = (H[3] + d) | 0;
|
|
2028
|
-
H[4] = (H[4] + e) | 0; H[5] = (H[5] + f) | 0; H[6] = (H[6] + g) | 0; H[7] = (H[7] + h) | 0;
|
|
2029
|
-
}
|
|
2030
|
-
function digest(bytes) {
|
|
2031
|
-
const H = new Int32Array([
|
|
2032
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
2033
|
-
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
2034
|
-
]);
|
|
2035
|
-
const len = bytes ? bytes.length : 0;
|
|
2036
|
-
const padLen = (len % 64 < 56) ? (56 - (len % 64)) : (120 - (len % 64));
|
|
2037
|
-
const total = len + padLen + 8;
|
|
2038
|
-
const buf = new Uint8Array(total);
|
|
2039
|
-
if (bytes) {
|
|
2040
|
-
if (ArrayBuffer.isView(bytes)) buf.set(bytes);
|
|
2041
|
-
else for (let i = 0; i < len; i++) buf[i] = bytes[i];
|
|
2042
|
-
}
|
|
2043
|
-
buf[len] = 0x80;
|
|
2044
|
-
const bits = BigInt(len) * 8n;
|
|
2045
|
-
for (let i = 0; i < 8; i++) {
|
|
2046
|
-
buf[total - 1 - i] = Number((bits >> BigInt(i * 8)) & 0xffn);
|
|
2047
|
-
}
|
|
2048
|
-
for (let i = 0; i < total; i += 64) {
|
|
2049
|
-
block(H, buf.subarray(i, i + 64));
|
|
2050
|
-
}
|
|
2051
|
-
const out = new Uint8Array(32);
|
|
2052
|
-
for (let i = 0; i < 8; i++) {
|
|
2053
|
-
out[i * 4] = (H[i] >>> 24) & 0xff;
|
|
2054
|
-
out[i * 4 + 1] = (H[i] >>> 16) & 0xff;
|
|
2055
|
-
out[i * 4 + 2] = (H[i] >>> 8) & 0xff;
|
|
2056
|
-
out[i * 4 + 3] = H[i] & 0xff;
|
|
2057
|
-
}
|
|
2058
|
-
return out;
|
|
2059
|
-
}
|
|
2060
|
-
class Hash {
|
|
2061
|
-
constructor() { this.Reset(); }
|
|
2062
|
-
Reset() { this.buf = []; }
|
|
2063
|
-
Write(p) {
|
|
2064
|
-
if (p) {
|
|
2065
|
-
for (let i = 0; i < p.length; i++) this.buf.push(p[i]);
|
|
2066
|
-
}
|
|
2067
|
-
return [p ? p.length : 0, null];
|
|
2068
|
-
}
|
|
2069
|
-
Sum(b) {
|
|
2070
|
-
const d = digest(this.buf);
|
|
2071
|
-
if (!b || b.length === 0) return d;
|
|
2072
|
-
const res = new Uint8Array(b.length + d.length);
|
|
2073
|
-
res.set(b, 0);
|
|
2074
|
-
res.set(d, b.length);
|
|
2075
|
-
return res;
|
|
964
|
+
// internal/jsonrt's encoder writes into `e.buf[0:e.n]`; these helpers append
|
|
965
|
+
// to it directly (see the jsonrt natives in natives.js).
|
|
966
|
+
export const HELPER_JSONRT = `var __jte = __jte || new TextEncoder();
|
|
967
|
+
var __jroom = __jroom || function(e, k) {
|
|
968
|
+
var need = e.n + k;
|
|
969
|
+
if (need > e.buf.length) {
|
|
970
|
+
var nb = new Uint8Array(Math.max(need, e.buf.length * 2));
|
|
971
|
+
nb.set(e.buf.subarray(0, e.n));
|
|
972
|
+
e.buf = nb;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
var __jput = __jput || function(e, s) {
|
|
976
|
+
var l = s.length, i = 0;
|
|
977
|
+
__jroom(e, l);
|
|
978
|
+
var buf = e.buf, n = e.n;
|
|
979
|
+
for (; i < l; i++) {
|
|
980
|
+
var c = s.charCodeAt(i);
|
|
981
|
+
if (c > 127) break;
|
|
982
|
+
buf[n + i] = c;
|
|
983
|
+
}
|
|
984
|
+
e.n = n + i;
|
|
985
|
+
if (i < l) {
|
|
986
|
+
var u = __jte.encode(s.slice(i));
|
|
987
|
+
__jroom(e, u.length);
|
|
988
|
+
e.buf.set(u, e.n);
|
|
989
|
+
e.n += u.length;
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
var __jint = __jint || function(e, v) { __jput(e, String(v)); };
|
|
993
|
+
var __jfloat = __jfloat || function(e, f, bits) {
|
|
994
|
+
if (bits === 32) {
|
|
995
|
+
var g = Math.fround(f);
|
|
996
|
+
for (var p = 1; p <= 9; p++) {
|
|
997
|
+
var t = g.toPrecision(p);
|
|
998
|
+
if (Math.fround(+t) === g) { f = +t; break; }
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
__jput(e, String(f));
|
|
1002
|
+
};
|
|
1003
|
+
var __jescRe = __jescRe || /[\\u0000-\\u001f"\\\\<>&\\u2028\\u2029\\ud800-\\udfff]/;
|
|
1004
|
+
var __jescRe2 = __jescRe2 || /[\\u0000-\\u001f"\\\\\\u2028\\u2029\\ud800-\\udfff]/;
|
|
1005
|
+
var __jesc = __jesc || function(s, html) {
|
|
1006
|
+
var out = "", start = 0;
|
|
1007
|
+
for (var i = 0; i < s.length; i++) {
|
|
1008
|
+
var c = s.charCodeAt(i), r = null;
|
|
1009
|
+
if (c < 0x20) {
|
|
1010
|
+
r = c === 8 ? "\\\\b" : c === 12 ? "\\\\f" : c === 10 ? "\\\\n" : c === 13 ? "\\\\r" : c === 9 ? "\\\\t" : "\\\\u00" + (c < 16 ? "0" : "") + c.toString(16);
|
|
1011
|
+
} else if (c === 34) r = '\\\\"';
|
|
1012
|
+
else if (c === 92) r = "\\\\\\\\";
|
|
1013
|
+
else if (html && (c === 60 || c === 62 || c === 38)) r = "\\\\u00" + c.toString(16);
|
|
1014
|
+
else if (c === 0x2028 || c === 0x2029) r = "\\\\u202" + (c & 15).toString(16);
|
|
1015
|
+
else if (c >= 0xd800 && c <= 0xdfff) {
|
|
1016
|
+
var d = i + 1 < s.length ? s.charCodeAt(i + 1) : 0;
|
|
1017
|
+
if (c < 0xdc00 && d >= 0xdc00 && d <= 0xdfff) { i++; continue; }
|
|
1018
|
+
r = "\\ufffd";
|
|
1019
|
+
}
|
|
1020
|
+
if (r !== null) { out += s.slice(start, i) + r; start = i + 1; }
|
|
1021
|
+
}
|
|
1022
|
+
return out + s.slice(start);
|
|
1023
|
+
};
|
|
1024
|
+
var __jtd = __jtd || new TextDecoder("utf-8", { ignoreBOM: true });
|
|
1025
|
+
var __jrstr = __jrstr || function(d, unquote) {
|
|
1026
|
+
var data = d.data, p = d.pos + 1, start = p, n = data.length, esc = false;
|
|
1027
|
+
for (; p < n; p++) {
|
|
1028
|
+
var c = data[p];
|
|
1029
|
+
if (c === 34) break;
|
|
1030
|
+
if (c === 92) { esc = true; p++; }
|
|
1031
|
+
}
|
|
1032
|
+
d.pos = p + 1;
|
|
1033
|
+
if (esc) return unquote(data.subarray(start, p));
|
|
1034
|
+
if (p - start < 32) {
|
|
1035
|
+
var s = "";
|
|
1036
|
+
for (var i = start; i < p; i++) {
|
|
1037
|
+
var b = data[i];
|
|
1038
|
+
if (b > 127) return __jtd.decode(data.subarray(start, p));
|
|
1039
|
+
s += String.fromCharCode(b);
|
|
2076
1040
|
}
|
|
2077
|
-
Size() { return 32; }
|
|
2078
|
-
BlockSize() { return 64; }
|
|
2079
|
-
}
|
|
2080
|
-
return {
|
|
2081
|
-
Sum256: digest,
|
|
2082
|
-
New: () => new Hash()
|
|
2083
|
-
};
|
|
2084
|
-
})();`;
|
|
2085
|
-
|
|
2086
|
-
export const HELPER_BINARY = `var __binary_le = __binary_le || {
|
|
2087
|
-
Uint16: function(b) { return (b[0] | (b[1] << 8)) & 0xffff; },
|
|
2088
|
-
Uint32: function(b) { return ((b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0); },
|
|
2089
|
-
Uint64: function(b) {
|
|
2090
|
-
const lo = BigInt((b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0);
|
|
2091
|
-
const hi = BigInt((b[4] | (b[5] << 8) | (b[6] << 16) | (b[7] << 24)) >>> 0);
|
|
2092
|
-
return Number(lo | (hi << 32n));
|
|
2093
|
-
},
|
|
2094
|
-
PutUint16: function(b, v) { b[0] = v & 0xff; b[1] = (v >> 8) & 0xff; },
|
|
2095
|
-
PutUint32: function(b, v) { b[0] = v & 0xff; b[1] = (v >> 8) & 0xff; b[2] = (v >> 16) & 0xff; b[3] = (v >>> 24) & 0xff; },
|
|
2096
|
-
PutUint64: function(b, v) {
|
|
2097
|
-
const bv = BigInt(v);
|
|
2098
|
-
for (let i = 0n; i < 8n; i++) b[Number(i)] = Number((bv >> (i * 8n)) & 0xffn);
|
|
2099
|
-
},
|
|
2100
|
-
AppendUint16: function(b, v) {
|
|
2101
|
-
const len = b ? b.length : 0;
|
|
2102
|
-
const res = new Uint8Array(len + 2);
|
|
2103
|
-
if (len > 0) res.set(b, 0);
|
|
2104
|
-
res[len] = v & 0xff;
|
|
2105
|
-
res[len + 1] = (v >> 8) & 0xff;
|
|
2106
|
-
return res;
|
|
2107
|
-
},
|
|
2108
|
-
AppendUint32: function(b, v) {
|
|
2109
|
-
const len = b ? b.length : 0;
|
|
2110
|
-
const res = new Uint8Array(len + 4);
|
|
2111
|
-
if (len > 0) res.set(b, 0);
|
|
2112
|
-
res[len] = v & 0xff;
|
|
2113
|
-
res[len + 1] = (v >> 8) & 0xff;
|
|
2114
|
-
res[len + 2] = (v >> 16) & 0xff;
|
|
2115
|
-
res[len + 3] = (v >>> 24) & 0xff;
|
|
2116
|
-
return res;
|
|
2117
|
-
},
|
|
2118
|
-
AppendUint64: function(b, v) {
|
|
2119
|
-
const len = b ? b.length : 0;
|
|
2120
|
-
const res = new Uint8Array(len + 8);
|
|
2121
|
-
if (len > 0) res.set(b, 0);
|
|
2122
|
-
const bv = BigInt(v);
|
|
2123
|
-
for (let i = 0n; i < 8n; i++) res[len + Number(i)] = Number((bv >> (i * 8n)) & 0xffn);
|
|
2124
|
-
return res;
|
|
2125
|
-
},
|
|
2126
|
-
String: function() { return "LittleEndian"; }
|
|
2127
|
-
};
|
|
2128
|
-
var __binary_be = __binary_be || {
|
|
2129
|
-
Uint16: function(b) { return ((b[0] << 8) | b[1]) & 0xffff; },
|
|
2130
|
-
Uint32: function(b) { return (((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0); },
|
|
2131
|
-
Uint64: function(b) {
|
|
2132
|
-
const hi = BigInt(((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0);
|
|
2133
|
-
const lo = BigInt(((b[4] << 24) | (b[5] << 16) | (b[6] << 8) | b[7]) >>> 0);
|
|
2134
|
-
return Number((hi << 32n) | lo);
|
|
2135
|
-
},
|
|
2136
|
-
PutUint16: function(b, v) { b[0] = (v >> 8) & 0xff; b[1] = v & 0xff; },
|
|
2137
|
-
PutUint32: function(b, v) { b[0] = (v >>> 24) & 0xff; b[1] = (v >> 16) & 0xff; b[2] = (v >> 8) & 0xff; b[3] = v & 0xff; },
|
|
2138
|
-
PutUint64: function(b, v) {
|
|
2139
|
-
const bv = BigInt(v);
|
|
2140
|
-
for (let i = 0n; i < 8n; i++) b[Number(7n - i)] = Number((bv >> (i * 8n)) & 0xffn);
|
|
2141
|
-
},
|
|
2142
|
-
AppendUint16: function(b, v) {
|
|
2143
|
-
const len = b ? b.length : 0;
|
|
2144
|
-
const res = new Uint8Array(len + 2);
|
|
2145
|
-
if (len > 0) res.set(b, 0);
|
|
2146
|
-
res[len] = (v >> 8) & 0xff;
|
|
2147
|
-
res[len + 1] = v & 0xff;
|
|
2148
|
-
return res;
|
|
2149
|
-
},
|
|
2150
|
-
AppendUint32: function(b, v) {
|
|
2151
|
-
const len = b ? b.length : 0;
|
|
2152
|
-
const res = new Uint8Array(len + 4);
|
|
2153
|
-
if (len > 0) res.set(b, 0);
|
|
2154
|
-
res[len] = (v >>> 24) & 0xff;
|
|
2155
|
-
res[len + 1] = (v >> 16) & 0xff;
|
|
2156
|
-
res[len + 2] = (v >> 8) & 0xff;
|
|
2157
|
-
res[len + 3] = v & 0xff;
|
|
2158
|
-
return res;
|
|
2159
|
-
},
|
|
2160
|
-
AppendUint64: function(b, v) {
|
|
2161
|
-
const len = b ? b.length : 0;
|
|
2162
|
-
const res = new Uint8Array(len + 8);
|
|
2163
|
-
if (len > 0) res.set(b, 0);
|
|
2164
|
-
const bv = BigInt(v);
|
|
2165
|
-
for (let i = 0n; i < 8n; i++) res[len + Number(i)] = Number((bv >> ((7n - i) * 8n)) & 0xffn);
|
|
2166
|
-
return res;
|
|
2167
|
-
},
|
|
2168
|
-
String: function() { return "BigEndian"; }
|
|
2169
|
-
};
|
|
2170
|
-
var __binary_size = __binary_size || function(v) {
|
|
2171
|
-
if (typeof v === "number" || typeof v === "bigint") return 8;
|
|
2172
|
-
if (Array.isArray(v) || ArrayBuffer.isView(v)) return v.length;
|
|
2173
|
-
if (v && typeof v === "object") {
|
|
2174
|
-
let s = 0;
|
|
2175
|
-
for (const k of Object.keys(v)) { if (!k.startsWith("_") && typeof v[k] !== "function") s += __binary_size(v[k]); }
|
|
2176
1041
|
return s;
|
|
2177
1042
|
}
|
|
2178
|
-
return
|
|
2179
|
-
};
|
|
2180
|
-
var __binary_read = __binary_read || function(r, order, data, sz, typeTag) {
|
|
2181
|
-
const targetR = r?.value ?? r;
|
|
2182
|
-
const readChunk = function(buf) {
|
|
2183
|
-
if (typeof targetR?.Read === "function") return targetR.Read(buf);
|
|
2184
|
-
if (Array.isArray(targetR?._buf)) {
|
|
2185
|
-
const n = Math.min(buf.length, targetR._buf.length);
|
|
2186
|
-
for (let i = 0; i < n; i++) buf[i] = targetR._buf.shift();
|
|
2187
|
-
return [n, n < buf.length ? __io_eof : null];
|
|
2188
|
-
}
|
|
2189
|
-
return [0, __error("binary.Read: unsupported reader")];
|
|
2190
|
-
};
|
|
2191
|
-
const isBox = data && typeof data === "object" && Object.prototype.hasOwnProperty.call(data, "value") && (data.__box === true || (Object.keys(data).length <= 2 && (data.constructor === Object || !data.constructor || data.constructor?.name === "Object")));
|
|
2192
|
-
const target = isBox ? data : null;
|
|
2193
|
-
if (!target && data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data)) {
|
|
2194
|
-
for (const k of Object.keys(data)) {
|
|
2195
|
-
if (k.startsWith("_") || typeof data[k] === "function") continue;
|
|
2196
|
-
const fBox = { value: data[k], __box: true };
|
|
2197
|
-
const err = __binary_read(r, order, fBox);
|
|
2198
|
-
if (err) return err;
|
|
2199
|
-
data[k] = fBox.value;
|
|
2200
|
-
}
|
|
2201
|
-
return null;
|
|
2202
|
-
}
|
|
2203
|
-
const s = sz || (target ? (typeof target.value === "bigint" ? 8 : (typeof target.value === "number" ? 4 : 4)) : __binary_size(data?.value ?? data));
|
|
2204
|
-
if (s <= 0) return __error("binary.Read: invalid type");
|
|
2205
|
-
const buf = new Uint8Array(s);
|
|
2206
|
-
const [n, err] = readChunk(buf);
|
|
2207
|
-
if (err) return err;
|
|
2208
|
-
if (n < s) return __io_eof;
|
|
2209
|
-
if (target) {
|
|
2210
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
2211
|
-
const isLe = order.String() === "LittleEndian";
|
|
2212
|
-
if (typeTag === "float32") target.value = view.getFloat32(0, isLe);
|
|
2213
|
-
else if (typeTag === "float64") target.value = view.getFloat64(0, isLe);
|
|
2214
|
-
else if (typeTag === "int8") target.value = view.getInt8(0);
|
|
2215
|
-
else if (typeTag === "uint8" || typeTag === "byte" || typeTag === "bool") target.value = view.getUint8(0);
|
|
2216
|
-
else if (typeTag === "int16") target.value = view.getInt16(0, isLe);
|
|
2217
|
-
else if (typeTag === "uint16") target.value = view.getUint16(0, isLe);
|
|
2218
|
-
else if (typeTag === "int32" || typeTag === "rune") target.value = view.getInt32(0, isLe);
|
|
2219
|
-
else if (typeTag === "uint32") target.value = view.getUint32(0, isLe);
|
|
2220
|
-
else if (typeTag === "int64") target.value = Number(view.getBigInt64(0, isLe));
|
|
2221
|
-
else if (typeTag === "uint64") target.value = Number(view.getBigUint64(0, isLe));
|
|
2222
|
-
else if (s === 1) target.value = buf[0];
|
|
2223
|
-
else if (s === 2) target.value = order.Uint16(buf);
|
|
2224
|
-
else if (s === 4) target.value = order.Uint32(buf);
|
|
2225
|
-
else if (s === 8) target.value = order.Uint64(buf);
|
|
2226
|
-
return null;
|
|
2227
|
-
}
|
|
2228
|
-
if (Array.isArray(data) || ArrayBuffer.isView(data)) {
|
|
2229
|
-
for (let i = 0; i < s; i++) data[i] = buf[i];
|
|
2230
|
-
return null;
|
|
2231
|
-
}
|
|
2232
|
-
return null;
|
|
2233
|
-
};
|
|
2234
|
-
var __binary_write = __binary_write || function(w, order, data, sz, typeTag) {
|
|
2235
|
-
const targetW = w?.value ?? w;
|
|
2236
|
-
const writeChunk = function(chunk) {
|
|
2237
|
-
if (typeof targetW?.Write === "function") return targetW.Write(chunk);
|
|
2238
|
-
if (Array.isArray(targetW?._buf)) {
|
|
2239
|
-
for (let i = 0; i < chunk.length; i++) targetW._buf.push(chunk[i]);
|
|
2240
|
-
return [chunk.length, null];
|
|
2241
|
-
}
|
|
2242
|
-
if (typeof targetW?._buf === "string") {
|
|
2243
|
-
targetW._buf += new TextDecoder().decode(chunk);
|
|
2244
|
-
return [chunk.length, null];
|
|
2245
|
-
}
|
|
2246
|
-
return [0, __error("binary.Write: unsupported writer")];
|
|
2247
|
-
};
|
|
2248
|
-
const isBox = data && typeof data === "object" && Object.prototype.hasOwnProperty.call(data, "value") && (data.__box === true || (Object.keys(data).length <= 2 && (data.constructor === Object || !data.constructor || data.constructor?.name === "Object")));
|
|
2249
|
-
const v = isBox ? data.value : data;
|
|
2250
|
-
if (!isBox && typeof data === "object" && data !== null && !Array.isArray(data) && !ArrayBuffer.isView(data)) {
|
|
2251
|
-
for (const k of Object.keys(data)) {
|
|
2252
|
-
if (k.startsWith("_") || typeof data[k] === "function") continue;
|
|
2253
|
-
const err = __binary_write(w, order, data[k]);
|
|
2254
|
-
if (err) return err;
|
|
2255
|
-
}
|
|
2256
|
-
return null;
|
|
2257
|
-
}
|
|
2258
|
-
if (typeof v === "number" || typeof v === "bigint" || typeof v === "boolean") {
|
|
2259
|
-
const s = sz || (typeof v === "bigint" ? 8 : (typeTag === "float64" ? 8 : 4));
|
|
2260
|
-
const buf = new Uint8Array(s);
|
|
2261
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
2262
|
-
const isLe = order.String() === "LittleEndian";
|
|
2263
|
-
if (typeTag === "float32") view.setFloat32(0, Number(v), isLe);
|
|
2264
|
-
else if (typeTag === "float64") view.setFloat64(0, Number(v), isLe);
|
|
2265
|
-
else if (s === 1) buf[0] = Number(v) & 0xff;
|
|
2266
|
-
else if (s === 2) order.PutUint16(buf, Number(v));
|
|
2267
|
-
else if (s === 4) order.PutUint32(buf, Number(v));
|
|
2268
|
-
else order.PutUint64(buf, v);
|
|
2269
|
-
const [, err] = writeChunk(buf);
|
|
2270
|
-
return err;
|
|
2271
|
-
}
|
|
2272
|
-
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
|
|
2273
|
-
const [, err] = writeChunk(v);
|
|
2274
|
-
return err;
|
|
2275
|
-
}
|
|
2276
|
-
return __error("binary.Write: unsupported type");
|
|
2277
|
-
};`;
|
|
2278
|
-
|
|
2279
|
-
export const HELPER_HEX = `var __hex_encode_to_string = __hex_encode_to_string || function(src) {
|
|
2280
|
-
if (!src || src.length === 0) return "";
|
|
2281
|
-
let s = "";
|
|
2282
|
-
for (let i = 0; i < src.length; i++) s += src[i].toString(16).padStart(2, "0");
|
|
2283
|
-
return s;
|
|
1043
|
+
return __jtd.decode(data.subarray(start, p));
|
|
2284
1044
|
};
|
|
2285
|
-
var
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
return [out.subarray(0, i / 2), __error("encoding/hex: invalid byte: " + pair)];
|
|
2292
|
-
}
|
|
2293
|
-
out[i / 2] = parseInt(pair, 16);
|
|
2294
|
-
}
|
|
2295
|
-
return [out, null];
|
|
2296
|
-
};
|
|
2297
|
-
var __hex_encode = __hex_encode || function(dst, src) {
|
|
2298
|
-
const hex = __hex_encode_to_string(src);
|
|
2299
|
-
for (let i = 0; i < hex.length; i++) dst[i] = hex.charCodeAt(i);
|
|
2300
|
-
return hex.length;
|
|
2301
|
-
};
|
|
2302
|
-
var __hex_decode = __hex_decode || function(dst, src) {
|
|
2303
|
-
const str = typeof src === "string" ? src : (src instanceof Uint8Array ? new TextDecoder().decode(src) : String.fromCharCode(...src));
|
|
2304
|
-
const [res, err] = __hex_decode_string(str);
|
|
2305
|
-
for (let i = 0; i < res.length; i++) dst[i] = res[i];
|
|
2306
|
-
return [res.length, err];
|
|
2307
|
-
};`;
|
|
2308
|
-
|
|
2309
|
-
export const HELPER_BASE64 = `var __base64_make = __base64_make || function(alphabet, padChar) {
|
|
2310
|
-
const encMap = alphabet.split("");
|
|
2311
|
-
const decMap = {};
|
|
2312
|
-
for (let i = 0; i < 64; i++) decMap[alphabet[i]] = i;
|
|
2313
|
-
return {
|
|
2314
|
-
EncodeToString: function(src) {
|
|
2315
|
-
if (!src || src.length === 0) return "";
|
|
2316
|
-
let res = "";
|
|
2317
|
-
let i = 0;
|
|
2318
|
-
for (; i + 2 < src.length; i += 3) {
|
|
2319
|
-
const n = (src[i] << 16) | (src[i + 1] << 8) | src[i + 2];
|
|
2320
|
-
res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63] + encMap[(n >> 6) & 63] + encMap[n & 63];
|
|
2321
|
-
}
|
|
2322
|
-
if (i < src.length) {
|
|
2323
|
-
if (src.length - i === 1) {
|
|
2324
|
-
const n = src[i] << 16;
|
|
2325
|
-
res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63];
|
|
2326
|
-
if (padChar) res += padChar + padChar;
|
|
2327
|
-
} else {
|
|
2328
|
-
const n = (src[i] << 16) | (src[i + 1] << 8);
|
|
2329
|
-
res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63] + encMap[(n >> 6) & 63];
|
|
2330
|
-
if (padChar) res += padChar;
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
return res;
|
|
2334
|
-
},
|
|
2335
|
-
DecodeString: function(s) {
|
|
2336
|
-
let str = s.replace(/\\s+/g, "");
|
|
2337
|
-
if (padChar) {
|
|
2338
|
-
if (str.length % 4 !== 0) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
|
|
2339
|
-
if (str.endsWith(padChar + padChar)) {
|
|
2340
|
-
if (str.endsWith(padChar + padChar + padChar)) return [new Uint8Array(0), __error("illegal base64 data at input byte " + (str.length - 3))];
|
|
2341
|
-
str = str.slice(0, -2);
|
|
2342
|
-
if (str.length % 4 !== 2) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
|
|
2343
|
-
} else if (str.endsWith(padChar)) {
|
|
2344
|
-
str = str.slice(0, -1);
|
|
2345
|
-
if (str.length % 4 !== 3) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
const out = [];
|
|
2349
|
-
let i = 0;
|
|
2350
|
-
for (; i + 3 < str.length; i += 4) {
|
|
2351
|
-
const c0 = decMap[str[i]], c1 = decMap[str[i+1]], c2 = decMap[str[i+2]], c3 = decMap[str[i+3]];
|
|
2352
|
-
if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
|
|
2353
|
-
const n = (c0 << 18) | (c1 << 12) | (c2 << 6) | c3;
|
|
2354
|
-
out.push((n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff);
|
|
2355
|
-
}
|
|
2356
|
-
const rem = str.length - i;
|
|
2357
|
-
if (rem === 2) {
|
|
2358
|
-
const c0 = decMap[str[i]], c1 = decMap[str[i+1]];
|
|
2359
|
-
if (c0 === undefined || c1 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
|
|
2360
|
-
out.push((c0 << 2) | (c1 >> 4));
|
|
2361
|
-
} else if (rem === 3) {
|
|
2362
|
-
const c0 = decMap[str[i]], c1 = decMap[str[i+1]], c2 = decMap[str[i+2]];
|
|
2363
|
-
if (c0 === undefined || c1 === undefined || c2 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
|
|
2364
|
-
out.push((c0 << 2) | (c1 >> 4), ((c1 & 15) << 4) | (c2 >> 2));
|
|
2365
|
-
} else if (rem === 1) {
|
|
2366
|
-
return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
|
|
2367
|
-
}
|
|
2368
|
-
return [new Uint8Array(out), null];
|
|
2369
|
-
},
|
|
2370
|
-
Encode: function(dst, src) {
|
|
2371
|
-
const s = this.EncodeToString(src);
|
|
2372
|
-
for (let i = 0; i < s.length; i++) dst[i] = s.charCodeAt(i);
|
|
2373
|
-
},
|
|
2374
|
-
Decode: function(dst, src) {
|
|
2375
|
-
const str = String.fromCharCode(...src);
|
|
2376
|
-
const [res, err] = this.DecodeString(str);
|
|
2377
|
-
for (let i = 0; i < res.length; i++) dst[i] = res[i];
|
|
2378
|
-
return [res.length, err];
|
|
2379
|
-
},
|
|
2380
|
-
EncodedLen: function(n) { return padChar ? Math.ceil(n / 3) * 4 : Math.floor((n * 8 + 5) / 6); },
|
|
2381
|
-
DecodedLen: function(n) { return padChar ? Math.floor(n * 3 / 4) : Math.floor(n * 6 / 8); },
|
|
2382
|
-
WithPadding: function(p) { return __base64_make(alphabet, p === -1 ? "" : String.fromCharCode(p)); }
|
|
2383
|
-
};
|
|
2384
|
-
};
|
|
2385
|
-
var __base64_std = __base64_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "=");
|
|
2386
|
-
var __base64_url = __base64_url || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "=");
|
|
2387
|
-
var __base64_raw_std = __base64_raw_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "");
|
|
2388
|
-
var __base64_raw_url = __base64_raw_url || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "");`;
|
|
2389
|
-
|
|
2390
|
-
export const HELPER_JSON = `var __json_esc = __json_esc || function(s) {
|
|
2391
|
-
if (typeof s !== "string") s = String(s);
|
|
2392
|
-
var out = JSON.stringify(s);
|
|
2393
|
-
var escHtml = typeof OptEscapeHTML$$internal$jsonrt === "undefined" || OptEscapeHTML$$internal$jsonrt;
|
|
2394
|
-
if (escHtml) {
|
|
2395
|
-
out = out
|
|
2396
|
-
.replace(/[<>&]/g, function(c) {
|
|
2397
|
-
return c === "<" ? "\\\\u003c" : (c === ">" ? "\\\\u003e" : "\\\\u0026");
|
|
2398
|
-
})
|
|
2399
|
-
.replace(/\\u2028/g, "\\\\u2028")
|
|
2400
|
-
.replace(/\\u2029/g, "\\\\u2029");
|
|
2401
|
-
}
|
|
2402
|
-
return out;
|
|
2403
|
-
};
|
|
2404
|
-
var __json_check_unknown = __json_check_unknown || function(parsed, knownKeys) {
|
|
2405
|
-
var disallow = typeof OptDisallowUnknownFields$$internal$jsonrt !== "undefined" && OptDisallowUnknownFields$$internal$jsonrt;
|
|
2406
|
-
if (!disallow || !parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
2407
|
-
var lowerSet = new Set(knownKeys.map(function(k) { return k.toLowerCase(); }));
|
|
2408
|
-
for (var k in parsed) {
|
|
2409
|
-
if (Object.prototype.hasOwnProperty.call(parsed, k) && !k.startsWith("__")) {
|
|
2410
|
-
if (!lowerSet.has(k.toLowerCase())) {
|
|
2411
|
-
var msg = "json: unknown field " + JSON.stringify(k);
|
|
2412
|
-
return typeof __error === "function" ? __error(msg) : new Error(msg);
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
return null;
|
|
2417
|
-
};
|
|
2418
|
-
var __json_err = __json_err || function(msg, valKind, targetType) {
|
|
2419
|
-
var fullMsg = "json: " + msg;
|
|
2420
|
-
var valDesc = valKind || "";
|
|
2421
|
-
var typeDesc = targetType || "";
|
|
2422
|
-
if (!valDesc && msg.startsWith("cannot unmarshal ")) {
|
|
2423
|
-
var parts = msg.slice(17).split(" into ");
|
|
2424
|
-
valDesc = parts[0];
|
|
2425
|
-
var rest = parts[1] || "";
|
|
2426
|
-
var idx = rest.indexOf(" of type ");
|
|
2427
|
-
if (idx >= 0) typeDesc = rest.slice(idx + 9);
|
|
2428
|
-
else if (rest.startsWith("Go value of type ")) typeDesc = rest.slice(17);
|
|
2429
|
-
}
|
|
2430
|
-
var structName = __json_structs.length > 0 ? __json_structs[__json_structs.length - 1] : "";
|
|
2431
|
-
var fieldPath = __json_path.join(".");
|
|
2432
|
-
var offset = typeof __json_current_offset === "number" ? __json_current_offset : 0;
|
|
2433
|
-
var e;
|
|
2434
|
-
if (typeof UnmarshalTypeError$$internal$jsonrt === "function") {
|
|
2435
|
-
e = new UnmarshalTypeError$$internal$jsonrt(valDesc, typeDesc, BigInt(offset), structName, fieldPath);
|
|
2436
|
-
if (e.__p !== true && Object.isExtensible(e)) Object.defineProperty(e, "__p", { value: true, configurable: true, writable: true });
|
|
2437
|
-
} else {
|
|
2438
|
-
e = typeof __error === "function" ? __error(fullMsg) : new Error(fullMsg);
|
|
2439
|
-
e.Value = valDesc;
|
|
2440
|
-
e.Type = typeDesc;
|
|
2441
|
-
e.Offset = BigInt(offset);
|
|
2442
|
-
e.Struct = structName;
|
|
2443
|
-
e.Field = fieldPath;
|
|
2444
|
-
if (e.__p !== true && Object.isExtensible(e)) Object.defineProperty(e, "__p", { value: true, configurable: true, writable: true });
|
|
2445
|
-
}
|
|
2446
|
-
e.Error = function() { return fullMsg; };
|
|
2447
|
-
e._msg = fullMsg;
|
|
2448
|
-
e.__struct = "UnmarshalTypeError$$internal$jsonrt";
|
|
2449
|
-
return e;
|
|
2450
|
-
};
|
|
2451
|
-
// Decode error context, as in Go: innermost struct being decoded plus the path
|
|
2452
|
-
// of JSON field names from the root. Reset by every __json_unmarshal call.
|
|
2453
|
-
var __json_structs = __json_structs || [];
|
|
2454
|
-
var __json_path = __json_path || [];
|
|
2455
|
-
var __json_current_offset = __json_current_offset || 0;
|
|
2456
|
-
var __json_ctx = __json_ctx || function(typeName) {
|
|
2457
|
-
if (__json_path.length > 0 && __json_structs.length > 0) {
|
|
2458
|
-
return "Go struct field " + __json_structs[__json_structs.length - 1] + "." + __json_path.join(".") + " of type " + typeName;
|
|
2459
|
-
}
|
|
2460
|
-
return "Go value of type " + typeName;
|
|
2461
|
-
};
|
|
2462
|
-
// The JSON source text of a number, for "cannot unmarshal number <literal>" messages.
|
|
2463
|
-
var __json_lit = __json_lit || function(v, raw) {
|
|
2464
|
-
if (raw !== undefined && raw !== null) return String(raw).trim();
|
|
2465
|
-
return typeof v === "string" ? v.replace(/__bigint$/, "") : String(v);
|
|
2466
|
-
};
|
|
2467
|
-
var __json_is_valid_number = __json_is_valid_number || function(s) {
|
|
2468
|
-
return typeof s === "string" && /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/.test(s);
|
|
2469
|
-
};
|
|
2470
|
-
var __json_enc_number = __json_enc_number || function(v) {
|
|
2471
|
-
var s = typeof v === "string" ? v : (v != null ? String(v) : "");
|
|
2472
|
-
if (s === "") return "0";
|
|
2473
|
-
if (!__json_is_valid_number(s)) {
|
|
2474
|
-
throw new Error("json: invalid number literal " + JSON.stringify(s));
|
|
1045
|
+
var __jrnum = __jrnum || function(d) {
|
|
1046
|
+
var data = d.data, p = d.pos, start = p, n = data.length, s = "";
|
|
1047
|
+
for (; p < n; p++) {
|
|
1048
|
+
var c = data[p];
|
|
1049
|
+
if (!((c >= 48 && c <= 57) || c === 45 || c === 43 || c === 46 || c === 101 || c === 69)) break;
|
|
1050
|
+
s += String.fromCharCode(c);
|
|
2475
1051
|
}
|
|
1052
|
+
d.pos = p;
|
|
2476
1053
|
return s;
|
|
2477
1054
|
};
|
|
2478
|
-
var
|
|
2479
|
-
if (
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
var f = bits === 32 ? Math.fround(n) : n;
|
|
2501
|
-
if (!isFinite(f)) return __json_err("cannot unmarshal number " + __json_lit(v, raw) + " into " + __json_ctx(ctxType));
|
|
2502
|
-
return f;
|
|
2503
|
-
};
|
|
2504
|
-
// []byte accepts a base64 string or (like Go) an array of uint8 values.
|
|
2505
|
-
var __json_bytes_decode = __json_bytes_decode || function(v) {
|
|
2506
|
-
if (Array.isArray(v)) {
|
|
2507
|
-
var u8 = new Uint8Array(v.length);
|
|
2508
|
-
for (var i = 0; i < v.length; i++) {
|
|
2509
|
-
var b = __json_int_decode(v[i], "uint8", "uint8", __json_raw_child(v, i));
|
|
2510
|
-
if (b && b._msg) return b;
|
|
2511
|
-
u8[i] = b;
|
|
2512
|
-
}
|
|
2513
|
-
return u8;
|
|
2514
|
-
}
|
|
2515
|
-
if (typeof v !== "string") return __json_err("cannot unmarshal " + __json_type(v) + " into " + __json_ctx("[]uint8"));
|
|
2516
|
-
return __json_b64_dec(v);
|
|
2517
|
-
};
|
|
2518
|
-
var __json_esc_noh = __json_esc_noh || function(s) {
|
|
2519
|
-
return JSON.stringify(String(s)).replace(/\\u2028/g, "\\\\u2028").replace(/\\u2029/g, "\\\\u2029");
|
|
2520
|
-
};
|
|
2521
|
-
var __json_syntax_msg = __json_syntax_msg || function(s) {
|
|
2522
|
-
if (typeof CheckValid$$internal$jsonrt === "function") {
|
|
2523
|
-
var se = CheckValid$$internal$jsonrt(new TextEncoder().encode(String(s)));
|
|
2524
|
-
if (se && typeof se.Error === "function") return se.Error();
|
|
2525
|
-
}
|
|
2526
|
-
var t = String(s).trim();
|
|
2527
|
-
if (t === "") return "unexpected end of JSON input";
|
|
2528
|
-
var m;
|
|
2529
|
-
try { JSON.parse(t); } catch (e) { m = String(e && e.message); }
|
|
2530
|
-
if (m && /end of JSON input|Unterminated/.test(m)) return "unexpected end of JSON input";
|
|
2531
|
-
var pos = m && /after JSON at position (\\d+)/.exec(m);
|
|
2532
|
-
if (pos) return "invalid character '" + t[Number(pos[1])] + "' after top-level value";
|
|
2533
|
-
if ("{[\\"-0123456789tfn".indexOf(t[0]) < 0) return "invalid character '" + t[0] + "' looking for beginning of value";
|
|
2534
|
-
return "invalid character in JSON value";
|
|
2535
|
-
};
|
|
2536
|
-
// Validates and compacts JSON text, escaping <, >, & and U+2028/U+2029 inside strings.
|
|
2537
|
-
var __json_compact = __json_compact || function(s) {
|
|
2538
|
-
try { JSON.parse(s); } catch (e) { return null; }
|
|
2539
|
-
var out = "", inStr = false, esc = false;
|
|
2540
|
-
var escHtml = typeof OptEscapeHTML$$internal$jsonrt === "undefined" || OptEscapeHTML$$internal$jsonrt;
|
|
2541
|
-
for (var i = 0; i < s.length; i++) {
|
|
2542
|
-
var c = s[i];
|
|
2543
|
-
if (inStr) {
|
|
2544
|
-
if (esc) { esc = false; out += c; continue; }
|
|
2545
|
-
if (c === "\\\\") { esc = true; out += c; continue; }
|
|
2546
|
-
if (c === '"') inStr = false;
|
|
2547
|
-
if (!escHtml) out += c;
|
|
2548
|
-
else if (c === "<") out += "\\\\u003c";
|
|
2549
|
-
else if (c === ">") out += "\\\\u003e";
|
|
2550
|
-
else if (c === "&") out += "\\\\u0026";
|
|
2551
|
-
else if (c === "\\u2028") out += "\\\\u2028";
|
|
2552
|
-
else if (c === "\\u2029") out += "\\\\u2029";
|
|
2553
|
-
else out += c;
|
|
2554
|
-
continue;
|
|
2555
|
-
}
|
|
2556
|
-
if (c === '"') { inStr = true; out += c; continue; }
|
|
2557
|
-
if (c === " " || c === "\\t" || c === "\\n" || c === "\\r") continue;
|
|
2558
|
-
out += c;
|
|
2559
|
-
}
|
|
2560
|
-
return out;
|
|
2561
|
-
};
|
|
2562
|
-
var __json_unsupported_value = __json_unsupported_value || function(str) {
|
|
2563
|
-
str = str === "Infinity" ? "+Inf" : (str === "-Infinity" ? "-Inf" : str);
|
|
2564
|
-
if (typeof UnsupportedValueError$$internal$jsonrt === "function") {
|
|
2565
|
-
var e = new UnsupportedValueError$$internal$jsonrt(null, str);
|
|
2566
|
-
e.Str = str;
|
|
2567
|
-
if (e.__p !== true && Object.isExtensible(e)) Object.defineProperty(e, "__p", { value: true, configurable: true, writable: true });
|
|
2568
|
-
e.__struct = "UnsupportedValueError$$internal$jsonrt";
|
|
2569
|
-
return e;
|
|
2570
|
-
}
|
|
2571
|
-
var e = new Error("json: unsupported value: " + str);
|
|
2572
|
-
e.Str = str;
|
|
2573
|
-
e.__struct = "UnsupportedValueError$$internal$jsonrt";
|
|
2574
|
-
return e;
|
|
2575
|
-
};
|
|
2576
|
-
var __json_marshaler_out = __json_marshaler_out || function(res, typeName) {
|
|
2577
|
-
var err = res && res[1];
|
|
2578
|
-
if (err) {
|
|
2579
|
-
var merr;
|
|
2580
|
-
if (typeof MarshalerError$$internal$jsonrt === "function") {
|
|
2581
|
-
merr = new MarshalerError$$internal$jsonrt(typeName, err, "MarshalJSON");
|
|
2582
|
-
if (merr.__p !== true && Object.isExtensible(merr)) Object.defineProperty(merr, "__p", { value: true, configurable: true, writable: true });
|
|
2583
|
-
merr.__struct = "MarshalerError$$internal$jsonrt";
|
|
2584
|
-
} else {
|
|
2585
|
-
merr = new Error("json: error calling MarshalJSON for type " + typeName + ": " + (typeof err.Error === "function" ? err.Error() : String(err)));
|
|
2586
|
-
}
|
|
2587
|
-
throw merr;
|
|
2588
|
-
}
|
|
2589
|
-
var b = res ? res[0] : null;
|
|
2590
|
-
var s = b === null || b === undefined ? "" : (typeof b === "string" ? b : new TextDecoder().decode(b));
|
|
2591
|
-
var c = __json_compact(s);
|
|
2592
|
-
if (c === null) throw new Error("json: error calling MarshalJSON for type " + typeName + ": " + __json_syntax_msg(s));
|
|
2593
|
-
return c;
|
|
2594
|
-
};
|
|
2595
|
-
// Keeps user errors returned by UnmarshalJSON intact while fitting the decoders'
|
|
2596
|
-
// "_msg"-tagged error protocol; __json_unmarshal unwraps __userErr.
|
|
2597
|
-
var __json_user_err = __json_user_err || function(e) {
|
|
2598
|
-
if (e && e._msg !== undefined) return e;
|
|
2599
|
-
return { _msg: e && typeof e.Error === "function" ? e.Error() : String(e), __userErr: e };
|
|
2600
|
-
};
|
|
2601
|
-
// Decodes the JSON string payload of a ,string field. Returns { v } or an error.
|
|
2602
|
-
var __json_unquote = __json_unquote || function(val, kind, typeStr) {
|
|
2603
|
-
if (val === null) return { v: null, lit: "null" };
|
|
2604
|
-
if (typeof val !== "string" || val.endsWith("__bigint")) {
|
|
2605
|
-
return __json_err("invalid use of ,string struct tag, trying to unmarshal unquoted value into " + typeStr);
|
|
2606
|
-
}
|
|
2607
|
-
var invalid = function() {
|
|
2608
|
-
return __json_err("invalid use of ,string struct tag, trying to unmarshal " + JSON.stringify(val) + " into " + typeStr);
|
|
2609
|
-
};
|
|
2610
|
-
var inner;
|
|
2611
|
-
try { inner = JSON.parse(__json_preserve_int64(val)); } catch (e) {
|
|
2612
|
-
if (kind !== "string" && kind !== "bool" && /^-?[0-9]/.test(val)) return __json_err("cannot unmarshal number " + val + " into " + __json_ctx(typeStr));
|
|
2613
|
-
return invalid();
|
|
2614
|
-
}
|
|
2615
|
-
if (inner === null) return { v: null, lit: val };
|
|
2616
|
-
if (kind === "string") return typeof inner === "string" ? { v: inner, lit: val } : invalid();
|
|
2617
|
-
if (kind === "bool") return typeof inner === "number" ? invalid() : { v: inner, lit: val };
|
|
2618
|
-
return typeof inner === "boolean" ? invalid() : { v: inner, lit: val };
|
|
2619
|
-
};
|
|
2620
|
-
var __json_type = __json_type || function(v) {
|
|
2621
|
-
if (v === null) return "null";
|
|
2622
|
-
if (Array.isArray(v)) return "array";
|
|
2623
|
-
var t = typeof v;
|
|
2624
|
-
if (t === "number" || t === "bigint") return "number";
|
|
2625
|
-
if (t === "string") return "string";
|
|
2626
|
-
if (t === "boolean") return "bool";
|
|
2627
|
-
if (t === "object") return "object";
|
|
2628
|
-
return t;
|
|
2629
|
-
};
|
|
2630
|
-
var __json_raw_index = __json_raw_index || new WeakMap();
|
|
2631
|
-
var __json_parse_raw_node = __json_parse_raw_node || function(s) {
|
|
2632
|
-
var i = 0;
|
|
2633
|
-
function ws() { while (i < s.length && /[\\t\\n\\r ]/.test(s[i])) i++; }
|
|
2634
|
-
function stringEnd() {
|
|
2635
|
-
i++;
|
|
2636
|
-
while (i < s.length) {
|
|
2637
|
-
if (s[i] === "\\\\") i += 2;
|
|
2638
|
-
else if (s[i++] === '"') break;
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
function value() {
|
|
2642
|
-
ws();
|
|
2643
|
-
var start = i;
|
|
2644
|
-
var node = { children: null };
|
|
2645
|
-
if (s[i] === "{") {
|
|
2646
|
-
i++;
|
|
2647
|
-
node.children = new Map();
|
|
2648
|
-
ws();
|
|
2649
|
-
while (s[i] !== "}") {
|
|
2650
|
-
var keyStart = i;
|
|
2651
|
-
stringEnd();
|
|
2652
|
-
var key = JSON.parse(s.slice(keyStart, i));
|
|
2653
|
-
ws();
|
|
2654
|
-
i++;
|
|
2655
|
-
var child = value();
|
|
2656
|
-
node.children.set(key, child);
|
|
2657
|
-
ws();
|
|
2658
|
-
if (s[i] === ",") { i++; ws(); }
|
|
2659
|
-
else break;
|
|
2660
|
-
}
|
|
2661
|
-
i++;
|
|
2662
|
-
} else if (s[i] === "[") {
|
|
2663
|
-
i++;
|
|
2664
|
-
node.children = new Map();
|
|
2665
|
-
ws();
|
|
2666
|
-
var index = 0;
|
|
2667
|
-
while (s[i] !== "]") {
|
|
2668
|
-
node.children.set(String(index++), value());
|
|
2669
|
-
ws();
|
|
2670
|
-
if (s[i] === ",") { i++; ws(); }
|
|
2671
|
-
else break;
|
|
2672
|
-
}
|
|
2673
|
-
i++;
|
|
2674
|
-
} else if (s[i] === '"') {
|
|
2675
|
-
stringEnd();
|
|
2676
|
-
} else {
|
|
2677
|
-
while (i < s.length && !/[\\t\\n\\r ,}\\]]/.test(s[i])) i++;
|
|
2678
|
-
}
|
|
2679
|
-
node.raw = s.slice(start, i);
|
|
2680
|
-
node.start = start;
|
|
2681
|
-
node.end = i;
|
|
2682
|
-
return node;
|
|
2683
|
-
}
|
|
2684
|
-
return value();
|
|
2685
|
-
};
|
|
2686
|
-
var __json_bind_raw = __json_bind_raw || function(value, node) {
|
|
2687
|
-
if (value === null || typeof value !== "object" || !node?.children) return;
|
|
2688
|
-
__json_raw_index.set(value, node.children);
|
|
2689
|
-
for (const [key, child] of node.children) __json_bind_raw(value[key], child);
|
|
2690
|
-
};
|
|
2691
|
-
var __json_raw_child = __json_raw_child || function(parent, key) {
|
|
2692
|
-
return __json_raw_index.get(parent)?.get(String(key))?.raw;
|
|
2693
|
-
};
|
|
2694
|
-
var __json_raw_end = __json_raw_end || function(parent, key) {
|
|
2695
|
-
return __json_raw_index.get(parent)?.get(String(key))?.end;
|
|
2696
|
-
};
|
|
2697
|
-
var __json_raw_bytes = __json_raw_bytes || function(raw) {
|
|
2698
|
-
return new TextEncoder().encode(raw ?? "null");
|
|
2699
|
-
};
|
|
2700
|
-
var __json_match_field = __json_match_field || function(obj, tagName, fieldName) {
|
|
2701
|
-
if (Object.prototype.hasOwnProperty.call(obj, tagName)) return tagName;
|
|
2702
|
-
if (Object.prototype.hasOwnProperty.call(obj, fieldName)) return fieldName;
|
|
2703
|
-
var tagFold = tagName.toLowerCase();
|
|
2704
|
-
var fieldFold = fieldName.toLowerCase();
|
|
2705
|
-
for (const key of Object.keys(obj)) {
|
|
2706
|
-
var keyFold = key.toLowerCase();
|
|
2707
|
-
if (keyFold === tagFold || keyFold === fieldFold) return key;
|
|
2708
|
-
}
|
|
2709
|
-
return null;
|
|
2710
|
-
};
|
|
2711
|
-
var __json_float64 = __json_float64 || function(v) {
|
|
2712
|
-
if (!isFinite(v)) throw __json_unsupported_value(String(v));
|
|
2713
|
-
return Object.is(v, -0) ? "-0" : String(v);
|
|
2714
|
-
};
|
|
2715
|
-
var __json_float32 = __json_float32 || function(v) {
|
|
2716
|
-
var f = Math.fround(v);
|
|
2717
|
-
if (!isFinite(f)) throw __json_unsupported_value(String(f));
|
|
2718
|
-
if (Object.is(f, -0)) return "-0";
|
|
2719
|
-
var candidate;
|
|
2720
|
-
for (var precision = 1; precision <= 9; precision++) {
|
|
2721
|
-
candidate = f.toPrecision(precision);
|
|
2722
|
-
if (Math.fround(Number(candidate)) === f) break;
|
|
2723
|
-
}
|
|
2724
|
-
var n = Number(candidate);
|
|
2725
|
-
var expText = n.toExponential();
|
|
2726
|
-
var match = /e([+-]?)(\\d+)$/.exec(expText);
|
|
2727
|
-
var exponent = Number(match[2]) * (match[1] === "-" ? -1 : 1);
|
|
2728
|
-
if (exponent < -6 || exponent >= 21) {
|
|
2729
|
-
var mantissa = expText.slice(0, expText.indexOf("e"));
|
|
2730
|
-
var sign = exponent >= 0 ? "+" : "-";
|
|
2731
|
-
return mantissa + "e" + sign + String(Math.abs(exponent));
|
|
2732
|
-
}
|
|
2733
|
-
return n.toString();
|
|
2734
|
-
};
|
|
2735
|
-
var __json_number_value = __json_number_value || function(v) {
|
|
2736
|
-
return typeof v === "string" && v.endsWith("__bigint") ? Number(v.slice(0, -8)) : v;
|
|
2737
|
-
};
|
|
2738
|
-
var __json_int_decode = __json_int_decode || function(v, typeName, ctxType, raw) {
|
|
2739
|
-
var type = typeof v === "string" && v.endsWith("__bigint") ? "number" : __json_type(v);
|
|
2740
|
-
var fail = function() {
|
|
2741
|
-
return __json_err("cannot unmarshal " + (type === "number" ? "number " + __json_lit(v, raw) : type) + " into " + __json_ctx(ctxType));
|
|
2742
|
-
};
|
|
2743
|
-
if (type !== "number") return fail();
|
|
2744
|
-
// Go parses integers with strconv.ParseInt: "1.0" and "1e2" are not integers.
|
|
2745
|
-
if (raw !== undefined && raw !== null && !/^-?(0|[1-9][0-9]*)$/.test(String(raw).trim())) return fail();
|
|
2746
|
-
var integer;
|
|
2747
|
-
var signed = typeName === "int" || typeName.startsWith("int");
|
|
2748
|
-
if (typeName === "int64" || typeName === "uint64") {
|
|
2749
|
-
if (typeof v === "string" && v.endsWith("__bigint")) {
|
|
2750
|
-
try { integer = BigInt(v.slice(0, -8)); } catch (_) {}
|
|
2751
|
-
} else if (typeof v === "number" && Number.isSafeInteger(v)) {
|
|
2752
|
-
integer = BigInt(v);
|
|
2753
|
-
}
|
|
2754
|
-
if (integer !== undefined) {
|
|
2755
|
-
var min64 = typeName === "int64" ? -(1n << 63n) : 0n;
|
|
2756
|
-
var max64 = typeName === "int64" ? (1n << 63n) - 1n : (1n << 64n) - 1n;
|
|
2757
|
-
if (integer >= min64 && integer <= max64) return typeof v === "number" ? v : integer;
|
|
2758
|
-
}
|
|
2759
|
-
return fail();
|
|
2760
|
-
}
|
|
2761
|
-
if (typeof v === "number" && Number.isSafeInteger(v)) {
|
|
2762
|
-
if (typeName === "int") return v;
|
|
2763
|
-
var bits = typeName === "uint" ? 53 : Number(typeName.replace(/^(u?int|byte|rune)/, ""));
|
|
2764
|
-
if (!bits) bits = typeName === "byte" ? 8 : typeName === "rune" ? 32 : 53;
|
|
2765
|
-
var min = signed ? -(2 ** (bits - 1)) : 0;
|
|
2766
|
-
var max = signed ? (2 ** (bits - 1)) - 1 : (2 ** bits) - 1;
|
|
2767
|
-
if (v >= min && v <= max) return v;
|
|
2768
|
-
}
|
|
2769
|
-
return fail();
|
|
2770
|
-
};
|
|
2771
|
-
var __json_b64 = __json_b64 || function(u8) {
|
|
2772
|
-
if (u8 === null || u8 === undefined) return "null";
|
|
2773
|
-
if (typeof __base64_std !== "undefined") return '"' + __base64_std.EncodeToString(u8) + '"';
|
|
2774
|
-
var bstr = "";
|
|
2775
|
-
for (var i = 0; i < u8.length; i++) bstr += String.fromCharCode(u8[i]);
|
|
2776
|
-
return '"' + (typeof btoa !== "undefined" ? btoa(bstr) : Buffer.from(u8).toString("base64")) + '"';
|
|
2777
|
-
};
|
|
2778
|
-
var __json_b64_dec = __json_b64_dec || function(str) {
|
|
2779
|
-
if (typeof __base64_std !== "undefined") {
|
|
2780
|
-
var res = __base64_std.DecodeString(str);
|
|
2781
|
-
if (!res[1]) return res[0];
|
|
2782
|
-
}
|
|
2783
|
-
var bin = typeof atob !== "undefined" ? atob(str) : Buffer.from(str, "base64").toString("binary");
|
|
2784
|
-
var u8 = new Uint8Array(bin.length);
|
|
2785
|
-
for (var i = 0; i < bin.length; i++) u8[i] = bin.charCodeAt(i);
|
|
2786
|
-
return u8;
|
|
2787
|
-
};
|
|
2788
|
-
var __json_is_zero = __json_is_zero || function(val, isStruct, isMap) {
|
|
2789
|
-
if (isStruct) return false;
|
|
2790
|
-
if (isMap) return __json_nilmap(val) || (val instanceof Map ? val.size === 0 : Object.keys(val).length === 0);
|
|
2791
|
-
if (val === null || val === undefined || val === false || val === 0 || val === "") return true;
|
|
2792
|
-
if (typeof val === "bigint") return val === 0n;
|
|
2793
|
-
if (Array.isArray(val) || (ArrayBuffer.isView(val) && !val.__raw)) return val.length === 0;
|
|
2794
|
-
if (val instanceof Map) return val.size === 0;
|
|
2795
|
-
if (val && val.__map) return Object.keys(val).filter(function(k) { return !k.startsWith("__"); }).length === 0;
|
|
2796
|
-
return false;
|
|
2797
|
-
};
|
|
2798
|
-
var __json_preserve_int64 = __json_preserve_int64 || function(str) {
|
|
2799
|
-
return str.replace(/"(?:\\\\.|[^"\\\\])*"|(?<=[,:\\[{\\s]|^)(-?\\d{16,})(?=[,\\]}\\s]|$)/g, function(m, num) {
|
|
2800
|
-
if (num) {
|
|
2801
|
-
try {
|
|
2802
|
-
var b = BigInt(num);
|
|
2803
|
-
if (b > 9007199254740991n || b < -9007199254740991n) return '"' + num + '__bigint"';
|
|
2804
|
-
} catch (e) {}
|
|
2805
|
-
}
|
|
2806
|
-
return m;
|
|
2807
|
-
});
|
|
2808
|
-
};
|
|
2809
|
-
// Go maps: a nil map is the __nm()/__nilmap marker, an empty one a plain object.
|
|
2810
|
-
var __json_nilmap = __json_nilmap || function(m) {
|
|
2811
|
-
return m === null || m === undefined || m.__nilm === true || m.__nm === true;
|
|
2812
|
-
};
|
|
2813
|
-
// Decoded maps carry a hidden marker so fmt and json treat them as maps.
|
|
2814
|
-
var __json_newmap = __json_newmap || function() {
|
|
2815
|
-
return Object.defineProperty(Object.create(null), "__map", { value: true, configurable: true });
|
|
2816
|
-
};
|
|
2817
|
-
// json.RawMessage is compacted (and validated) like any Marshaler output; nil is null.
|
|
2818
|
-
var __json_enc_raw = __json_enc_raw || function(v) {
|
|
2819
|
-
if (v === null || v === undefined) return "null";
|
|
2820
|
-
return __json_marshaler_out([v, null], "json.RawMessage");
|
|
2821
|
-
};
|
|
2822
|
-
var __json_enc_any = __json_enc_any || function(v) {
|
|
2823
|
-
if (v === null || v === undefined) return "null";
|
|
2824
|
-
var t = typeof v;
|
|
2825
|
-
if (t === "boolean") return v ? "true" : "false";
|
|
2826
|
-
if (t === "number") {
|
|
2827
|
-
if (!isFinite(v)) throw __json_unsupported_value(String(v));
|
|
2828
|
-
return Object.is(v, -0) ? "-0" : String(v);
|
|
2829
|
-
}
|
|
2830
|
-
if (t === "bigint") return v.toString();
|
|
2831
|
-
if (t === "string") return __json_esc(v);
|
|
2832
|
-
if (Object.prototype.toString.call(v) === "[object Uint8Array]") {
|
|
2833
|
-
if (v.__raw) return __json_enc_raw(v);
|
|
2834
|
-
return __json_b64(v);
|
|
2835
|
-
}
|
|
2836
|
-
if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(v)) {
|
|
2837
|
-
var titems = [];
|
|
2838
|
-
for (var ti = 0; ti < v.length; ti++) titems.push(v instanceof Float32Array ? __json_float32(v[ti]) : (typeof v[ti] === "bigint" ? v[ti].toString() : String(v[ti])));
|
|
2839
|
-
return "[" + titems.join(",") + "]";
|
|
2840
|
-
}
|
|
2841
|
-
if (Array.isArray(v)) {
|
|
2842
|
-
var items = [];
|
|
2843
|
-
for (var i = 0; i < v.length; i++) items.push(__json_enc_any(v[i]));
|
|
2844
|
-
return "[" + items.join(",") + "]";
|
|
2845
|
-
}
|
|
2846
|
-
if (v instanceof Map) {
|
|
2847
|
-
var mkeys = Array.from(v.keys()).map(String).sort();
|
|
2848
|
-
var mentries = [];
|
|
2849
|
-
for (var mi = 0; mi < mkeys.length; mi++) {
|
|
2850
|
-
mentries.push(__json_esc(mkeys[mi]) + ":" + __json_enc_any(v.get(mkeys[mi])));
|
|
2851
|
-
}
|
|
2852
|
-
return "{" + mentries.join(",") + "}";
|
|
2853
|
-
}
|
|
2854
|
-
if (typeof v.__json_enc === "function") return v.__json_enc();
|
|
2855
|
-
if (typeof v.MarshalJSON === "function" && !(v.__v === true && v.MarshalJSON.__ptrRecv)) {
|
|
2856
|
-
return __json_marshaler_out(v.MarshalJSON(), v.constructor && v.constructor.name ? v.constructor.name : "value");
|
|
2857
|
-
}
|
|
2858
|
-
// Boxed named values (from an interface) encode as their value; *T boxes as the pointee.
|
|
2859
|
-
if (typeof v.__gfUnbox === "function") {
|
|
2860
|
-
var inner = v.__gfUnbox();
|
|
2861
|
-
if (Object.prototype.hasOwnProperty.call(v, "_p")) inner = inner == null ? null : inner.value;
|
|
2862
|
-
return __json_enc_any(inner);
|
|
2863
|
-
}
|
|
2864
|
-
if (typeof v === "object") {
|
|
2865
|
-
if (__json_nilmap(v)) return "null";
|
|
2866
|
-
var okeys = Object.keys(v).filter(function(k) { return !k.startsWith("__") || k === "__proto__"; });
|
|
2867
|
-
if (!v.__map && v.constructor && v.constructor !== Object && v.constructor.name !== "Object") {
|
|
2868
|
-
okeys = okeys.filter(function(k) { return !(k.length > 0 && k[0] >= "a" && k[0] <= "z"); });
|
|
2869
|
-
}
|
|
2870
|
-
okeys.sort();
|
|
2871
|
-
var oentries = [];
|
|
2872
|
-
for (var oi = 0; oi < okeys.length; oi++) {
|
|
2873
|
-
oentries.push(__json_esc(okeys[oi]) + ":" + __json_enc_any(v[okeys[oi]]));
|
|
2874
|
-
}
|
|
2875
|
-
return "{" + oentries.join(",") + "}";
|
|
2876
|
-
}
|
|
2877
|
-
return "null";
|
|
2878
|
-
};
|
|
2879
|
-
var __json_dec_any = __json_dec_any || function(parsed) {
|
|
2880
|
-
if (parsed === null) return null;
|
|
2881
|
-
var useNum = typeof OptUseNumber$$internal$jsonrt !== "undefined" && OptUseNumber$$internal$jsonrt;
|
|
2882
|
-
if (typeof parsed === "string") {
|
|
2883
|
-
if (parsed.endsWith("__bigint")) {
|
|
2884
|
-
var rawBig = parsed.slice(0, -8);
|
|
2885
|
-
if (useNum) return typeof Number$$internal$jsonrt === "function" ? new Number$$internal$jsonrt(rawBig) : rawBig;
|
|
2886
|
-
return Number(rawBig);
|
|
2887
|
-
}
|
|
2888
|
-
return parsed;
|
|
2889
|
-
}
|
|
2890
|
-
if (typeof parsed === "number") {
|
|
2891
|
-
if (useNum) {
|
|
2892
|
-
var rawNum = String(parsed);
|
|
2893
|
-
return typeof Number$$internal$jsonrt === "function" ? new Number$$internal$jsonrt(rawNum) : rawNum;
|
|
2894
|
-
}
|
|
2895
|
-
return parsed;
|
|
2896
|
-
}
|
|
2897
|
-
if (typeof parsed === "boolean") return parsed;
|
|
2898
|
-
if (Array.isArray(parsed)) {
|
|
2899
|
-
var outSlice = [];
|
|
2900
|
-
for (var i = 0; i < parsed.length; i++) outSlice.push(__json_dec_any(parsed[i]));
|
|
2901
|
-
return outSlice;
|
|
2902
|
-
}
|
|
2903
|
-
if (typeof parsed === "object") {
|
|
2904
|
-
var outMap = __json_newmap();
|
|
2905
|
-
for (var k in parsed) {
|
|
2906
|
-
if (Object.prototype.hasOwnProperty.call(parsed, k)) {
|
|
2907
|
-
outMap[k] = __json_dec_any(parsed[k]);
|
|
2908
|
-
}
|
|
2909
|
-
}
|
|
2910
|
-
return outMap;
|
|
2911
|
-
}
|
|
2912
|
-
return parsed;
|
|
2913
|
-
};
|
|
2914
|
-
var __json_dec_any_target = __json_dec_any_target || function(parsed, target, box) {
|
|
2915
|
-
var out = __json_dec_any(parsed);
|
|
2916
|
-
if (box) box.value = out;
|
|
2917
|
-
else if (target && typeof target === "object") {
|
|
2918
|
-
for (const k of Object.keys(out)) Object.defineProperty(target, k, { value: out[k], writable: true, enumerable: true, configurable: true });
|
|
2919
|
-
}
|
|
2920
|
-
return null;
|
|
2921
|
-
};
|
|
2922
|
-
var __json_enc_slice = __json_enc_slice || function(slice, elemEnc) {
|
|
2923
|
-
if (slice === null || slice === undefined) return "null";
|
|
2924
|
-
var items = [];
|
|
2925
|
-
for (var i = 0; i < slice.length; i++) items.push(elemEnc(slice[i]));
|
|
2926
|
-
return "[" + items.join(",") + "]";
|
|
2927
|
-
};
|
|
2928
|
-
var __json_enc_map = __json_enc_map || function(m, valEnc) {
|
|
2929
|
-
if (__json_nilmap(m)) return "null";
|
|
2930
|
-
if (m instanceof Map) {
|
|
2931
|
-
var mkeys = Array.from(m.keys()).map(String).sort();
|
|
2932
|
-
var mentries = [];
|
|
2933
|
-
for (var i = 0; i < mkeys.length; i++) {
|
|
2934
|
-
mentries.push(__json_esc(mkeys[i]) + ":" + valEnc(m.get(mkeys[i])));
|
|
2935
|
-
}
|
|
2936
|
-
return "{" + mentries.join(",") + "}";
|
|
2937
|
-
}
|
|
2938
|
-
var keys = Object.keys(m).filter(function(k) { return !k.startsWith("__") || k === "__proto__"; }).sort();
|
|
2939
|
-
var entries = [];
|
|
2940
|
-
for (var j = 0; j < keys.length; j++) {
|
|
2941
|
-
entries.push(__json_esc(keys[j]) + ":" + valEnc(m[keys[j]]));
|
|
2942
|
-
}
|
|
2943
|
-
return "{" + entries.join(",") + "}";
|
|
2944
|
-
};
|
|
2945
|
-
var __json_marshal = __json_marshal || function(enc, val) {
|
|
2946
|
-
try {
|
|
2947
|
-
var str = enc(val);
|
|
2948
|
-
return [new TextEncoder().encode(str), null];
|
|
2949
|
-
} catch (e) {
|
|
2950
|
-
if (e && typeof e.Error === "function") return [new Uint8Array(0), e];
|
|
2951
|
-
return [new Uint8Array(0), typeof __error === "function" ? __error(e.message || String(e)) : e];
|
|
2952
|
-
}
|
|
2953
|
-
};
|
|
2954
|
-
var __json_indent = __json_indent || function(jsonStr, prefix, indent) {
|
|
2955
|
-
var out = "";
|
|
2956
|
-
var depth = 0;
|
|
2957
|
-
var inString = false;
|
|
2958
|
-
var escaped = false;
|
|
2959
|
-
for (var i = 0; i < jsonStr.length; i++) {
|
|
2960
|
-
var c = jsonStr[i];
|
|
2961
|
-
if (inString) {
|
|
2962
|
-
out += c;
|
|
2963
|
-
if (escaped) escaped = false;
|
|
2964
|
-
else if (c === "\\\\") escaped = true;
|
|
2965
|
-
else if (c === '"') inString = false;
|
|
2966
|
-
continue;
|
|
2967
|
-
}
|
|
2968
|
-
if (c === '"') { inString = true; out += c; continue; }
|
|
2969
|
-
if (c === "{" || c === "[") {
|
|
2970
|
-
out += c;
|
|
2971
|
-
depth++;
|
|
2972
|
-
var next = jsonStr[i + 1];
|
|
2973
|
-
if ((c === "{" && next === "}") || (c === "[" && next === "]")) {
|
|
2974
|
-
out += next;
|
|
2975
|
-
i++;
|
|
2976
|
-
depth--;
|
|
2977
|
-
continue;
|
|
2978
|
-
}
|
|
2979
|
-
out += "\\n" + prefix + indent.repeat(depth);
|
|
2980
|
-
} else if (c === "}" || c === "]") {
|
|
2981
|
-
depth--;
|
|
2982
|
-
out += "\\n" + prefix + indent.repeat(depth) + c;
|
|
2983
|
-
} else if (c === ",") {
|
|
2984
|
-
out += ",\\n" + prefix + indent.repeat(depth);
|
|
2985
|
-
} else if (c === ":") {
|
|
2986
|
-
out += ": ";
|
|
2987
|
-
} else if (c !== " " && c !== "\\t" && c !== "\\n" && c !== "\\r") {
|
|
2988
|
-
out += c;
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
return out;
|
|
2992
|
-
};
|
|
2993
|
-
var __json_marshal_indent = __json_marshal_indent || function(enc, val, prefix, indent) {
|
|
2994
|
-
var res = __json_marshal(enc, val);
|
|
2995
|
-
if (res[1]) return res;
|
|
2996
|
-
var rawStr = new TextDecoder().decode(res[0]);
|
|
2997
|
-
var formatted = __json_indent(rawStr, prefix, indent);
|
|
2998
|
-
return [new TextEncoder().encode(formatted), null];
|
|
2999
|
-
};
|
|
3000
|
-
var __json_valid = __json_valid || function(data) {
|
|
3001
|
-
try {
|
|
3002
|
-
var s = typeof data === "string" ? data : new TextDecoder().decode(((typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data)) || data instanceof Uint8Array) ? data : new Uint8Array(data));
|
|
3003
|
-
JSON.parse(s);
|
|
3004
|
-
return true;
|
|
3005
|
-
} catch (e) {
|
|
3006
|
-
return false;
|
|
3007
|
-
}
|
|
3008
|
-
};
|
|
3009
|
-
// The static type of the target decides the argument errors, as in Go:
|
|
3010
|
-
// targetKind is "ptr" (a pointer), "val" (neither pointer nor interface) or
|
|
3011
|
-
// empty (an interface, judged by the dynamic value).
|
|
3012
|
-
var __json_invalid_target = __json_invalid_target || function(name, isPtr) {
|
|
3013
|
-
if (typeof InvalidUnmarshalError$$internal$jsonrt === "function") {
|
|
3014
|
-
var e = new InvalidUnmarshalError$$internal$jsonrt(name, isPtr);
|
|
3015
|
-
if (e.__p !== true && Object.isExtensible(e)) Object.defineProperty(e, "__p", { value: true, configurable: true, writable: true });
|
|
3016
|
-
e.__struct = "InvalidUnmarshalError$$internal$jsonrt";
|
|
3017
|
-
return e;
|
|
3018
|
-
}
|
|
3019
|
-
var msg = name === "" ? "json: Unmarshal(nil)" : (isPtr ? "json: Unmarshal(nil " + name + ")" : "json: Unmarshal(non-pointer " + name + ")");
|
|
3020
|
-
return typeof __error === "function" ? __error(msg) : new Error(msg);
|
|
3021
|
-
};
|
|
3022
|
-
var __json_unmarshal = __json_unmarshal || function(dec, data, target, targetTypeName, targetKind) {
|
|
3023
|
-
__json_structs.length = 0;
|
|
3024
|
-
__json_path.length = 0;
|
|
3025
|
-
__json_current_offset = 0;
|
|
3026
|
-
var u8data = ((typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data)) || data instanceof Uint8Array) ? data : new Uint8Array(data);
|
|
3027
|
-
if (typeof CheckValid$$internal$jsonrt === "function") {
|
|
3028
|
-
var syntaxErr = CheckValid$$internal$jsonrt(u8data);
|
|
3029
|
-
if (syntaxErr) {
|
|
3030
|
-
if (typeof syntaxErr === "object" && syntaxErr !== null) {
|
|
3031
|
-
if (syntaxErr.__p !== true && Object.isExtensible(syntaxErr)) {
|
|
3032
|
-
Object.defineProperty(syntaxErr, "__p", { value: true, configurable: true, writable: true });
|
|
3033
|
-
}
|
|
3034
|
-
syntaxErr.__struct = "SyntaxError$$internal$jsonrt";
|
|
3035
|
-
}
|
|
3036
|
-
return syntaxErr;
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
if (targetKind === "val") return __json_invalid_target(targetTypeName, false);
|
|
3040
|
-
if (target === null || target === undefined) {
|
|
3041
|
-
return targetKind === "ptr" ? __json_invalid_target(targetTypeName, true) : __json_invalid_target("", false);
|
|
3042
|
-
}
|
|
3043
|
-
if (typeof target !== "object" || target.__v === true) {
|
|
3044
|
-
var tname = targetTypeName || (target && target.constructor && target.constructor.name && target.constructor.name !== "Object" ? target.constructor.name : typeof target);
|
|
3045
|
-
return __json_invalid_target(tname, false);
|
|
3046
|
-
}
|
|
3047
|
-
var str;
|
|
3048
|
-
try {
|
|
3049
|
-
str = typeof data === "string" ? data : new TextDecoder().decode(u8data);
|
|
3050
|
-
} catch (e) {
|
|
3051
|
-
return typeof __error === "function" ? __error("invalid UTF-8 data") : e;
|
|
3052
|
-
}
|
|
3053
|
-
var safeStr = __json_preserve_int64(str);
|
|
3054
|
-
var parsed;
|
|
3055
|
-
try {
|
|
3056
|
-
parsed = JSON.parse(safeStr);
|
|
3057
|
-
} catch (e) {
|
|
3058
|
-
return typeof __error === "function" ? __error(e.message) : e;
|
|
3059
|
-
}
|
|
3060
|
-
var rootRaw = __json_parse_raw_node(str);
|
|
3061
|
-
__json_bind_raw(parsed, rootRaw);
|
|
3062
|
-
__json_current_offset = str.length;
|
|
3063
|
-
var isBox = target && typeof target === "object" && (Object.prototype.hasOwnProperty.call(target, "value") || typeof target.__gfUnbox === "function");
|
|
3064
|
-
var dest = isBox ? target.value : target;
|
|
3065
|
-
var err = dec(parsed, dest, isBox ? target : null, data, rootRaw.raw);
|
|
3066
|
-
if (err) return err.__userErr || err;
|
|
3067
|
-
return null;
|
|
3068
|
-
};
|
|
3069
|
-
var __json_encoder_encode = __json_encoder_encode || function(enc, codec, v) {
|
|
3070
|
-
var e = enc?.value ?? enc;
|
|
3071
|
-
if (e.err != null) return e.err;
|
|
3072
|
-
OptEscapeHTML$$internal$jsonrt = e.escapeHTML;
|
|
3073
|
-
var jsonStr;
|
|
3074
|
-
try {
|
|
3075
|
-
jsonStr = codec(v);
|
|
3076
|
-
} catch (err) {
|
|
3077
|
-
if (err && typeof err.Error === "function") return err;
|
|
3078
|
-
return typeof __error === "function" ? __error(err.message || String(err)) : err;
|
|
3079
|
-
} finally {
|
|
3080
|
-
OptEscapeHTML$$internal$jsonrt = true;
|
|
3081
|
-
}
|
|
3082
|
-
if (e.indent !== "" || e.prefix !== "") {
|
|
3083
|
-
var indented = __json_indent(jsonStr, e.prefix, e.indent);
|
|
3084
|
-
if (indented != null) jsonStr = indented;
|
|
3085
|
-
}
|
|
3086
|
-
var bytes = new TextEncoder().encode(jsonStr + "\\n");
|
|
3087
|
-
var res = e.w.Write(bytes);
|
|
3088
|
-
var err = Array.isArray(res) ? res[1] : null;
|
|
3089
|
-
if (err != null) {
|
|
3090
|
-
e.err = err;
|
|
3091
|
-
return err;
|
|
3092
|
-
}
|
|
3093
|
-
return null;
|
|
3094
|
-
};
|
|
3095
|
-
var __json_decoder_decode = __json_decoder_decode || function(dec, decFn, target, targetTypeName, targetKind) {
|
|
3096
|
-
var d = dec?.value ?? dec;
|
|
3097
|
-
var res = ScanNext$$internal$jsonrt(d.r);
|
|
3098
|
-
var data = res[0], skipped = res[1], err = res[2];
|
|
3099
|
-
d.offset += skipped;
|
|
3100
|
-
if (err != null) return err;
|
|
3101
|
-
d.offset += data.length;
|
|
3102
|
-
OptUseNumber$$internal$jsonrt = d.useNumber;
|
|
3103
|
-
OptDisallowUnknownFields$$internal$jsonrt = d.disallowUnknownFields;
|
|
3104
|
-
var uerr;
|
|
3105
|
-
try {
|
|
3106
|
-
uerr = __json_unmarshal(decFn, data, target, targetTypeName, targetKind);
|
|
3107
|
-
} finally {
|
|
3108
|
-
OptUseNumber$$internal$jsonrt = false;
|
|
3109
|
-
OptDisallowUnknownFields$$internal$jsonrt = false;
|
|
3110
|
-
}
|
|
3111
|
-
return uerr;
|
|
1055
|
+
var __jvalid = __jvalid || function(data) {
|
|
1056
|
+
if (data === null || data === undefined) return false;
|
|
1057
|
+
var n = data.length;
|
|
1058
|
+
if (n > 10000) {
|
|
1059
|
+
// encoding/json stops at a nesting depth of 10000.
|
|
1060
|
+
var depth = 0, inStr = false;
|
|
1061
|
+
for (var i = 0; i < n; i++) {
|
|
1062
|
+
var c = data[i];
|
|
1063
|
+
if (inStr) { if (c === 92) i++; else if (c === 34) inStr = false; }
|
|
1064
|
+
else if (c === 34) inStr = true;
|
|
1065
|
+
else if (c === 91 || c === 123) { if (++depth > 10000) return false; }
|
|
1066
|
+
else if (c === 93 || c === 125) depth--;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
try { JSON.parse(__jtd.decode(data)); return true; } catch (e) { return false; }
|
|
1070
|
+
};
|
|
1071
|
+
var __jquote = __jquote || function(e, s) {
|
|
1072
|
+
__jroom(e, 1);
|
|
1073
|
+
e.buf[e.n++] = 34;
|
|
1074
|
+
__jput(e, (e.EscapeHTML ? __jescRe : __jescRe2).test(s) ? __jesc(s, e.EscapeHTML) : s);
|
|
1075
|
+
__jroom(e, 1);
|
|
1076
|
+
e.buf[e.n++] = 34;
|
|
3112
1077
|
};`;
|
|
3113
1078
|
|
|
3114
1079
|
export const HELPER_SIMD = `var __simd_f32x4 = __simd_f32x4 || function(a, b, c, d) {
|