@getpara/server-sdk 2.0.0-alpha.3 → 2.0.0-alpha.6
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/dist/cjs/ParaServer.js +91 -0
- package/dist/cjs/ServerLocalStorage.js +48 -0
- package/dist/cjs/ServerSessionStorage.js +48 -0
- package/dist/cjs/ServerUtils.js +77 -0
- package/dist/cjs/index.js +3 -523
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/wallet/keygen.js +229 -0
- package/dist/cjs/wallet/privateKey.js +86 -0
- package/dist/cjs/wallet/signing.js +172 -0
- package/dist/cjs/wasm/wasm_exec.js +589 -0
- package/dist/cjs/workers/walletUtils.js +367 -0
- package/dist/cjs/workers/worker.js +24 -906
- package/dist/cjs/workers/workerWrapper.js +88 -0
- package/dist/esm/ParaServer.js +39 -0
- package/dist/esm/ServerLocalStorage.js +26 -0
- package/dist/esm/ServerSessionStorage.js +26 -0
- package/dist/esm/ServerUtils.js +55 -0
- package/dist/esm/chunk-FTA5RKYX.js +8 -0
- package/dist/esm/index.js +4 -468
- package/dist/esm/package.json +6 -0
- package/dist/esm/wallet/keygen.js +160 -0
- package/dist/esm/wallet/privateKey.js +32 -0
- package/dist/esm/wallet/signing.js +109 -0
- package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
- package/dist/esm/workers/walletUtils.js +290 -0
- package/dist/esm/workers/worker.js +41 -336
- package/dist/esm/workers/workerWrapper.js +44 -0
- package/dist/types/ServerUtils.d.ts +5 -4
- package/dist/types/wallet/keygen.d.ts +5 -3
- package/dist/types/workers/walletUtils.d.ts +3 -3
- package/dist/types/workers/worker.d.ts +2 -1
- package/package.json +5 -5
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/workers/worker.js.br +0 -0
- package/dist/cjs/workers/worker.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js +0 -36
- package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
- package/dist/esm/workers/worker.js.br +0 -0
- package/dist/esm/workers/worker.js.gz +0 -0
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
var fulfilled = (value) => {
|
|
5
|
+
try {
|
|
6
|
+
step(generator.next(value));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
reject(e);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var rejected = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.throw(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const globalThisCopy = global;
|
|
23
|
+
if (!globalThisCopy.crypto) {
|
|
24
|
+
globalThisCopy.crypto = require("crypto");
|
|
25
|
+
}
|
|
26
|
+
const crypto = globalThisCopy.crypto;
|
|
27
|
+
(() => {
|
|
28
|
+
const enosys = () => {
|
|
29
|
+
const err = new Error("not implemented");
|
|
30
|
+
err.code = "ENOSYS";
|
|
31
|
+
return err;
|
|
32
|
+
};
|
|
33
|
+
if (!globalThis.fs) {
|
|
34
|
+
let outputBuf = "";
|
|
35
|
+
globalThis.fs = {
|
|
36
|
+
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
|
37
|
+
// unused
|
|
38
|
+
writeSync(fd, buf) {
|
|
39
|
+
outputBuf += decoder.decode(buf);
|
|
40
|
+
const nl = outputBuf.lastIndexOf("\n");
|
|
41
|
+
if (nl != -1) {
|
|
42
|
+
console.log(outputBuf.substring(0, nl));
|
|
43
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
44
|
+
}
|
|
45
|
+
return buf.length;
|
|
46
|
+
},
|
|
47
|
+
write(fd, buf, offset, length, position, callback) {
|
|
48
|
+
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
49
|
+
callback(enosys());
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const n = this.writeSync(fd, buf);
|
|
53
|
+
callback(null, n);
|
|
54
|
+
},
|
|
55
|
+
chmod(path, mode, callback) {
|
|
56
|
+
callback(enosys());
|
|
57
|
+
},
|
|
58
|
+
chown(path, uid, gid, callback) {
|
|
59
|
+
callback(enosys());
|
|
60
|
+
},
|
|
61
|
+
close(fd, callback) {
|
|
62
|
+
callback(enosys());
|
|
63
|
+
},
|
|
64
|
+
fchmod(fd, mode, callback) {
|
|
65
|
+
callback(enosys());
|
|
66
|
+
},
|
|
67
|
+
fchown(fd, uid, gid, callback) {
|
|
68
|
+
callback(enosys());
|
|
69
|
+
},
|
|
70
|
+
fstat(fd, callback) {
|
|
71
|
+
callback(enosys());
|
|
72
|
+
},
|
|
73
|
+
fsync(fd, callback) {
|
|
74
|
+
callback(null);
|
|
75
|
+
},
|
|
76
|
+
ftruncate(fd, length, callback) {
|
|
77
|
+
callback(enosys());
|
|
78
|
+
},
|
|
79
|
+
lchown(path, uid, gid, callback) {
|
|
80
|
+
callback(enosys());
|
|
81
|
+
},
|
|
82
|
+
link(path, link, callback) {
|
|
83
|
+
callback(enosys());
|
|
84
|
+
},
|
|
85
|
+
lstat(path, callback) {
|
|
86
|
+
callback(enosys());
|
|
87
|
+
},
|
|
88
|
+
mkdir(path, perm, callback) {
|
|
89
|
+
callback(enosys());
|
|
90
|
+
},
|
|
91
|
+
open(path, flags, mode, callback) {
|
|
92
|
+
callback(enosys());
|
|
93
|
+
},
|
|
94
|
+
read(fd, buffer, offset, length, position, callback) {
|
|
95
|
+
callback(enosys());
|
|
96
|
+
},
|
|
97
|
+
readdir(path, callback) {
|
|
98
|
+
callback(enosys());
|
|
99
|
+
},
|
|
100
|
+
readlink(path, callback) {
|
|
101
|
+
callback(enosys());
|
|
102
|
+
},
|
|
103
|
+
rename(from, to, callback) {
|
|
104
|
+
callback(enosys());
|
|
105
|
+
},
|
|
106
|
+
rmdir(path, callback) {
|
|
107
|
+
callback(enosys());
|
|
108
|
+
},
|
|
109
|
+
stat(path, callback) {
|
|
110
|
+
callback(enosys());
|
|
111
|
+
},
|
|
112
|
+
symlink(path, link, callback) {
|
|
113
|
+
callback(enosys());
|
|
114
|
+
},
|
|
115
|
+
truncate(path, length, callback) {
|
|
116
|
+
callback(enosys());
|
|
117
|
+
},
|
|
118
|
+
unlink(path, callback) {
|
|
119
|
+
callback(enosys());
|
|
120
|
+
},
|
|
121
|
+
utimes(path, atime, mtime, callback) {
|
|
122
|
+
callback(enosys());
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (!globalThis.process) {
|
|
127
|
+
globalThis.process = {
|
|
128
|
+
getuid() {
|
|
129
|
+
return -1;
|
|
130
|
+
},
|
|
131
|
+
getgid() {
|
|
132
|
+
return -1;
|
|
133
|
+
},
|
|
134
|
+
geteuid() {
|
|
135
|
+
return -1;
|
|
136
|
+
},
|
|
137
|
+
getegid() {
|
|
138
|
+
return -1;
|
|
139
|
+
},
|
|
140
|
+
getgroups() {
|
|
141
|
+
throw enosys();
|
|
142
|
+
},
|
|
143
|
+
pid: -1,
|
|
144
|
+
ppid: -1,
|
|
145
|
+
umask() {
|
|
146
|
+
throw enosys();
|
|
147
|
+
},
|
|
148
|
+
cwd() {
|
|
149
|
+
throw enosys();
|
|
150
|
+
},
|
|
151
|
+
chdir() {
|
|
152
|
+
throw enosys();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (!globalThis.crypto) {
|
|
157
|
+
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
|
158
|
+
}
|
|
159
|
+
if (!globalThis.performance) {
|
|
160
|
+
throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
|
|
161
|
+
}
|
|
162
|
+
if (!globalThis.TextEncoder) {
|
|
163
|
+
throw new Error("globalThis.TextEncoder is not available, polyfill required");
|
|
164
|
+
}
|
|
165
|
+
if (!globalThis.TextDecoder) {
|
|
166
|
+
throw new Error("globalThis.TextDecoder is not available, polyfill required");
|
|
167
|
+
}
|
|
168
|
+
const encoder = new TextEncoder("utf-8");
|
|
169
|
+
const decoder = new TextDecoder("utf-8");
|
|
170
|
+
globalThis.Go = class {
|
|
171
|
+
constructor() {
|
|
172
|
+
this.argv = ["js"];
|
|
173
|
+
this.env = {};
|
|
174
|
+
this.exit = (code) => {
|
|
175
|
+
if (code !== 0) {
|
|
176
|
+
console.warn("exit code:", code);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
this._exitPromise = new Promise((resolve) => {
|
|
180
|
+
this._resolveExitPromise = resolve;
|
|
181
|
+
});
|
|
182
|
+
this._pendingEvent = null;
|
|
183
|
+
this._scheduledTimeouts = /* @__PURE__ */ new Map();
|
|
184
|
+
this._nextCallbackTimeoutID = 1;
|
|
185
|
+
const setInt64 = (addr, v) => {
|
|
186
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
187
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
188
|
+
};
|
|
189
|
+
const setInt32 = (addr, v) => {
|
|
190
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
191
|
+
};
|
|
192
|
+
const getInt64 = (addr) => {
|
|
193
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
194
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
195
|
+
return low + high * 4294967296;
|
|
196
|
+
};
|
|
197
|
+
const loadValue = (addr) => {
|
|
198
|
+
const f = this.mem.getFloat64(addr, true);
|
|
199
|
+
if (f === 0) {
|
|
200
|
+
return void 0;
|
|
201
|
+
}
|
|
202
|
+
if (!isNaN(f)) {
|
|
203
|
+
return f;
|
|
204
|
+
}
|
|
205
|
+
const id = this.mem.getUint32(addr, true);
|
|
206
|
+
return this._values[id];
|
|
207
|
+
};
|
|
208
|
+
const storeValue = (addr, v) => {
|
|
209
|
+
const nanHead = 2146959360;
|
|
210
|
+
if (typeof v === "number" && v !== 0) {
|
|
211
|
+
if (isNaN(v)) {
|
|
212
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
213
|
+
this.mem.setUint32(addr, 0, true);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.mem.setFloat64(addr, v, true);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (v === void 0) {
|
|
220
|
+
this.mem.setFloat64(addr, 0, true);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
let id = this._ids.get(v);
|
|
224
|
+
if (id === void 0) {
|
|
225
|
+
id = this._idPool.pop();
|
|
226
|
+
if (id === void 0) {
|
|
227
|
+
id = this._values.length;
|
|
228
|
+
}
|
|
229
|
+
this._values[id] = v;
|
|
230
|
+
this._goRefCounts[id] = 0;
|
|
231
|
+
this._ids.set(v, id);
|
|
232
|
+
}
|
|
233
|
+
this._goRefCounts[id]++;
|
|
234
|
+
let typeFlag = 0;
|
|
235
|
+
switch (typeof v) {
|
|
236
|
+
case "object":
|
|
237
|
+
if (v !== null) {
|
|
238
|
+
typeFlag = 1;
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case "string":
|
|
242
|
+
typeFlag = 2;
|
|
243
|
+
break;
|
|
244
|
+
case "symbol":
|
|
245
|
+
typeFlag = 3;
|
|
246
|
+
break;
|
|
247
|
+
case "function":
|
|
248
|
+
typeFlag = 4;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
252
|
+
this.mem.setUint32(addr, id, true);
|
|
253
|
+
};
|
|
254
|
+
const loadSlice = (addr) => {
|
|
255
|
+
const array = getInt64(addr + 0);
|
|
256
|
+
const len = getInt64(addr + 8);
|
|
257
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
258
|
+
};
|
|
259
|
+
const loadSliceOfValues = (addr) => {
|
|
260
|
+
const array = getInt64(addr + 0);
|
|
261
|
+
const len = getInt64(addr + 8);
|
|
262
|
+
const a = new Array(len);
|
|
263
|
+
for (let i = 0; i < len; i++) {
|
|
264
|
+
a[i] = loadValue(array + i * 8);
|
|
265
|
+
}
|
|
266
|
+
return a;
|
|
267
|
+
};
|
|
268
|
+
const loadString = (addr) => {
|
|
269
|
+
const saddr = getInt64(addr + 0);
|
|
270
|
+
const len = getInt64(addr + 8);
|
|
271
|
+
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
272
|
+
};
|
|
273
|
+
const timeOrigin = Date.now() - performance.now();
|
|
274
|
+
this.importObject = {
|
|
275
|
+
_gotest: {
|
|
276
|
+
add: (a, b) => a + b
|
|
277
|
+
},
|
|
278
|
+
gojs: {
|
|
279
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
280
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
281
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
282
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
283
|
+
// func wasmExit(code int32)
|
|
284
|
+
"runtime.wasmExit": (sp) => {
|
|
285
|
+
sp >>>= 0;
|
|
286
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
287
|
+
this.exited = true;
|
|
288
|
+
delete this._inst;
|
|
289
|
+
delete this._values;
|
|
290
|
+
delete this._goRefCounts;
|
|
291
|
+
delete this._ids;
|
|
292
|
+
delete this._idPool;
|
|
293
|
+
this.exit(code);
|
|
294
|
+
},
|
|
295
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
296
|
+
"runtime.wasmWrite": (sp) => {
|
|
297
|
+
sp >>>= 0;
|
|
298
|
+
const fd = getInt64(sp + 8);
|
|
299
|
+
const p = getInt64(sp + 16);
|
|
300
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
301
|
+
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
302
|
+
},
|
|
303
|
+
// func resetMemoryDataView()
|
|
304
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
305
|
+
sp >>>= 0;
|
|
306
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
307
|
+
},
|
|
308
|
+
// func nanotime1() int64
|
|
309
|
+
"runtime.nanotime1": (sp) => {
|
|
310
|
+
sp >>>= 0;
|
|
311
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
|
|
312
|
+
},
|
|
313
|
+
// func walltime() (sec int64, nsec int32)
|
|
314
|
+
"runtime.walltime": (sp) => {
|
|
315
|
+
sp >>>= 0;
|
|
316
|
+
const msec = (/* @__PURE__ */ new Date()).getTime();
|
|
317
|
+
setInt64(sp + 8, msec / 1e3);
|
|
318
|
+
this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
|
|
319
|
+
},
|
|
320
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
321
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
322
|
+
sp >>>= 0;
|
|
323
|
+
const id = this._nextCallbackTimeoutID;
|
|
324
|
+
this._nextCallbackTimeoutID++;
|
|
325
|
+
this._scheduledTimeouts.set(id, setTimeout(
|
|
326
|
+
() => {
|
|
327
|
+
this._resume();
|
|
328
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
329
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
330
|
+
this._resume();
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
getInt64(sp + 8)
|
|
334
|
+
));
|
|
335
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
336
|
+
},
|
|
337
|
+
// func clearTimeoutEvent(id int32)
|
|
338
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
339
|
+
sp >>>= 0;
|
|
340
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
341
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
342
|
+
this._scheduledTimeouts.delete(id);
|
|
343
|
+
},
|
|
344
|
+
// func getRandomData(r []byte)
|
|
345
|
+
"runtime.getRandomData": (sp) => {
|
|
346
|
+
sp >>>= 0;
|
|
347
|
+
crypto.getRandomValues(loadSlice(sp + 8));
|
|
348
|
+
},
|
|
349
|
+
// func finalizeRef(v ref)
|
|
350
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
351
|
+
sp >>>= 0;
|
|
352
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
353
|
+
this._goRefCounts[id]--;
|
|
354
|
+
if (this._goRefCounts[id] === 0) {
|
|
355
|
+
const v = this._values[id];
|
|
356
|
+
this._values[id] = null;
|
|
357
|
+
this._ids.delete(v);
|
|
358
|
+
this._idPool.push(id);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
// func stringVal(value string) ref
|
|
362
|
+
"syscall/js.stringVal": (sp) => {
|
|
363
|
+
sp >>>= 0;
|
|
364
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
365
|
+
},
|
|
366
|
+
// func valueGet(v ref, p string) ref
|
|
367
|
+
"syscall/js.valueGet": (sp) => {
|
|
368
|
+
sp >>>= 0;
|
|
369
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
370
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
371
|
+
storeValue(sp + 32, result);
|
|
372
|
+
},
|
|
373
|
+
// func valueSet(v ref, p string, x ref)
|
|
374
|
+
"syscall/js.valueSet": (sp) => {
|
|
375
|
+
sp >>>= 0;
|
|
376
|
+
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
377
|
+
},
|
|
378
|
+
// func valueDelete(v ref, p string)
|
|
379
|
+
"syscall/js.valueDelete": (sp) => {
|
|
380
|
+
sp >>>= 0;
|
|
381
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
382
|
+
},
|
|
383
|
+
// func valueIndex(v ref, i int) ref
|
|
384
|
+
"syscall/js.valueIndex": (sp) => {
|
|
385
|
+
sp >>>= 0;
|
|
386
|
+
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
387
|
+
},
|
|
388
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
389
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
390
|
+
sp >>>= 0;
|
|
391
|
+
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
392
|
+
},
|
|
393
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
394
|
+
"syscall/js.valueCall": (sp) => {
|
|
395
|
+
sp >>>= 0;
|
|
396
|
+
try {
|
|
397
|
+
const v = loadValue(sp + 8);
|
|
398
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
399
|
+
const args = loadSliceOfValues(sp + 32);
|
|
400
|
+
const result = Reflect.apply(m, v, args);
|
|
401
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
402
|
+
storeValue(sp + 56, result);
|
|
403
|
+
this.mem.setUint8(sp + 64, 1);
|
|
404
|
+
} catch (err) {
|
|
405
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
406
|
+
storeValue(sp + 56, err);
|
|
407
|
+
this.mem.setUint8(sp + 64, 0);
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
411
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
412
|
+
sp >>>= 0;
|
|
413
|
+
try {
|
|
414
|
+
const v = loadValue(sp + 8);
|
|
415
|
+
const args = loadSliceOfValues(sp + 16);
|
|
416
|
+
const result = Reflect.apply(v, void 0, args);
|
|
417
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
418
|
+
storeValue(sp + 40, result);
|
|
419
|
+
this.mem.setUint8(sp + 48, 1);
|
|
420
|
+
} catch (err) {
|
|
421
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
422
|
+
storeValue(sp + 40, err);
|
|
423
|
+
this.mem.setUint8(sp + 48, 0);
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
427
|
+
"syscall/js.valueNew": (sp) => {
|
|
428
|
+
sp >>>= 0;
|
|
429
|
+
try {
|
|
430
|
+
const v = loadValue(sp + 8);
|
|
431
|
+
const args = loadSliceOfValues(sp + 16);
|
|
432
|
+
const result = Reflect.construct(v, args);
|
|
433
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
434
|
+
storeValue(sp + 40, result);
|
|
435
|
+
this.mem.setUint8(sp + 48, 1);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
438
|
+
storeValue(sp + 40, err);
|
|
439
|
+
this.mem.setUint8(sp + 48, 0);
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
// func valueLength(v ref) int
|
|
443
|
+
"syscall/js.valueLength": (sp) => {
|
|
444
|
+
sp >>>= 0;
|
|
445
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
446
|
+
},
|
|
447
|
+
// valuePrepareString(v ref) (ref, int)
|
|
448
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
449
|
+
sp >>>= 0;
|
|
450
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
451
|
+
storeValue(sp + 16, str);
|
|
452
|
+
setInt64(sp + 24, str.length);
|
|
453
|
+
},
|
|
454
|
+
// valueLoadString(v ref, b []byte)
|
|
455
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
456
|
+
sp >>>= 0;
|
|
457
|
+
const str = loadValue(sp + 8);
|
|
458
|
+
loadSlice(sp + 16).set(str);
|
|
459
|
+
},
|
|
460
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
461
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
462
|
+
sp >>>= 0;
|
|
463
|
+
this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
|
|
464
|
+
},
|
|
465
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
466
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
467
|
+
sp >>>= 0;
|
|
468
|
+
const dst = loadSlice(sp + 8);
|
|
469
|
+
const src = loadValue(sp + 32);
|
|
470
|
+
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
471
|
+
this.mem.setUint8(sp + 48, 0);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const toCopy = src.subarray(0, dst.length);
|
|
475
|
+
dst.set(toCopy);
|
|
476
|
+
setInt64(sp + 40, toCopy.length);
|
|
477
|
+
this.mem.setUint8(sp + 48, 1);
|
|
478
|
+
},
|
|
479
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
480
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
481
|
+
sp >>>= 0;
|
|
482
|
+
const dst = loadValue(sp + 8);
|
|
483
|
+
const src = loadSlice(sp + 16);
|
|
484
|
+
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
485
|
+
this.mem.setUint8(sp + 48, 0);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const toCopy = src.subarray(0, dst.length);
|
|
489
|
+
dst.set(toCopy);
|
|
490
|
+
setInt64(sp + 40, toCopy.length);
|
|
491
|
+
this.mem.setUint8(sp + 48, 1);
|
|
492
|
+
},
|
|
493
|
+
"debug": (value) => {
|
|
494
|
+
console.log(value);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
run(instance) {
|
|
500
|
+
return __async(this, null, function* () {
|
|
501
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
502
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
503
|
+
}
|
|
504
|
+
this._inst = instance;
|
|
505
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
506
|
+
this._values = [
|
|
507
|
+
// JS values that Go currently has references to, indexed by reference id
|
|
508
|
+
NaN,
|
|
509
|
+
0,
|
|
510
|
+
null,
|
|
511
|
+
true,
|
|
512
|
+
false,
|
|
513
|
+
globalThis,
|
|
514
|
+
this
|
|
515
|
+
];
|
|
516
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity);
|
|
517
|
+
this._ids = /* @__PURE__ */ new Map([
|
|
518
|
+
// mapping from JS values to reference ids
|
|
519
|
+
[0, 1],
|
|
520
|
+
[null, 2],
|
|
521
|
+
[true, 3],
|
|
522
|
+
[false, 4],
|
|
523
|
+
[globalThis, 5],
|
|
524
|
+
[this, 6]
|
|
525
|
+
]);
|
|
526
|
+
this._idPool = [];
|
|
527
|
+
this.exited = false;
|
|
528
|
+
let offset = 4096;
|
|
529
|
+
const strPtr = (str) => {
|
|
530
|
+
const ptr = offset;
|
|
531
|
+
const bytes = encoder.encode(str + "\0");
|
|
532
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
533
|
+
offset += bytes.length;
|
|
534
|
+
if (offset % 8 !== 0) {
|
|
535
|
+
offset += 8 - offset % 8;
|
|
536
|
+
}
|
|
537
|
+
return ptr;
|
|
538
|
+
};
|
|
539
|
+
const argc = this.argv.length;
|
|
540
|
+
const argvPtrs = [];
|
|
541
|
+
this.argv.forEach((arg) => {
|
|
542
|
+
argvPtrs.push(strPtr(arg));
|
|
543
|
+
});
|
|
544
|
+
argvPtrs.push(0);
|
|
545
|
+
const keys = Object.keys(this.env).sort();
|
|
546
|
+
keys.forEach((key) => {
|
|
547
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
548
|
+
});
|
|
549
|
+
argvPtrs.push(0);
|
|
550
|
+
const argv = offset;
|
|
551
|
+
argvPtrs.forEach((ptr) => {
|
|
552
|
+
this.mem.setUint32(offset, ptr, true);
|
|
553
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
554
|
+
offset += 8;
|
|
555
|
+
});
|
|
556
|
+
const wasmMinDataAddr = 4096 + 8192;
|
|
557
|
+
if (offset >= wasmMinDataAddr) {
|
|
558
|
+
throw new Error("total length of command line and environment variables exceeds limit");
|
|
559
|
+
}
|
|
560
|
+
this._inst.exports.run(argc, argv);
|
|
561
|
+
if (this.exited) {
|
|
562
|
+
this._resolveExitPromise();
|
|
563
|
+
}
|
|
564
|
+
yield this._exitPromise;
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
_resume() {
|
|
568
|
+
if (this.exited) {
|
|
569
|
+
throw new Error("Go program has already exited");
|
|
570
|
+
}
|
|
571
|
+
this._inst.exports.resume();
|
|
572
|
+
if (this.exited) {
|
|
573
|
+
this._resolveExitPromise();
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
_makeFuncWrapper(id) {
|
|
577
|
+
const go = this;
|
|
578
|
+
return function() {
|
|
579
|
+
const event = { id, this: this, args: arguments };
|
|
580
|
+
go._pendingEvent = event;
|
|
581
|
+
go._resume();
|
|
582
|
+
return event.result;
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
})();
|
|
587
|
+
module.exports = {
|
|
588
|
+
globalThisCopy
|
|
589
|
+
};
|