esbuild-wasm-strapkit 0.25.3-build.2 → 0.25.4-build.2
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/esbuild.wasm +0 -0
- package/esm/browser.d.ts +6 -0
- package/esm/browser.js +42 -56
- package/esm/browser.min.js +8 -8
- package/lib/browser.d.ts +6 -0
- package/lib/browser.js +42 -56
- package/lib/browser.min.js +7 -7
- package/lib/main.d.ts +6 -0
- package/lib/main.js +44 -58
- package/package.json +3 -3
package/esbuild.wasm
CHANGED
|
Binary file
|
package/esm/browser.d.ts
CHANGED
|
@@ -241,9 +241,15 @@ export interface ServeOptions {
|
|
|
241
241
|
keyfile?: string
|
|
242
242
|
certfile?: string
|
|
243
243
|
fallback?: string
|
|
244
|
+
cors?: CORSOptions
|
|
244
245
|
onRequest?: (args: ServeOnRequestArgs) => void
|
|
245
246
|
}
|
|
246
247
|
|
|
248
|
+
/** Documentation: https://esbuild.github.io/api/#cors */
|
|
249
|
+
export interface CORSOptions {
|
|
250
|
+
origin?: string | string[]
|
|
251
|
+
}
|
|
252
|
+
|
|
247
253
|
export interface ServeOnRequestArgs {
|
|
248
254
|
remoteAddress: string
|
|
249
255
|
method: string
|
package/esm/browser.js
CHANGED
|
@@ -194,10 +194,14 @@ function writeUInt32LE(buffer, value, offset) {
|
|
|
194
194
|
var quote = JSON.stringify;
|
|
195
195
|
var buildLogLevelDefault = "warning";
|
|
196
196
|
var transformLogLevelDefault = "silent";
|
|
197
|
-
function
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
function validateAndJoinStringArray(values, what) {
|
|
198
|
+
const toJoin = [];
|
|
199
|
+
for (const value of values) {
|
|
200
|
+
validateStringValue(value, what);
|
|
201
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
|
|
202
|
+
toJoin.push(value);
|
|
203
|
+
}
|
|
204
|
+
return toJoin.join(",");
|
|
201
205
|
}
|
|
202
206
|
var canBeAnything = () => null;
|
|
203
207
|
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
@@ -207,13 +211,14 @@ var mustBeInteger = (value) => typeof value === "number" && value === (value | 0
|
|
|
207
211
|
var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
|
|
208
212
|
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
209
213
|
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
214
|
+
var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "an array of strings";
|
|
210
215
|
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
211
216
|
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
212
217
|
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
213
218
|
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
214
219
|
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
215
220
|
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
216
|
-
var
|
|
221
|
+
var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "a string or an array of strings";
|
|
217
222
|
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
|
218
223
|
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
|
219
224
|
function getFlag(object, keys, key, mustBeFn) {
|
|
@@ -277,7 +282,7 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
277
282
|
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
278
283
|
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
279
284
|
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
|
280
|
-
let target = getFlag(options, keys, "target",
|
|
285
|
+
let target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings);
|
|
281
286
|
let format = getFlag(options, keys, "format", mustBeString);
|
|
282
287
|
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
|
283
288
|
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
|
@@ -288,8 +293,8 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
288
293
|
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
|
289
294
|
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
|
290
295
|
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
|
291
|
-
let drop = getFlag(options, keys, "drop",
|
|
292
|
-
let dropLabels = getFlag(options, keys, "dropLabels",
|
|
296
|
+
let drop = getFlag(options, keys, "drop", mustBeArrayOfStrings);
|
|
297
|
+
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
|
|
293
298
|
let charset = getFlag(options, keys, "charset", mustBeString);
|
|
294
299
|
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
|
295
300
|
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
|
@@ -302,17 +307,14 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
302
307
|
let define = getFlag(options, keys, "define", mustBeObject);
|
|
303
308
|
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
|
304
309
|
let supported = getFlag(options, keys, "supported", mustBeObject);
|
|
305
|
-
let pure = getFlag(options, keys, "pure",
|
|
310
|
+
let pure = getFlag(options, keys, "pure", mustBeArrayOfStrings);
|
|
306
311
|
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
307
312
|
let platform = getFlag(options, keys, "platform", mustBeString);
|
|
308
313
|
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
|
309
314
|
if (legalComments) flags.push(`--legal-comments=${legalComments}`);
|
|
310
315
|
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
|
311
316
|
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
|
312
|
-
if (target) {
|
|
313
|
-
if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
|
|
314
|
-
else flags.push(`--target=${validateTarget(target)}`);
|
|
315
|
-
}
|
|
317
|
+
if (target) flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
|
|
316
318
|
if (format) flags.push(`--format=${format}`);
|
|
317
319
|
if (globalName) flags.push(`--global-name=${globalName}`);
|
|
318
320
|
if (platform) flags.push(`--platform=${platform}`);
|
|
@@ -326,7 +328,7 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
326
328
|
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
|
327
329
|
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
|
328
330
|
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
329
|
-
if (dropLabels) flags.push(`--drop-labels=${
|
|
331
|
+
if (dropLabels) flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
|
|
330
332
|
if (mangleProps) flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
|
|
331
333
|
if (reserveProps) flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
|
|
332
334
|
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
@@ -377,11 +379,11 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
|
377
379
|
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
|
378
380
|
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
|
379
381
|
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
|
380
|
-
let resolveExtensions = getFlag(options, keys, "resolveExtensions",
|
|
381
|
-
let nodePathsInput = getFlag(options, keys, "nodePaths",
|
|
382
|
-
let mainFields = getFlag(options, keys, "mainFields",
|
|
383
|
-
let conditions = getFlag(options, keys, "conditions",
|
|
384
|
-
let external = getFlag(options, keys, "external",
|
|
382
|
+
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
|
|
383
|
+
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
|
|
384
|
+
let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
|
|
385
|
+
let conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
|
|
386
|
+
let external = getFlag(options, keys, "external", mustBeArrayOfStrings);
|
|
385
387
|
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
386
388
|
let alias = getFlag(options, keys, "alias", mustBeObject);
|
|
387
389
|
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
@@ -390,7 +392,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
|
390
392
|
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
391
393
|
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
392
394
|
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
393
|
-
let inject = getFlag(options, keys, "inject",
|
|
395
|
+
let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
|
|
394
396
|
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
395
397
|
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
396
398
|
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
@@ -412,37 +414,13 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
|
412
414
|
if (outbase) flags.push(`--outbase=${outbase}`);
|
|
413
415
|
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
|
414
416
|
if (packages) flags.push(`--packages=${packages}`);
|
|
415
|
-
if (resolveExtensions) {
|
|
416
|
-
let values = [];
|
|
417
|
-
for (let value of resolveExtensions) {
|
|
418
|
-
validateStringValue(value, "resolve extension");
|
|
419
|
-
if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`);
|
|
420
|
-
values.push(value);
|
|
421
|
-
}
|
|
422
|
-
flags.push(`--resolve-extensions=${values.join(",")}`);
|
|
423
|
-
}
|
|
417
|
+
if (resolveExtensions) flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
|
|
424
418
|
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
|
425
419
|
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
|
426
420
|
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
|
427
421
|
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
|
428
|
-
if (mainFields) {
|
|
429
|
-
|
|
430
|
-
for (let value of mainFields) {
|
|
431
|
-
validateStringValue(value, "main field");
|
|
432
|
-
if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`);
|
|
433
|
-
values.push(value);
|
|
434
|
-
}
|
|
435
|
-
flags.push(`--main-fields=${values.join(",")}`);
|
|
436
|
-
}
|
|
437
|
-
if (conditions) {
|
|
438
|
-
let values = [];
|
|
439
|
-
for (let value of conditions) {
|
|
440
|
-
validateStringValue(value, "condition");
|
|
441
|
-
if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`);
|
|
442
|
-
values.push(value);
|
|
443
|
-
}
|
|
444
|
-
flags.push(`--conditions=${values.join(",")}`);
|
|
445
|
-
}
|
|
422
|
+
if (mainFields) flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
|
|
423
|
+
if (conditions) flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`);
|
|
446
424
|
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
447
425
|
if (alias) {
|
|
448
426
|
for (let old in alias) {
|
|
@@ -639,8 +617,8 @@ function createChannel(streamIn) {
|
|
|
639
617
|
if (isFirstPacket) {
|
|
640
618
|
isFirstPacket = false;
|
|
641
619
|
let binaryVersion = String.fromCharCode(...bytes);
|
|
642
|
-
if (binaryVersion !== "0.25.
|
|
643
|
-
throw new Error(`Cannot start service: Host version "${"0.25.
|
|
620
|
+
if (binaryVersion !== "0.25.4") {
|
|
621
|
+
throw new Error(`Cannot start service: Host version "${"0.25.4"}" does not match binary version ${quote(binaryVersion)}`);
|
|
644
622
|
}
|
|
645
623
|
return;
|
|
646
624
|
}
|
|
@@ -1001,6 +979,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1001
979
|
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
1002
980
|
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
1003
981
|
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
|
982
|
+
const cors = getFlag(options2, keys, "cors", mustBeObject);
|
|
1004
983
|
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
1005
984
|
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
1006
985
|
const request2 = {
|
|
@@ -1014,6 +993,13 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1014
993
|
if (keyfile !== void 0) request2.keyfile = keyfile;
|
|
1015
994
|
if (certfile !== void 0) request2.certfile = certfile;
|
|
1016
995
|
if (fallback !== void 0) request2.fallback = fallback;
|
|
996
|
+
if (cors) {
|
|
997
|
+
const corsKeys = {};
|
|
998
|
+
const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
|
999
|
+
checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
|
|
1000
|
+
if (Array.isArray(origin)) request2.corsOrigin = origin;
|
|
1001
|
+
else if (origin !== void 0) request2.corsOrigin = [origin];
|
|
1002
|
+
}
|
|
1017
1003
|
sendRequest(refs, request2, (error2, response2) => {
|
|
1018
1004
|
if (error2) return reject(new Error(error2));
|
|
1019
1005
|
if (onRequest) {
|
|
@@ -1221,8 +1207,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1221
1207
|
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
1222
1208
|
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1223
1209
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1224
|
-
let watchFiles = getFlag(result, keys, "watchFiles",
|
|
1225
|
-
let watchDirs = getFlag(result, keys, "watchDirs",
|
|
1210
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
1211
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
1226
1212
|
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
1227
1213
|
response.id = id2;
|
|
1228
1214
|
if (pluginName != null) response.pluginName = pluginName;
|
|
@@ -1267,8 +1253,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1267
1253
|
let loader = getFlag(result, keys, "loader", mustBeString);
|
|
1268
1254
|
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1269
1255
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1270
|
-
let watchFiles = getFlag(result, keys, "watchFiles",
|
|
1271
|
-
let watchDirs = getFlag(result, keys, "watchDirs",
|
|
1256
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
1257
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
1272
1258
|
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
1273
1259
|
response.id = id2;
|
|
1274
1260
|
if (pluginName != null) response.pluginName = pluginName;
|
|
@@ -1579,7 +1565,7 @@ function jsRegExpToGoRegExp(regexp) {
|
|
|
1579
1565
|
}
|
|
1580
1566
|
|
|
1581
1567
|
// lib/npm/browser.ts
|
|
1582
|
-
var version = "0.25.
|
|
1568
|
+
var version = "0.25.4";
|
|
1583
1569
|
var build = (options) => ensureServiceIsRunning().build(options);
|
|
1584
1570
|
var context = (options) => ensureServiceIsRunning().context(options);
|
|
1585
1571
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
@@ -1627,7 +1613,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
|
1627
1613
|
let rejectAllWith;
|
|
1628
1614
|
const rejectAllPromise = new Promise((resolve) => rejectAllWith = resolve);
|
|
1629
1615
|
if (useWorker) {
|
|
1630
|
-
let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const setInt32 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n _gotest: {\n add: (a, b) => a + b\n },\n gojs: {\n // Go\'s SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n // func wasmExit(code int32)\n "runtime.wasmExit": (sp) => {\n sp = Number(sp);\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n "runtime.wasmWrite": (sp) => {\n sp = Number(sp);\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n // func resetMemoryDataView()\n "runtime.resetMemoryDataView": (sp) => {\n sp = Number(sp);\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n // func nanotime1() int64\n "runtime.nanotime1": (sp) => {\n sp = Number(sp);\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n // func walltime() (sec int64, nsec int32)\n "runtime.walltime": (sp) => {\n sp = Number(sp);\n const msec = (/* @__PURE__ */ new Date()).getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n // func scheduleTimeoutEvent(delay int64) int32\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp = Number(sp);\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8)\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n // func clearTimeoutEvent(id int32)\n "runtime.clearTimeoutEvent": (sp) => {\n sp = Number(sp);\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n // func getRandomData(r []byte)\n "runtime.getRandomData": (sp) => {\n sp = Number(sp);\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n // func finalizeRef(v ref)\n "syscall/js.finalizeRef": (sp) => {\n sp = Number(sp);\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n // func stringVal(value string) ref\n "syscall/js.stringVal": (sp) => {\n sp = Number(sp);\n storeValue(sp + 24, loadString(sp + 8));\n },\n // func valueGet(v ref, p string) ref\n "syscall/js.valueGet": (sp) => {\n sp = Number(sp);\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 32, result);\n },\n // func valueSet(v ref, p string, x ref)\n "syscall/js.valueSet": (sp) => {\n sp = Number(sp);\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n // func valueDelete(v ref, p string)\n "syscall/js.valueDelete": (sp) => {\n sp = Number(sp);\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n // func valueIndex(v ref, i int) ref\n "syscall/js.valueIndex": (sp) => {\n sp = Number(sp);\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n // valueSetIndex(v ref, i int, x ref)\n "syscall/js.valueSetIndex": (sp) => {\n sp = Number(sp);\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n // func valueCall(v ref, m string, args []ref) (ref, bool)\n "syscall/js.valueCall": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n // func valueInvoke(v ref, args []ref) (ref, bool)\n "syscall/js.valueInvoke": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueNew(v ref, args []ref) (ref, bool)\n "syscall/js.valueNew": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueLength(v ref) int\n "syscall/js.valueLength": (sp) => {\n sp = Number(sp);\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n // valuePrepareString(v ref) (ref, int)\n "syscall/js.valuePrepareString": (sp) => {\n sp = Number(sp);\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n // valueLoadString(v ref, b []byte)\n "syscall/js.valueLoadString": (sp) => {\n sp = Number(sp);\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n // func valueInstanceOf(v ref, t ref) bool\n "syscall/js.valueInstanceOf": (sp) => {\n sp = Number(sp);\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n // func copyBytesToGo(dst []byte, src ref) (int, bool)\n "syscall/js.copyBytesToGo": (sp) => {\n sp = Number(sp);\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n // func copyBytesToJS(dst ref, src []byte) (int, bool)\n "syscall/js.copyBytesToJS": (sp) => {\n sp = Number(sp);\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n // JS values that Go currently has references to, indexed by reference id\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n // mapping from JS values to reference ids\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1) console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin) resumeStdin();\n }\n return go;\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.25.3"}`];\n tryToInstantiateModule(wasm, go).then(\n (instance) => {\n postMessage(null);\n go.run(instance);\n },\n (error) => {\n postMessage(error);\n }\n );\n return go;\n };\n async function tryToInstantiateModule(wasm, go) {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = await fetch(wasm);\n if (!res.ok) throw new Error(`Failed to download ${JSON.stringify(wasm)}`);\n if ("instantiateStreaming" in WebAssembly && /^application\\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {\n const result2 = await WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = await res.arrayBuffer();\n const result = await WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
|
|
1616
|
+
let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const setInt32 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n _gotest: {\n add: (a, b) => a + b\n },\n gojs: {\n // Go\'s SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n // func wasmExit(code int32)\n "runtime.wasmExit": (sp) => {\n sp = Number(sp);\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n "runtime.wasmWrite": (sp) => {\n sp = Number(sp);\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n // func resetMemoryDataView()\n "runtime.resetMemoryDataView": (sp) => {\n sp = Number(sp);\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n // func nanotime1() int64\n "runtime.nanotime1": (sp) => {\n sp = Number(sp);\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n // func walltime() (sec int64, nsec int32)\n "runtime.walltime": (sp) => {\n sp = Number(sp);\n const msec = (/* @__PURE__ */ new Date()).getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n // func scheduleTimeoutEvent(delay int64) int32\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp = Number(sp);\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8)\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n // func clearTimeoutEvent(id int32)\n "runtime.clearTimeoutEvent": (sp) => {\n sp = Number(sp);\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n // func getRandomData(r []byte)\n "runtime.getRandomData": (sp) => {\n sp = Number(sp);\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n // func finalizeRef(v ref)\n "syscall/js.finalizeRef": (sp) => {\n sp = Number(sp);\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n // func stringVal(value string) ref\n "syscall/js.stringVal": (sp) => {\n sp = Number(sp);\n storeValue(sp + 24, loadString(sp + 8));\n },\n // func valueGet(v ref, p string) ref\n "syscall/js.valueGet": (sp) => {\n sp = Number(sp);\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 32, result);\n },\n // func valueSet(v ref, p string, x ref)\n "syscall/js.valueSet": (sp) => {\n sp = Number(sp);\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n // func valueDelete(v ref, p string)\n "syscall/js.valueDelete": (sp) => {\n sp = Number(sp);\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n // func valueIndex(v ref, i int) ref\n "syscall/js.valueIndex": (sp) => {\n sp = Number(sp);\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n // valueSetIndex(v ref, i int, x ref)\n "syscall/js.valueSetIndex": (sp) => {\n sp = Number(sp);\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n // func valueCall(v ref, m string, args []ref) (ref, bool)\n "syscall/js.valueCall": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n // func valueInvoke(v ref, args []ref) (ref, bool)\n "syscall/js.valueInvoke": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueNew(v ref, args []ref) (ref, bool)\n "syscall/js.valueNew": (sp) => {\n sp = Number(sp);\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = Number(this._inst.exports.getsp());\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueLength(v ref) int\n "syscall/js.valueLength": (sp) => {\n sp = Number(sp);\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n // valuePrepareString(v ref) (ref, int)\n "syscall/js.valuePrepareString": (sp) => {\n sp = Number(sp);\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n // valueLoadString(v ref, b []byte)\n "syscall/js.valueLoadString": (sp) => {\n sp = Number(sp);\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n // func valueInstanceOf(v ref, t ref) bool\n "syscall/js.valueInstanceOf": (sp) => {\n sp = Number(sp);\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n // func copyBytesToGo(dst []byte, src ref) (int, bool)\n "syscall/js.copyBytesToGo": (sp) => {\n sp = Number(sp);\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n // func copyBytesToJS(dst ref, src []byte) (int, bool)\n "syscall/js.copyBytesToJS": (sp) => {\n sp = Number(sp);\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n // JS values that Go currently has references to, indexed by reference id\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n // mapping from JS values to reference ids\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1) console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin) resumeStdin();\n }\n return go;\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.25.4"}`];\n tryToInstantiateModule(wasm, go).then(\n (instance) => {\n postMessage(null);\n go.run(instance);\n },\n (error) => {\n postMessage(error);\n }\n );\n return go;\n };\n async function tryToInstantiateModule(wasm, go) {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = await fetch(wasm);\n if (!res.ok) throw new Error(`Failed to download ${JSON.stringify(wasm)}`);\n if ("instantiateStreaming" in WebAssembly && /^application\\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {\n const result2 = await WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = await res.arrayBuffer();\n const result = await WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
|
|
1631
1617
|
worker = new Worker(URL.createObjectURL(blob));
|
|
1632
1618
|
} else {
|
|
1633
1619
|
let onmessage = ((postMessage) => {
|
|
@@ -2245,7 +2231,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
|
2245
2231
|
callback(null, count);
|
|
2246
2232
|
};
|
|
2247
2233
|
let go = new globalThis.Go();
|
|
2248
|
-
go.argv = ["", `--service=${"0.25.
|
|
2234
|
+
go.argv = ["", `--service=${"0.25.4"}`];
|
|
2249
2235
|
tryToInstantiateModule(wasm, go).then(
|
|
2250
2236
|
(instance) => {
|
|
2251
2237
|
postMessage(null);
|