quickjs-emscripten-sync 1.8.3 → 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 +231 -150
- package/dist/index.d.ts +45 -7
- package/dist/quickjs-emscripten-sync.js +573 -342
- package/dist/quickjs-emscripten-sync.umd.cjs +17 -8
- package/package.json +9 -7
- package/src/index.test.ts +250 -5
- package/src/index.ts +85 -7
- package/src/marshal/custom.ts +16 -2
- package/src/marshal/hostref.ts +18 -0
- package/src/marshal/index.ts +12 -0
- package/src/marshal/mapset.ts +28 -0
- package/src/marshal/primitive.ts +2 -11
- package/src/marshal/properties.ts +8 -6
- package/src/unmarshal/custom.ts +35 -4
- package/src/unmarshal/function.ts +2 -2
- package/src/unmarshal/hostref.ts +21 -0
- package/src/unmarshal/index.ts +21 -1
- package/src/unmarshal/mapset.ts +43 -0
- package/src/unmarshal/object.ts +16 -20
- package/src/unmarshal/primitive.ts +6 -17
- package/src/unmarshal/properties.ts +7 -6
- package/src/vmmap.ts +59 -69
- package/src/vmutil.ts +94 -11
- package/src/wrapper.ts +97 -30
|
@@ -1,23 +1,48 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var C = Object.getOwnPropertySymbols;
|
|
3
|
+
var z = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var M = (n, e, t) => e in n ? W(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, B = (n, e) => {
|
|
5
|
+
for (var t in e || (e = {}))
|
|
6
|
+
z.call(e, t) && M(n, t, e[t]);
|
|
7
|
+
if (C)
|
|
8
|
+
for (var t of C(e))
|
|
9
|
+
$.call(e, t) && M(n, t, e[t]);
|
|
10
|
+
return n;
|
|
11
|
+
};
|
|
12
|
+
var l = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
|
|
13
|
+
var F = (n, e, t) => new Promise((r, s) => {
|
|
14
|
+
var o = (u) => {
|
|
15
|
+
try {
|
|
16
|
+
a(t.next(u));
|
|
17
|
+
} catch (f) {
|
|
18
|
+
s(f);
|
|
19
|
+
}
|
|
20
|
+
}, i = (u) => {
|
|
21
|
+
try {
|
|
22
|
+
a(t.throw(u));
|
|
23
|
+
} catch (f) {
|
|
24
|
+
s(f);
|
|
25
|
+
}
|
|
26
|
+
}, a = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(o, i);
|
|
27
|
+
a((t = t.apply(n, e)).next());
|
|
28
|
+
});
|
|
29
|
+
const L = (n) => {
|
|
30
|
+
const e = new K(n);
|
|
6
31
|
return new Proxy(n, {
|
|
7
32
|
get(t, r, s) {
|
|
8
33
|
return r in e ? e[r] : Reflect.get(t, r, s);
|
|
9
34
|
}
|
|
10
35
|
});
|
|
11
36
|
};
|
|
12
|
-
class
|
|
37
|
+
class K {
|
|
13
38
|
constructor(e) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
l(this, "context");
|
|
40
|
+
l(this, "fn");
|
|
41
|
+
l(this, "fnGenerator");
|
|
42
|
+
l(this, "fnCounter", Number.MIN_SAFE_INTEGER);
|
|
43
|
+
l(this, "fnMap", /* @__PURE__ */ new Map());
|
|
19
44
|
/** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
|
|
20
|
-
|
|
45
|
+
l(this, "newFunction", (e, t) => {
|
|
21
46
|
this.fnCounter++;
|
|
22
47
|
const r = this.fnCounter;
|
|
23
48
|
return this.fnMap.set(r, t), this.context.unwrapResult(
|
|
@@ -52,7 +77,7 @@ class U {
|
|
|
52
77
|
this.fnGenerator.dispose(), this.fn.dispose();
|
|
53
78
|
}
|
|
54
79
|
}
|
|
55
|
-
const
|
|
80
|
+
const q = [
|
|
56
81
|
// basic objects
|
|
57
82
|
[Symbol, "Symbol"],
|
|
58
83
|
[Symbol.prototype, "Symbol.prototype"],
|
|
@@ -84,33 +109,73 @@ const I = [
|
|
|
84
109
|
// built-in symbols
|
|
85
110
|
...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
|
|
86
111
|
];
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
112
|
+
function S(n, e) {
|
|
113
|
+
if ("error" in e && e.error) {
|
|
114
|
+
const { error: t } = e;
|
|
115
|
+
let r;
|
|
116
|
+
try {
|
|
117
|
+
r = n.dump(t);
|
|
118
|
+
} catch (o) {
|
|
119
|
+
} finally {
|
|
120
|
+
t.alive && t.dispose();
|
|
121
|
+
}
|
|
122
|
+
const s = new Error(
|
|
123
|
+
typeof r == "object" && r && "message" in r ? String(r.message) : r !== void 0 ? String(r) : "quickjs-emscripten-sync: VM evaluation failed"
|
|
124
|
+
);
|
|
125
|
+
throw typeof r == "object" && r && ("name" in r && (s.name = String(r.name)), "stack" in r && (s.stack = String(r.stack))), s;
|
|
126
|
+
}
|
|
127
|
+
return e.value;
|
|
128
|
+
}
|
|
129
|
+
function Q(n, e) {
|
|
130
|
+
const t = S(n, n.evalCode(e)), r = (o, ...i) => S(n, n.callFunction(t, o != null ? o : n.undefined, ...i)), s = () => t.dispose();
|
|
131
|
+
return r.dispose = s, r[Symbol.dispose] = s, Object.defineProperty(r, "alive", {
|
|
90
132
|
get: () => t.alive
|
|
91
133
|
}), r;
|
|
92
134
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
135
|
+
const k = /* @__PURE__ */ new WeakMap();
|
|
136
|
+
function X(n) {
|
|
137
|
+
k.has(n) || k.set(n, /* @__PURE__ */ new Map());
|
|
138
|
+
}
|
|
139
|
+
function Y(n) {
|
|
140
|
+
const e = k.get(n);
|
|
141
|
+
if (e) {
|
|
142
|
+
for (const t of e.values())
|
|
143
|
+
t.alive && t.dispose();
|
|
144
|
+
k.delete(n);
|
|
99
145
|
}
|
|
100
146
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
147
|
+
function m(n, e, t, ...r) {
|
|
148
|
+
const s = k.get(n);
|
|
149
|
+
if (!s) {
|
|
150
|
+
const i = Q(n, e);
|
|
151
|
+
try {
|
|
152
|
+
return i(t, ...r);
|
|
153
|
+
} finally {
|
|
154
|
+
i.dispose();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let o = s.get(e);
|
|
158
|
+
return (!o || !o.alive) && (o = S(n, n.evalCode(e)), s.set(e, o)), S(n, n.callFunction(o, t != null ? t : n.undefined, ...r));
|
|
103
159
|
}
|
|
104
|
-
function
|
|
105
|
-
return n.dump(
|
|
106
|
-
|
|
107
|
-
|
|
160
|
+
function Z(n, e, t) {
|
|
161
|
+
return n.dump(m(n, "(a, b) => a instanceof b", void 0, e, t));
|
|
162
|
+
}
|
|
163
|
+
function x(n, e) {
|
|
164
|
+
const t = n.typeof(e);
|
|
165
|
+
return t === "function" || t === "object" && !n.sameValue(e, n.null);
|
|
108
166
|
}
|
|
109
|
-
function
|
|
167
|
+
function ee(n, e) {
|
|
110
168
|
const t = JSON.stringify(e);
|
|
111
|
-
return t ?
|
|
169
|
+
return t ? m(n, "JSON.parse", void 0, n.newString(t)) : n.undefined;
|
|
112
170
|
}
|
|
113
|
-
function
|
|
171
|
+
function w(n, e) {
|
|
172
|
+
try {
|
|
173
|
+
return e(n);
|
|
174
|
+
} finally {
|
|
175
|
+
n.alive && n.dispose();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function te(n, e) {
|
|
114
179
|
try {
|
|
115
180
|
return e(n);
|
|
116
181
|
} finally {
|
|
@@ -118,14 +183,14 @@ function _e(n, e) {
|
|
|
118
183
|
t.alive && t.dispose();
|
|
119
184
|
}
|
|
120
185
|
}
|
|
121
|
-
function
|
|
186
|
+
function ne([n, e], t) {
|
|
122
187
|
try {
|
|
123
188
|
return t(n);
|
|
124
189
|
} finally {
|
|
125
190
|
e && n.dispose();
|
|
126
191
|
}
|
|
127
192
|
}
|
|
128
|
-
function
|
|
193
|
+
function O(n, e) {
|
|
129
194
|
try {
|
|
130
195
|
return e(...n.map((t) => t[0]));
|
|
131
196
|
} finally {
|
|
@@ -133,40 +198,51 @@ function g(n, e) {
|
|
|
133
198
|
r && t.dispose();
|
|
134
199
|
}
|
|
135
200
|
}
|
|
136
|
-
function
|
|
201
|
+
function re(n) {
|
|
137
202
|
return "handle" in n;
|
|
138
203
|
}
|
|
139
|
-
function
|
|
140
|
-
return
|
|
204
|
+
function se(n) {
|
|
205
|
+
return re(n) ? n.handle : n;
|
|
141
206
|
}
|
|
142
|
-
function
|
|
207
|
+
function oe(n, e, t, r) {
|
|
143
208
|
var o;
|
|
144
209
|
let s;
|
|
145
210
|
for (const i of r)
|
|
146
211
|
if (s = i(e, n), s) break;
|
|
147
212
|
return s ? (o = t(e, s)) != null ? o : s : void 0;
|
|
148
213
|
}
|
|
149
|
-
function
|
|
150
|
-
return typeof n != "symbol" ? void 0 :
|
|
214
|
+
function ie(n, e) {
|
|
215
|
+
return typeof n != "symbol" ? void 0 : m(
|
|
151
216
|
e,
|
|
152
217
|
"d => Symbol(d)",
|
|
153
218
|
void 0,
|
|
154
219
|
n.description ? e.newString(n.description) : e.undefined
|
|
155
220
|
);
|
|
156
221
|
}
|
|
157
|
-
function
|
|
158
|
-
return n instanceof Date ?
|
|
222
|
+
function ue(n, e) {
|
|
223
|
+
return n instanceof Date ? m(e, "d => new Date(d)", void 0, e.newNumber(n.getTime())) : void 0;
|
|
159
224
|
}
|
|
160
|
-
|
|
161
|
-
|
|
225
|
+
function ae(n, e) {
|
|
226
|
+
if (n instanceof ArrayBuffer)
|
|
227
|
+
return e.newArrayBuffer(n.slice(0));
|
|
228
|
+
if (ArrayBuffer.isView(n)) {
|
|
229
|
+
const t = new Uint8Array(n.buffer, n.byteOffset, n.byteLength).slice();
|
|
230
|
+
return te(
|
|
231
|
+
[e.newArrayBuffer(t.buffer), e.newString(n.constructor.name)],
|
|
232
|
+
([r, s]) => m(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const fe = [ie, ue, ae];
|
|
237
|
+
function ce(n) {
|
|
162
238
|
return typeof n == "function" && /^class\s/.test(Function.prototype.toString.call(n));
|
|
163
239
|
}
|
|
164
|
-
function
|
|
240
|
+
function P(n) {
|
|
165
241
|
return typeof n == "function" || typeof n == "object" && n !== null;
|
|
166
242
|
}
|
|
167
|
-
function
|
|
243
|
+
function I(n, e) {
|
|
168
244
|
const t = /* @__PURE__ */ new Set(), r = (s) => {
|
|
169
|
-
if (!(!
|
|
245
|
+
if (!(!P(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
|
|
170
246
|
if (t.add(s), Array.isArray(s)) {
|
|
171
247
|
for (const o of s)
|
|
172
248
|
r(o);
|
|
@@ -182,10 +258,10 @@ function E(n, e) {
|
|
|
182
258
|
};
|
|
183
259
|
return r(n), t;
|
|
184
260
|
}
|
|
185
|
-
function
|
|
186
|
-
return
|
|
261
|
+
function Ie(n, e) {
|
|
262
|
+
return I(n, e ? (t, r) => r.size < e : void 0).size;
|
|
187
263
|
}
|
|
188
|
-
function
|
|
264
|
+
function pe() {
|
|
189
265
|
let n = () => {
|
|
190
266
|
}, e = () => {
|
|
191
267
|
};
|
|
@@ -197,34 +273,39 @@ function Z() {
|
|
|
197
273
|
reject: e
|
|
198
274
|
};
|
|
199
275
|
}
|
|
200
|
-
function
|
|
201
|
-
const s = n.newObject(), o = (
|
|
202
|
-
const
|
|
203
|
-
n.newObject().consume((
|
|
204
|
-
Object.entries(
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
}), n.setProp(s,
|
|
276
|
+
function N(n, e, t, r) {
|
|
277
|
+
const s = n.newObject(), o = (i, a) => {
|
|
278
|
+
const u = r(i), f = typeof a.value == "undefined" ? void 0 : r(a.value), d = typeof a.get == "undefined" ? void 0 : r(a.get), y = typeof a.set == "undefined" ? void 0 : r(a.set);
|
|
279
|
+
n.newObject().consume((h) => {
|
|
280
|
+
Object.entries(a).forEach(([c, p]) => {
|
|
281
|
+
const v = c === "value" ? f : c === "get" ? d : c === "set" ? y : p ? n.true : n.false;
|
|
282
|
+
v && n.setProp(h, c, v);
|
|
283
|
+
}), n.setProp(s, u, h);
|
|
208
284
|
});
|
|
209
|
-
}
|
|
210
|
-
|
|
285
|
+
};
|
|
286
|
+
try {
|
|
287
|
+
const i = Object.getOwnPropertyDescriptors(e);
|
|
288
|
+
Object.entries(i).forEach(([a, u]) => o(a, u)), Object.getOwnPropertySymbols(i).forEach((a) => o(a, i[a])), m(n, "Object.defineProperties", void 0, t, s).dispose();
|
|
289
|
+
} finally {
|
|
290
|
+
s.dispose();
|
|
291
|
+
}
|
|
211
292
|
}
|
|
212
|
-
function
|
|
293
|
+
function le(n, e, t, r, s, o) {
|
|
213
294
|
var u;
|
|
214
295
|
if (typeof e != "function") return;
|
|
215
|
-
const i = n.newFunction(e.name, function(...
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
return Object.entries(
|
|
220
|
-
n.setProp(this,
|
|
296
|
+
const i = n.newFunction(e.name, function(...f) {
|
|
297
|
+
const d = r(this), y = f.map((h) => r(h));
|
|
298
|
+
if (ce(e) && P(d)) {
|
|
299
|
+
const h = new e(...y);
|
|
300
|
+
return Object.entries(h).forEach(([c, p]) => {
|
|
301
|
+
n.setProp(this, c, t(p));
|
|
221
302
|
}), this;
|
|
222
303
|
}
|
|
223
|
-
return t(o ? o(e,
|
|
304
|
+
return t(o ? o(e, d, y) : e.apply(d, y));
|
|
224
305
|
}).consume(
|
|
225
|
-
(
|
|
306
|
+
(f) => (
|
|
226
307
|
// fucntions created by vm.newFunction are not callable as a class constrcutor
|
|
227
|
-
|
|
308
|
+
m(
|
|
228
309
|
n,
|
|
229
310
|
`Cls => {
|
|
230
311
|
const fn = function(...args) { return Cls.apply(this, args); };
|
|
@@ -233,24 +314,43 @@ function K(n, e, t, r, s, o) {
|
|
|
233
314
|
return fn;
|
|
234
315
|
}`,
|
|
235
316
|
void 0,
|
|
236
|
-
|
|
317
|
+
f
|
|
237
318
|
)
|
|
238
319
|
)
|
|
239
320
|
), a = (u = s(e, i)) != null ? u : i;
|
|
240
|
-
return
|
|
321
|
+
return N(n, e, i, t), a;
|
|
322
|
+
}
|
|
323
|
+
function de(n, e, t) {
|
|
324
|
+
if (!(typeof e != "object" && typeof e != "function") && e !== null)
|
|
325
|
+
return t(e, n.newHostRef(e).handle);
|
|
241
326
|
}
|
|
242
|
-
function
|
|
327
|
+
function ye(n, e, t) {
|
|
243
328
|
var o;
|
|
244
|
-
const r =
|
|
329
|
+
const r = ee(n, e);
|
|
245
330
|
return (o = t(e, r)) != null ? o : r;
|
|
246
331
|
}
|
|
247
|
-
function
|
|
332
|
+
function he(n, e, t, r) {
|
|
333
|
+
var s, o;
|
|
334
|
+
if (e instanceof Map) {
|
|
335
|
+
const i = m(n, "() => new Map()"), a = (s = r(e, i)) != null ? s : i;
|
|
336
|
+
for (const [u, f] of e)
|
|
337
|
+
m(n, "(m, k, v) => m.set(k, v)", void 0, i, t(u), t(f)).dispose();
|
|
338
|
+
return a;
|
|
339
|
+
}
|
|
340
|
+
if (e instanceof Set) {
|
|
341
|
+
const i = m(n, "() => new Set()"), a = (o = r(e, i)) != null ? o : i;
|
|
342
|
+
for (const u of e)
|
|
343
|
+
m(n, "(s, v) => s.add(v)", void 0, i, t(u)).dispose();
|
|
344
|
+
return a;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function me(n, e, t, r) {
|
|
248
348
|
var u;
|
|
249
349
|
if (typeof e != "object" || e === null) return;
|
|
250
350
|
const s = Array.isArray(e) ? n.newArray() : n.newObject(), o = (u = r(e, s)) != null ? u : s, i = Object.getPrototypeOf(e), a = i && i !== Object.prototype && i !== Array.prototype ? t(i) : void 0;
|
|
251
|
-
return a &&
|
|
351
|
+
return a && m(n, "Object.setPrototypeOf", void 0, o, a).dispose(), N(n, e, s, t), o;
|
|
252
352
|
}
|
|
253
|
-
function
|
|
353
|
+
function _e(n, e) {
|
|
254
354
|
switch (typeof e) {
|
|
255
355
|
case "undefined":
|
|
256
356
|
return n.undefined;
|
|
@@ -260,11 +360,13 @@ function te(n, e) {
|
|
|
260
360
|
return n.newString(e);
|
|
261
361
|
case "boolean":
|
|
262
362
|
return e ? n.true : n.false;
|
|
363
|
+
case "bigint":
|
|
364
|
+
return n.newBigInt(e);
|
|
263
365
|
case "object":
|
|
264
366
|
return e === null ? n.null : void 0;
|
|
265
367
|
}
|
|
266
368
|
}
|
|
267
|
-
function
|
|
369
|
+
function ve(n, e, t, r) {
|
|
268
370
|
var o;
|
|
269
371
|
if (!(e instanceof Promise)) return;
|
|
270
372
|
const s = n.newPromise();
|
|
@@ -273,11 +375,11 @@ function ne(n, e, t, r) {
|
|
|
273
375
|
(i) => s.reject(t(i))
|
|
274
376
|
), (o = r(e, s)) != null ? o : s.handle;
|
|
275
377
|
}
|
|
276
|
-
function
|
|
277
|
-
var
|
|
378
|
+
function D(n, e) {
|
|
379
|
+
var d, y, h, c, p, v, b;
|
|
278
380
|
const { ctx: t, unmarshal: r, isMarshalable: s, find: o, pre: i } = e;
|
|
279
381
|
{
|
|
280
|
-
const _ =
|
|
382
|
+
const _ = _e(t, n);
|
|
281
383
|
if (_)
|
|
282
384
|
return _;
|
|
283
385
|
}
|
|
@@ -285,154 +387,221 @@ function R(n, e) {
|
|
|
285
387
|
const _ = o(n);
|
|
286
388
|
if (_) return _;
|
|
287
389
|
}
|
|
390
|
+
if ((d = e.marshalByReference) != null && d.call(e, n) && e.registerHostRef) {
|
|
391
|
+
const _ = de(t, n, e.registerHostRef);
|
|
392
|
+
if (_) return _;
|
|
393
|
+
}
|
|
288
394
|
const a = s == null ? void 0 : s(n);
|
|
289
395
|
if (a === !1)
|
|
290
396
|
return t.undefined;
|
|
291
|
-
const u = (_,
|
|
397
|
+
const u = (_, g) => i(_, g, a);
|
|
292
398
|
if (a === "json")
|
|
293
|
-
return
|
|
294
|
-
const
|
|
295
|
-
return (
|
|
399
|
+
return ye(t, n, u);
|
|
400
|
+
const f = (_) => D(_, e);
|
|
401
|
+
return (b = (v = (p = (c = (h = oe(t, n, u, [...fe, ...(y = e.custom) != null ? y : []])) != null ? h : ve(t, n, f, u)) != null ? c : le(t, n, f, r, u, e.preApply)) != null ? p : he(t, n, f, u)) != null ? v : me(t, n, f, u)) != null ? b : t.undefined;
|
|
296
402
|
}
|
|
297
|
-
function
|
|
403
|
+
function be(n, e, t, r) {
|
|
298
404
|
var o;
|
|
299
405
|
let s;
|
|
300
406
|
for (const i of r)
|
|
301
407
|
if (s = i(e, n), s) break;
|
|
302
408
|
return s ? (o = t(s, e)) != null ? o : s : void 0;
|
|
303
409
|
}
|
|
304
|
-
function
|
|
410
|
+
function we(n, e) {
|
|
305
411
|
if (e.typeof(n) !== "symbol") return;
|
|
306
412
|
const t = e.getString(e.getProp(n, "description"));
|
|
307
413
|
return Symbol(t);
|
|
308
414
|
}
|
|
309
|
-
function
|
|
310
|
-
if (!
|
|
311
|
-
const t =
|
|
415
|
+
function ge(n, e) {
|
|
416
|
+
if (!w(m(e, "a => a instanceof Date", void 0, n), (r) => e.dump(r))) return;
|
|
417
|
+
const t = w(m(e, "a => a.getTime()", void 0, n), (r) => e.getNumber(r));
|
|
312
418
|
return new Date(t);
|
|
313
419
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
420
|
+
function je(n, e) {
|
|
421
|
+
if (w(m(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
|
|
422
|
+
const t = e.getArrayBuffer(n), r = t.value.slice();
|
|
423
|
+
return t.dispose(), r.buffer;
|
|
424
|
+
}
|
|
425
|
+
if (w(m(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
|
|
426
|
+
const t = w(
|
|
427
|
+
m(e, "a => a.constructor.name", void 0, n),
|
|
428
|
+
(a) => e.getString(a)
|
|
429
|
+
), r = globalThis[t];
|
|
430
|
+
if (typeof r != "function") return;
|
|
431
|
+
const s = m(
|
|
432
|
+
e,
|
|
433
|
+
"a => a.buffer.slice(a.byteOffset, a.byteOffset + a.byteLength)",
|
|
434
|
+
void 0,
|
|
435
|
+
n
|
|
436
|
+
), o = e.getArrayBuffer(s), i = o.value.slice();
|
|
437
|
+
return o.dispose(), s.dispose(), new r(i.buffer);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const Pe = [we, ge, je];
|
|
441
|
+
function U(n, e, t, r) {
|
|
442
|
+
w(
|
|
443
|
+
n.newFunction("", (s, o) => {
|
|
444
|
+
const [i] = r(s);
|
|
445
|
+
if (typeof i != "string" && typeof i != "number" && typeof i != "symbol")
|
|
446
|
+
return;
|
|
447
|
+
const a = [
|
|
448
|
+
["value", !0],
|
|
449
|
+
["get", !0],
|
|
450
|
+
["set", !0],
|
|
451
|
+
["configurable", !1],
|
|
452
|
+
["enumerable", !1],
|
|
453
|
+
["writable", !1]
|
|
454
|
+
].reduce((u, [f, d]) => {
|
|
455
|
+
const y = n.getProp(o, f), h = n.typeof(y);
|
|
456
|
+
if (h === "undefined") return u;
|
|
457
|
+
if (!d && h === "boolean")
|
|
458
|
+
return u[f] = n.dump(n.getProp(o, f)), u;
|
|
459
|
+
const [c, p] = r(y);
|
|
460
|
+
return p && y.dispose(), u[f] = c, u;
|
|
461
|
+
}, {});
|
|
462
|
+
Object.defineProperty(t, i, a);
|
|
463
|
+
}),
|
|
464
|
+
(s) => {
|
|
465
|
+
m(
|
|
466
|
+
n,
|
|
467
|
+
`(o, fn) => {
|
|
340
468
|
const descs = Object.getOwnPropertyDescriptors(o);
|
|
341
469
|
Object.entries(descs).forEach(([k, v]) => fn(k, v));
|
|
342
470
|
Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));
|
|
343
471
|
}`,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
472
|
+
void 0,
|
|
473
|
+
e,
|
|
474
|
+
s
|
|
475
|
+
).dispose();
|
|
476
|
+
}
|
|
477
|
+
);
|
|
349
478
|
}
|
|
350
|
-
function
|
|
479
|
+
function Se(n, e, t, r, s) {
|
|
351
480
|
var a;
|
|
352
481
|
if (n.typeof(e) !== "function") return;
|
|
353
482
|
const o = function(...u) {
|
|
354
|
-
return
|
|
355
|
-
[t(this), ...u.map((
|
|
356
|
-
(
|
|
483
|
+
return O(
|
|
484
|
+
[t(this), ...u.map((f) => t(f))],
|
|
485
|
+
(f, ...d) => {
|
|
357
486
|
if (new.target) {
|
|
358
|
-
const [
|
|
359
|
-
|
|
487
|
+
const [p] = r(
|
|
488
|
+
m(n, "(Cls, ...args) => new Cls(...args)", f, e, ...d)
|
|
360
489
|
);
|
|
361
|
-
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(
|
|
490
|
+
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(p)), this;
|
|
362
491
|
}
|
|
363
|
-
const
|
|
364
|
-
return
|
|
492
|
+
const y = S(n, n.callFunction(e, f, ...d)), [h, c] = r(y);
|
|
493
|
+
return c && y.dispose(), h;
|
|
365
494
|
}
|
|
366
495
|
);
|
|
367
496
|
}, i = (a = s(o, e)) != null ? a : o;
|
|
368
|
-
return
|
|
497
|
+
return U(n, e, o, r), i;
|
|
498
|
+
}
|
|
499
|
+
function V(n, e) {
|
|
500
|
+
const t = n.toHostRef(e);
|
|
501
|
+
if (t)
|
|
502
|
+
try {
|
|
503
|
+
return { value: t.value };
|
|
504
|
+
} finally {
|
|
505
|
+
t.dispose();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function ke(n, e, t, r) {
|
|
509
|
+
const s = w(m(n, "a => a instanceof Map", void 0, e), (u) => n.dump(u)), o = !s && w(m(n, "a => a instanceof Set", void 0, e), (u) => n.dump(u));
|
|
510
|
+
if (!s && !o) return;
|
|
511
|
+
const i = s ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
512
|
+
r(i, e);
|
|
513
|
+
const a = n.unwrapResult(n.getIterator(e));
|
|
514
|
+
try {
|
|
515
|
+
for (const u of a) {
|
|
516
|
+
const f = n.unwrapResult(u);
|
|
517
|
+
if (s) {
|
|
518
|
+
const d = n.getProp(f, 0), y = n.getProp(f, 1), [h, c] = t(d), [p, v] = t(y);
|
|
519
|
+
c && d.dispose(), v && y.dispose(), i.set(h, p), f.dispose();
|
|
520
|
+
} else {
|
|
521
|
+
const [d, y] = t(f);
|
|
522
|
+
y && f.dispose(), i.add(d);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
} finally {
|
|
526
|
+
a.alive && a.dispose();
|
|
527
|
+
}
|
|
528
|
+
return i;
|
|
369
529
|
}
|
|
370
|
-
function
|
|
530
|
+
function Re(n, e, t, r) {
|
|
371
531
|
var a;
|
|
372
|
-
if (n.typeof(e) !== "object" ||
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
`o => {
|
|
532
|
+
if (n.typeof(e) !== "object" || n.sameValue(e, n.null)) return;
|
|
533
|
+
const s = w(m(n, "Array.isArray", void 0, e), (u) => n.dump(u)) ? [] : {}, o = (a = r(s, e)) != null ? a : s, i = w(
|
|
534
|
+
m(
|
|
535
|
+
n,
|
|
536
|
+
`o => {
|
|
378
537
|
const p = Object.getPrototypeOf(o);
|
|
379
538
|
return !p || p === Object.prototype || p === Array.prototype ? undefined : p;
|
|
380
539
|
}`,
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
540
|
+
void 0,
|
|
541
|
+
e
|
|
542
|
+
),
|
|
543
|
+
(u) => {
|
|
544
|
+
if (n.typeof(u) === "undefined") return;
|
|
545
|
+
const [f] = t(u);
|
|
546
|
+
return f;
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
return typeof i == "object" && Object.setPrototypeOf(o, i), U(n, e, s, t), o;
|
|
389
550
|
}
|
|
390
|
-
function
|
|
551
|
+
function Ee(n, e) {
|
|
391
552
|
const t = n.typeof(e);
|
|
392
|
-
return t === "undefined" || t === "number" || t === "string" || t === "boolean" ? [n.dump(e), !0] : t === "
|
|
553
|
+
return t === "undefined" || t === "number" || t === "string" || t === "boolean" ? [n.dump(e), !0] : t === "bigint" ? [n.getBigInt(e), !0] : t === "object" && n.sameValue(e, n.null) ? [null, !0] : [void 0, !1];
|
|
393
554
|
}
|
|
394
|
-
function
|
|
395
|
-
var
|
|
396
|
-
if (!
|
|
397
|
-
const s =
|
|
398
|
-
return
|
|
555
|
+
function Oe(n, e, t, r) {
|
|
556
|
+
var f;
|
|
557
|
+
if (!Te(n, e)) return;
|
|
558
|
+
const s = pe(), [o, i] = t(s.resolve), [a, u] = t(s.reject);
|
|
559
|
+
return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, o, a), i && o.dispose(), u && a.dispose(), (f = r(s.promise, e)) != null ? f : s.promise;
|
|
399
560
|
}
|
|
400
|
-
function
|
|
401
|
-
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ?
|
|
561
|
+
function Te(n, e) {
|
|
562
|
+
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? Z(n, e, t) : !1) : !1;
|
|
402
563
|
}
|
|
403
|
-
function
|
|
404
|
-
const [t] =
|
|
564
|
+
function He(n, e) {
|
|
565
|
+
const [t] = G(n, e);
|
|
405
566
|
return t;
|
|
406
567
|
}
|
|
407
|
-
function
|
|
408
|
-
var
|
|
568
|
+
function G(n, e) {
|
|
569
|
+
var d, y, h;
|
|
409
570
|
const { ctx: t, marshal: r, find: s, pre: o } = e;
|
|
410
571
|
{
|
|
411
|
-
const [
|
|
412
|
-
if (
|
|
572
|
+
const [c, p] = Ee(t, n);
|
|
573
|
+
if (p) return [c, !1];
|
|
413
574
|
}
|
|
414
575
|
{
|
|
415
|
-
const
|
|
416
|
-
if (
|
|
417
|
-
return [
|
|
576
|
+
const c = s(n);
|
|
577
|
+
if (c)
|
|
578
|
+
return [c, !0];
|
|
418
579
|
}
|
|
419
|
-
const i = (
|
|
420
|
-
|
|
580
|
+
const i = (c) => G(c, e);
|
|
581
|
+
if (e.hostRef) {
|
|
582
|
+
const c = V(t, n);
|
|
583
|
+
if (c) return [c.value, !0];
|
|
584
|
+
}
|
|
585
|
+
const a = be(t, n, o, [...Pe, ...(d = e.custom) != null ? d : []]);
|
|
586
|
+
if (a) return [a, !0];
|
|
587
|
+
const u = ke(t, n, i, o);
|
|
588
|
+
return u ? [u, !0] : [(h = (y = Oe(t, n, r, o)) != null ? y : Se(t, n, r, i, o)) != null ? h : Re(t, n, i, o), !1];
|
|
421
589
|
}
|
|
422
|
-
class
|
|
590
|
+
class A {
|
|
423
591
|
constructor(e) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
592
|
+
l(this, "ctx");
|
|
593
|
+
l(this, "_keyToId", /* @__PURE__ */ new Map());
|
|
594
|
+
l(this, "_key2ToId", /* @__PURE__ */ new Map());
|
|
595
|
+
l(this, "_idToHandle", /* @__PURE__ */ new Map());
|
|
596
|
+
l(this, "_idToHandle2", /* @__PURE__ */ new Map());
|
|
597
|
+
l(this, "_idToKey", /* @__PURE__ */ new Map());
|
|
598
|
+
l(this, "_idToKey2", /* @__PURE__ */ new Map());
|
|
599
|
+
l(this, "_disposables", /* @__PURE__ */ new Set());
|
|
600
|
+
l(this, "_mapGet");
|
|
601
|
+
l(this, "_mapSet");
|
|
602
|
+
l(this, "_mapDelete");
|
|
603
|
+
l(this, "_mapClear");
|
|
604
|
+
l(this, "_nextId", Number.MIN_SAFE_INTEGER);
|
|
436
605
|
this.ctx = e;
|
|
437
606
|
const t = e.unwrapResult(
|
|
438
607
|
e.evalCode(`() => {
|
|
@@ -468,8 +637,8 @@ class O {
|
|
|
468
637
|
const o = (a = this.get(e)) != null ? a : this.get(r);
|
|
469
638
|
if (o)
|
|
470
639
|
return o === t || o === s;
|
|
471
|
-
const i = this.
|
|
472
|
-
return this.
|
|
640
|
+
const i = this._nextId++;
|
|
641
|
+
return this._keyToId.set(e, i), this._idToHandle.set(i, t), this._idToKey.set(i, e), r && (this._key2ToId.set(r, i), this._idToKey2.set(i, r), s && this._idToHandle2.set(i, s)), this.ctx.newNumber(i).consume((u) => {
|
|
473
642
|
this._call(this._mapSet, void 0, t, u, s != null ? s : this.ctx.undefined);
|
|
474
643
|
}), !0;
|
|
475
644
|
}
|
|
@@ -480,7 +649,7 @@ class O {
|
|
|
480
649
|
}
|
|
481
650
|
get(e) {
|
|
482
651
|
var s;
|
|
483
|
-
const t = (s = this.
|
|
652
|
+
const t = (s = this._keyToId.get(e)) != null ? s : this._key2ToId.get(e), r = typeof t == "number" ? this._idToHandle.get(t) : void 0;
|
|
484
653
|
if (r) {
|
|
485
654
|
if (!r.alive) {
|
|
486
655
|
this.delete(e);
|
|
@@ -491,7 +660,7 @@ class O {
|
|
|
491
660
|
}
|
|
492
661
|
getByHandle(e) {
|
|
493
662
|
if (e.alive)
|
|
494
|
-
return this.
|
|
663
|
+
return this._idToKey.get(this.ctx.getNumber(this._call(this._mapGet, void 0, e)));
|
|
495
664
|
}
|
|
496
665
|
has(e) {
|
|
497
666
|
return !!this.get(e);
|
|
@@ -500,77 +669,60 @@ class O {
|
|
|
500
669
|
return typeof this.getByHandle(e) != "undefined";
|
|
501
670
|
}
|
|
502
671
|
keys() {
|
|
503
|
-
return this.
|
|
672
|
+
return this._keyToId.keys();
|
|
504
673
|
}
|
|
505
674
|
delete(e, t) {
|
|
506
|
-
var
|
|
507
|
-
const r = (
|
|
675
|
+
var u;
|
|
676
|
+
const r = (u = this._keyToId.get(e)) != null ? u : this._key2ToId.get(e);
|
|
508
677
|
if (typeof r == "undefined") return;
|
|
509
|
-
const s = this.
|
|
678
|
+
const s = this._idToHandle.get(r), o = this._idToHandle2.get(r);
|
|
510
679
|
this._call(
|
|
511
680
|
this._mapDelete,
|
|
512
681
|
void 0,
|
|
513
|
-
...[s, o].filter((
|
|
514
|
-
)
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
this._map1.delete(a);
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
|
-
for (const [a, u] of this._map2)
|
|
521
|
-
if (u === r) {
|
|
522
|
-
this._map2.delete(a);
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
for (const [a, u] of this._counterMap)
|
|
526
|
-
if (u === e) {
|
|
527
|
-
this._counterMap.delete(a);
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
t && (s != null && s.alive && s.dispose(), o != null && o.alive && o.dispose());
|
|
682
|
+
...[s, o].filter((f) => !!(f != null && f.alive))
|
|
683
|
+
);
|
|
684
|
+
const i = this._idToKey.get(r), a = this._idToKey2.get(r);
|
|
685
|
+
typeof i != "undefined" && this._keyToId.delete(i), typeof a != "undefined" && this._key2ToId.delete(a), this._idToHandle.delete(r), this._idToHandle2.delete(r), this._idToKey.delete(r), this._idToKey2.delete(r), t && (s != null && s.alive && s.dispose(), o != null && o.alive && o.dispose());
|
|
531
686
|
}
|
|
532
687
|
deleteByHandle(e, t) {
|
|
533
688
|
const r = this.getByHandle(e);
|
|
534
689
|
typeof r != "undefined" && this.delete(r, t);
|
|
535
690
|
}
|
|
536
691
|
clear() {
|
|
537
|
-
this.
|
|
692
|
+
this._nextId = 0, this._keyToId.clear(), this._key2ToId.clear(), this._idToHandle.clear(), this._idToHandle2.clear(), this._idToKey.clear(), this._idToKey2.clear(), this._mapClear.alive && this._call(this._mapClear, void 0);
|
|
538
693
|
}
|
|
539
694
|
dispose() {
|
|
540
695
|
for (const e of this._disposables.values())
|
|
541
696
|
e.alive && e.dispose();
|
|
542
|
-
for (const e of this.
|
|
697
|
+
for (const e of this._idToHandle.values())
|
|
543
698
|
e.alive && e.dispose();
|
|
544
|
-
for (const e of this.
|
|
699
|
+
for (const e of this._idToHandle2.values())
|
|
545
700
|
e.alive && e.dispose();
|
|
546
701
|
this._disposables.clear(), this.clear();
|
|
547
702
|
}
|
|
548
703
|
get size() {
|
|
549
|
-
return this.
|
|
704
|
+
return this._keyToId.size;
|
|
550
705
|
}
|
|
551
706
|
[Symbol.iterator]() {
|
|
552
|
-
const e = this.
|
|
707
|
+
const e = this._keyToId.keys();
|
|
553
708
|
return {
|
|
554
709
|
next: () => {
|
|
555
710
|
for (; ; ) {
|
|
556
711
|
const t = e.next();
|
|
557
712
|
if (t.done) return { value: void 0, done: !0 };
|
|
558
|
-
const r = this.
|
|
713
|
+
const r = this._keyToId.get(t.value);
|
|
559
714
|
if (typeof r == "undefined") continue;
|
|
560
|
-
const s = this.
|
|
715
|
+
const s = this._idToHandle.get(r), o = this._idToHandle2.get(r);
|
|
561
716
|
if (!s) continue;
|
|
562
|
-
const i = this.
|
|
717
|
+
const i = this._idToKey2.get(r);
|
|
563
718
|
return { value: [t.value, s, i, o], done: !1 };
|
|
564
719
|
}
|
|
565
720
|
}
|
|
566
721
|
};
|
|
567
722
|
}
|
|
568
|
-
_get2(e) {
|
|
569
|
-
for (const [t, r] of this._map2)
|
|
570
|
-
if (r === e) return t;
|
|
571
|
-
}
|
|
572
723
|
_call(e, t, ...r) {
|
|
573
|
-
return
|
|
724
|
+
return S(
|
|
725
|
+
this.ctx,
|
|
574
726
|
this.ctx.callFunction(
|
|
575
727
|
e,
|
|
576
728
|
typeof t == "undefined" ? this.ctx.undefined : t,
|
|
@@ -579,72 +731,100 @@ class O {
|
|
|
579
731
|
);
|
|
580
732
|
}
|
|
581
733
|
}
|
|
582
|
-
function
|
|
583
|
-
if (!
|
|
734
|
+
function Me(n, e, t, r, s, o, i, a = !0) {
|
|
735
|
+
if (!P(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || i && !i(e))
|
|
584
736
|
return;
|
|
585
|
-
if (
|
|
586
|
-
const
|
|
587
|
-
get(
|
|
588
|
-
return
|
|
737
|
+
if (Be(e, t) || !a) return e;
|
|
738
|
+
const u = new Proxy(e, {
|
|
739
|
+
get(f, d) {
|
|
740
|
+
return d === t ? f : Reflect.get(f, d);
|
|
589
741
|
},
|
|
590
|
-
set(
|
|
591
|
-
var
|
|
592
|
-
const
|
|
593
|
-
return
|
|
594
|
-
[s(
|
|
595
|
-
(
|
|
596
|
-
const [
|
|
597
|
-
|
|
742
|
+
set(f, d, y, h) {
|
|
743
|
+
var v;
|
|
744
|
+
const c = j(y, t), p = (v = o == null ? void 0 : o(h)) != null ? v : "host";
|
|
745
|
+
return p !== "vm" && !Reflect.set(f, d, c) || p === "host" || !n.alive || O(
|
|
746
|
+
[s(h), s(d), s(c)],
|
|
747
|
+
(b, _, g) => {
|
|
748
|
+
const [R, E] = T(n, b, r);
|
|
749
|
+
E ? R.consume((H) => n.setProp(H, _, g)) : n.setProp(R, _, g);
|
|
598
750
|
}
|
|
599
751
|
), !0;
|
|
600
752
|
},
|
|
601
|
-
deleteProperty(
|
|
602
|
-
var
|
|
603
|
-
const
|
|
604
|
-
return
|
|
605
|
-
const [
|
|
606
|
-
if (
|
|
607
|
-
if (
|
|
608
|
-
|
|
753
|
+
deleteProperty(f, d) {
|
|
754
|
+
var h;
|
|
755
|
+
const y = (h = o == null ? void 0 : o(u)) != null ? h : "host";
|
|
756
|
+
return O([s(u), s(d)], (c, p) => {
|
|
757
|
+
const [v, b] = T(n, c, r);
|
|
758
|
+
if (y === "vm" || Reflect.deleteProperty(f, d)) {
|
|
759
|
+
if (y === "host" || !n.alive) return !0;
|
|
760
|
+
b ? v.consume((_) => m(n, "(a, b) => delete a[b]", void 0, _, p)) : m(n, "(a, b) => delete a[b]", void 0, v, p);
|
|
609
761
|
}
|
|
610
762
|
return !0;
|
|
611
763
|
});
|
|
764
|
+
},
|
|
765
|
+
defineProperty(f, d, y) {
|
|
766
|
+
var p;
|
|
767
|
+
const h = (p = o == null ? void 0 : o(u)) != null ? p : "host", c = B({}, y);
|
|
768
|
+
return "value" in c && (c.value = j(c.value, t)), typeof c.get == "function" && (c.get = j(c.get, t)), typeof c.set == "function" && (c.set = j(c.set, t)), h !== "vm" && !Reflect.defineProperty(f, d, c) ? !1 : (h === "host" || !n.alive || O(
|
|
769
|
+
[s(u), s(d), s(c)],
|
|
770
|
+
(v, b, _) => {
|
|
771
|
+
const [g, R] = T(n, v, r), E = (H) => m(
|
|
772
|
+
n,
|
|
773
|
+
"(o, k, d) => { Object.defineProperty(o, k, d); }",
|
|
774
|
+
void 0,
|
|
775
|
+
H,
|
|
776
|
+
b,
|
|
777
|
+
_
|
|
778
|
+
).dispose();
|
|
779
|
+
R ? g.consume(E) : E(g);
|
|
780
|
+
}
|
|
781
|
+
), !0);
|
|
612
782
|
}
|
|
613
783
|
});
|
|
614
|
-
return
|
|
784
|
+
return u;
|
|
615
785
|
}
|
|
616
|
-
function
|
|
617
|
-
if (!
|
|
786
|
+
function Ce(n, e, t, r, s, o, i, a = !0) {
|
|
787
|
+
if (!x(n, e) || i && !i(e, n))
|
|
618
788
|
return [void 0, !1];
|
|
619
|
-
if (
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
789
|
+
if (J(n, e, r)) return [e, !1];
|
|
790
|
+
if (!a) return [e, !1];
|
|
791
|
+
const u = (c) => {
|
|
792
|
+
const p = o == null ? void 0 : o(s(c));
|
|
793
|
+
return typeof p == "string" ? n.newString(p) : n.undefined;
|
|
794
|
+
}, f = (c, p, v) => {
|
|
795
|
+
const b = s(c);
|
|
796
|
+
if (!b) return;
|
|
797
|
+
const _ = s(p);
|
|
798
|
+
if (_ === "__proto__") return;
|
|
799
|
+
const g = s(v);
|
|
800
|
+
j(b, t)[_] = g;
|
|
801
|
+
}, d = (c, p) => {
|
|
802
|
+
const v = s(c);
|
|
803
|
+
if (!v) return;
|
|
804
|
+
const b = s(p);
|
|
805
|
+
Reflect.deleteProperty(j(v, t), b);
|
|
806
|
+
}, y = (c, p, v) => {
|
|
807
|
+
const b = s(c);
|
|
808
|
+
if (!b) return;
|
|
809
|
+
const _ = s(p);
|
|
810
|
+
if (_ === "__proto__") return;
|
|
811
|
+
const g = s(v);
|
|
812
|
+
Object.defineProperty(j(b, t), _, g);
|
|
813
|
+
}, h = n.newFunction("proxyFuncs", (c, ...p) => {
|
|
814
|
+
switch (n.getNumber(c)) {
|
|
638
815
|
case 1:
|
|
639
|
-
return
|
|
816
|
+
return u(p[0]);
|
|
640
817
|
case 2:
|
|
641
|
-
return
|
|
818
|
+
return f(p[0], p[1], p[2]);
|
|
642
819
|
case 3:
|
|
643
|
-
return p
|
|
820
|
+
return d(p[0], p[1]);
|
|
821
|
+
case 4:
|
|
822
|
+
return y(p[0], p[1], p[2]);
|
|
644
823
|
}
|
|
645
824
|
return n.undefined;
|
|
646
|
-
})
|
|
647
|
-
|
|
825
|
+
});
|
|
826
|
+
return w(h, (c) => [
|
|
827
|
+
m(
|
|
648
828
|
n,
|
|
649
829
|
`(target, sym, proxyFuncs) => {
|
|
650
830
|
const rec = new Proxy(target, {
|
|
@@ -656,7 +836,7 @@ function me(n, e, t, r, s, o, i) {
|
|
|
656
836
|
? value[sym] ?? value
|
|
657
837
|
: value;
|
|
658
838
|
const sync = proxyFuncs(1, receiver) ?? "vm";
|
|
659
|
-
if (sync === "host" || Reflect.set(obj, key, v
|
|
839
|
+
if (sync === "host" || Reflect.set(obj, key, v)) {
|
|
660
840
|
if (sync !== "vm") {
|
|
661
841
|
proxyFuncs(2, receiver, key, v);
|
|
662
842
|
}
|
|
@@ -672,68 +852,87 @@ function me(n, e, t, r, s, o, i) {
|
|
|
672
852
|
}
|
|
673
853
|
return true;
|
|
674
854
|
},
|
|
855
|
+
defineProperty(obj, key, descriptor) {
|
|
856
|
+
const sync = proxyFuncs(1, rec) ?? "vm";
|
|
857
|
+
if (sync === "host" || Reflect.defineProperty(obj, key, descriptor)) {
|
|
858
|
+
if (sync !== "vm") {
|
|
859
|
+
proxyFuncs(4, rec, key, descriptor);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return true;
|
|
863
|
+
},
|
|
675
864
|
});
|
|
676
865
|
return rec;
|
|
677
866
|
}`,
|
|
678
867
|
void 0,
|
|
679
868
|
e,
|
|
680
869
|
r,
|
|
681
|
-
|
|
870
|
+
c
|
|
682
871
|
),
|
|
683
872
|
!0
|
|
684
873
|
]);
|
|
685
874
|
}
|
|
686
|
-
function
|
|
875
|
+
function j(n, e) {
|
|
687
876
|
var t;
|
|
688
|
-
return
|
|
877
|
+
return P(n) && (t = n[e]) != null ? t : n;
|
|
689
878
|
}
|
|
690
|
-
function
|
|
691
|
-
return
|
|
879
|
+
function T(n, e, t) {
|
|
880
|
+
return J(n, e, t) ? [n.getProp(e, t), !0] : [e, !1];
|
|
692
881
|
}
|
|
693
|
-
function
|
|
694
|
-
return
|
|
882
|
+
function Be(n, e) {
|
|
883
|
+
return P(n) && !!n[e];
|
|
695
884
|
}
|
|
696
|
-
function
|
|
885
|
+
function J(n, e, t) {
|
|
697
886
|
return !!n.dump(
|
|
698
|
-
|
|
887
|
+
m(
|
|
699
888
|
n,
|
|
700
|
-
//
|
|
701
|
-
|
|
889
|
+
// Built-ins that must not be wrapped (internal slots / non-property access)
|
|
890
|
+
// report as "wrapped" so wrapHandle leaves them alone.
|
|
891
|
+
'(a, s) => (a instanceof Promise) || (a instanceof Date) || (a instanceof ArrayBuffer) || (ArrayBuffer.isView(a)) || (a instanceof Map) || (a instanceof Set) || (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',
|
|
702
892
|
void 0,
|
|
703
893
|
e,
|
|
704
894
|
t
|
|
705
895
|
)
|
|
706
896
|
);
|
|
707
897
|
}
|
|
708
|
-
class
|
|
898
|
+
class Fe {
|
|
709
899
|
/** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
|
|
710
900
|
constructor(e, t) {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
901
|
+
l(this, "context");
|
|
902
|
+
l(this, "_map");
|
|
903
|
+
l(this, "_registeredMap");
|
|
904
|
+
l(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
|
|
905
|
+
l(this, "_sync", /* @__PURE__ */ new Set());
|
|
906
|
+
l(this, "_temporalSync", /* @__PURE__ */ new Set());
|
|
907
|
+
l(this, "_symbol", /* @__PURE__ */ Symbol());
|
|
908
|
+
l(this, "_symbolHandle");
|
|
909
|
+
l(this, "_options");
|
|
910
|
+
l(this, "_isMarshalable", (e) => {
|
|
721
911
|
var r, s;
|
|
722
912
|
const t = (r = this._options) == null ? void 0 : r.isMarshalable;
|
|
723
913
|
return (s = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? s : "json";
|
|
724
914
|
});
|
|
725
|
-
|
|
915
|
+
l(this, "_marshalByReference", (e) => {
|
|
916
|
+
var t, r;
|
|
917
|
+
return !!((r = (t = this._options) == null ? void 0 : t.marshalByReference) != null && r.call(t, this._unwrap(e)));
|
|
918
|
+
});
|
|
919
|
+
// Register an opaque HostRef handle by its host value without wrapping it.
|
|
920
|
+
l(this, "_registerHostRef", (e, t) => {
|
|
921
|
+
const r = this._unwrap(e), s = this._map.get(r);
|
|
922
|
+
return s || (this._map.set(r, t), t);
|
|
923
|
+
});
|
|
924
|
+
l(this, "_marshalFind", (e) => {
|
|
726
925
|
var s, o, i;
|
|
727
926
|
const t = this._unwrap(e);
|
|
728
927
|
return (i = (o = (s = this._registeredMap.get(e)) != null ? s : t !== e ? this._registeredMap.get(t) : void 0) != null ? o : this._map.get(e)) != null ? i : t !== e ? this._map.get(t) : void 0;
|
|
729
928
|
});
|
|
730
|
-
|
|
929
|
+
l(this, "_marshalPre", (e, t, r) => {
|
|
731
930
|
var s;
|
|
732
931
|
if (r !== "json")
|
|
733
|
-
return (s = this._register(e,
|
|
932
|
+
return (s = this._register(e, se(t), this._map)) == null ? void 0 : s[1];
|
|
734
933
|
});
|
|
735
|
-
|
|
736
|
-
const s =
|
|
934
|
+
l(this, "_marshalPreApply", (e, t, r) => {
|
|
935
|
+
const s = P(t) ? this._unwrap(t) : void 0;
|
|
737
936
|
s && this._temporalSync.add(s);
|
|
738
937
|
try {
|
|
739
938
|
return e.apply(t, r);
|
|
@@ -741,49 +940,56 @@ class ve {
|
|
|
741
940
|
s && this._temporalSync.delete(s);
|
|
742
941
|
}
|
|
743
942
|
});
|
|
744
|
-
|
|
745
|
-
var
|
|
943
|
+
l(this, "_marshal", (e) => {
|
|
944
|
+
var i, a, u, f;
|
|
746
945
|
const t = this._registeredMap.get(e);
|
|
747
946
|
if (t)
|
|
748
947
|
return [t, !1];
|
|
749
|
-
const r =
|
|
948
|
+
const r = this._marshalByReference(e) ? this._unwrap(e) : (i = this._wrap(e)) != null ? i : e, s = D(r, {
|
|
750
949
|
ctx: this.context,
|
|
751
950
|
unmarshal: this._unmarshal,
|
|
752
951
|
isMarshalable: this._isMarshalable,
|
|
952
|
+
marshalByReference: this._marshalByReference,
|
|
953
|
+
registerHostRef: this._registerHostRef,
|
|
753
954
|
find: this._marshalFind,
|
|
754
955
|
pre: this._marshalPre,
|
|
755
956
|
preApply: this._marshalPreApply,
|
|
756
|
-
custom: (
|
|
757
|
-
});
|
|
758
|
-
return [
|
|
957
|
+
custom: (a = this._options) == null ? void 0 : a.customMarshaller
|
|
958
|
+
}), o = (f = (u = this._options) == null ? void 0 : u.syncEnabled) != null ? f : !0;
|
|
959
|
+
return [s, !o || !this._map.hasHandle(s)];
|
|
759
960
|
});
|
|
760
|
-
|
|
761
|
-
var r;
|
|
762
|
-
return (
|
|
961
|
+
l(this, "_preUnmarshal", (e, t) => {
|
|
962
|
+
var r, s, o;
|
|
963
|
+
return (o = this._register(e, t, void 0, (s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0)) == null ? void 0 : o[0];
|
|
763
964
|
});
|
|
764
|
-
|
|
965
|
+
l(this, "_unmarshalFind", (e) => {
|
|
765
966
|
var t;
|
|
766
967
|
return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
|
|
767
968
|
});
|
|
768
|
-
|
|
769
|
-
var s;
|
|
969
|
+
l(this, "_unmarshal", (e) => {
|
|
970
|
+
var s, o, i;
|
|
770
971
|
const t = this._registeredMap.getByHandle(e);
|
|
771
972
|
if (typeof t != "undefined")
|
|
772
973
|
return t;
|
|
974
|
+
if ((s = this._options) != null && s.marshalByReference) {
|
|
975
|
+
const a = V(this.context, e);
|
|
976
|
+
if (a) return a.value;
|
|
977
|
+
}
|
|
773
978
|
const [r] = this._wrapHandle(e);
|
|
774
|
-
return
|
|
979
|
+
return He(r != null ? r : e, {
|
|
775
980
|
ctx: this.context,
|
|
776
981
|
marshal: this._marshal,
|
|
777
982
|
find: this._unmarshalFind,
|
|
778
983
|
pre: this._preUnmarshal,
|
|
779
|
-
custom: (
|
|
984
|
+
custom: (o = this._options) == null ? void 0 : o.customUnmarshaller,
|
|
985
|
+
hostRef: !!((i = this._options) != null && i.marshalByReference)
|
|
780
986
|
});
|
|
781
987
|
});
|
|
782
|
-
|
|
988
|
+
l(this, "_syncMode", (e) => {
|
|
783
989
|
const t = this._unwrap(e);
|
|
784
990
|
return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
|
|
785
991
|
});
|
|
786
|
-
|
|
992
|
+
l(this, "_unwrapIfNotSynced", (e) => {
|
|
787
993
|
const t = this._unwrap(e);
|
|
788
994
|
return t instanceof Promise || !this._sync.has(t) ? t : e;
|
|
789
995
|
});
|
|
@@ -791,14 +997,18 @@ class ve {
|
|
|
791
997
|
t != null && t.compat && !("runtime" in e) && (e.runtime = {
|
|
792
998
|
hasPendingJob: () => e.hasPendingJob(),
|
|
793
999
|
executePendingJobs: (s) => e.executePendingJobs(s)
|
|
794
|
-
}), this.context = t != null && t.experimentalContextEx ?
|
|
1000
|
+
}), this.context = t != null && t.experimentalContextEx ? L(e) : e, X(this.context), this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._map = new A(e), this._registeredMap = new A(e), this.registerAll((r = t == null ? void 0 : t.registeredObjects) != null ? r : q);
|
|
795
1001
|
}
|
|
796
1002
|
/**
|
|
797
1003
|
* Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
|
|
798
1004
|
*/
|
|
799
1005
|
dispose() {
|
|
800
1006
|
var e, t;
|
|
801
|
-
this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose(), (t = (e = this.context).disposeEx) == null || t.call(e);
|
|
1007
|
+
this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose(), Y(this.context), (t = (e = this.context).disposeEx) == null || t.call(e);
|
|
1008
|
+
}
|
|
1009
|
+
/** Allows `using arena = new Arena(...)` to dispose the arena automatically. */
|
|
1010
|
+
[Symbol.dispose]() {
|
|
1011
|
+
this.dispose();
|
|
802
1012
|
}
|
|
803
1013
|
/**
|
|
804
1014
|
* Evaluate JS code in the VM and get the result as an object on the host side. It also converts and re-throws error objects when an error is thrown during evaluation.
|
|
@@ -850,7 +1060,7 @@ class ve {
|
|
|
850
1060
|
const t = this.context.runtime.executePendingJobs(e);
|
|
851
1061
|
if ("value" in t)
|
|
852
1062
|
return t.value;
|
|
853
|
-
throw this._unwrapIfNotSynced(t.error
|
|
1063
|
+
throw this._unwrapIfNotSynced(w(t.error, this._unmarshal));
|
|
854
1064
|
}
|
|
855
1065
|
/**
|
|
856
1066
|
* Set the max memory this runtime can allocate.
|
|
@@ -945,7 +1155,7 @@ class ve {
|
|
|
945
1155
|
*/
|
|
946
1156
|
expose(e) {
|
|
947
1157
|
for (const [t, r] of Object.entries(e))
|
|
948
|
-
|
|
1158
|
+
ne(this._marshal(r), (s) => {
|
|
949
1159
|
this.context.setProp(this.context.global, t, s);
|
|
950
1160
|
});
|
|
951
1161
|
}
|
|
@@ -956,7 +1166,7 @@ class ve {
|
|
|
956
1166
|
*/
|
|
957
1167
|
sync(e) {
|
|
958
1168
|
const t = this._wrap(e);
|
|
959
|
-
return typeof t == "undefined" ? e : (
|
|
1169
|
+
return typeof t == "undefined" ? e : (I(t, (r) => {
|
|
960
1170
|
const s = this._unwrap(r);
|
|
961
1171
|
this._sync.add(s);
|
|
962
1172
|
}), t);
|
|
@@ -992,7 +1202,7 @@ class ve {
|
|
|
992
1202
|
this.unregister(r, t);
|
|
993
1203
|
}
|
|
994
1204
|
startSync(e) {
|
|
995
|
-
if (!
|
|
1205
|
+
if (!P(e)) return;
|
|
996
1206
|
const t = this._unwrap(e);
|
|
997
1207
|
this._sync.add(t);
|
|
998
1208
|
}
|
|
@@ -1002,11 +1212,11 @@ class ve {
|
|
|
1002
1212
|
_unwrapResult(e) {
|
|
1003
1213
|
if ("value" in e)
|
|
1004
1214
|
return e.value;
|
|
1005
|
-
throw this._unwrapIfNotSynced(e.error
|
|
1215
|
+
throw this._unwrapIfNotSynced(w(e.error, this._unmarshal));
|
|
1006
1216
|
}
|
|
1007
1217
|
_unwrapResultAndUnmarshal(e) {
|
|
1008
1218
|
if (e)
|
|
1009
|
-
return this._unwrapIfNotSynced(this._unwrapResult(e)
|
|
1219
|
+
return this._unwrapIfNotSynced(w(this._unwrapResult(e), this._unmarshal));
|
|
1010
1220
|
}
|
|
1011
1221
|
_register(e, t, r = this._map, s) {
|
|
1012
1222
|
if (this._registeredMap.has(e) || this._registeredMap.hasHandle(t))
|
|
@@ -1015,55 +1225,76 @@ class ve {
|
|
|
1015
1225
|
const [i] = this._wrapHandle(t), a = e instanceof Promise;
|
|
1016
1226
|
if (!i || !o && !a) return;
|
|
1017
1227
|
a && (o = e);
|
|
1018
|
-
const u = this._unwrap(e), [
|
|
1019
|
-
if (r.set(o, i, u,
|
|
1228
|
+
const u = this._unwrap(e), [f, d] = this._unwrapHandle(t);
|
|
1229
|
+
if (r.set(o, i, u, f))
|
|
1020
1230
|
s && this._sync.add(u);
|
|
1021
|
-
else throw
|
|
1231
|
+
else throw d && f.dispose(), new Error("already registered");
|
|
1022
1232
|
return [o, i];
|
|
1023
1233
|
}
|
|
1024
1234
|
_wrap(e) {
|
|
1025
|
-
var t;
|
|
1026
|
-
return
|
|
1235
|
+
var t, r, s;
|
|
1236
|
+
return Me(
|
|
1027
1237
|
this.context,
|
|
1028
1238
|
e,
|
|
1029
1239
|
this._symbol,
|
|
1030
1240
|
this._symbolHandle,
|
|
1031
1241
|
this._marshal,
|
|
1032
1242
|
this._syncMode,
|
|
1033
|
-
(t = this._options) == null ? void 0 : t.isWrappable
|
|
1243
|
+
(t = this._options) == null ? void 0 : t.isWrappable,
|
|
1244
|
+
(s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0
|
|
1034
1245
|
);
|
|
1035
1246
|
}
|
|
1036
1247
|
_unwrap(e) {
|
|
1037
|
-
return
|
|
1248
|
+
return j(e, this._symbol);
|
|
1038
1249
|
}
|
|
1039
1250
|
_wrapHandle(e) {
|
|
1040
|
-
var t;
|
|
1041
|
-
return
|
|
1251
|
+
var t, r, s;
|
|
1252
|
+
return Ce(
|
|
1042
1253
|
this.context,
|
|
1043
1254
|
e,
|
|
1044
1255
|
this._symbol,
|
|
1045
1256
|
this._symbolHandle,
|
|
1046
1257
|
this._unmarshal,
|
|
1047
1258
|
this._syncMode,
|
|
1048
|
-
(t = this._options) == null ? void 0 : t.isHandleWrappable
|
|
1259
|
+
(t = this._options) == null ? void 0 : t.isHandleWrappable,
|
|
1260
|
+
(s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0
|
|
1049
1261
|
);
|
|
1050
1262
|
}
|
|
1051
1263
|
_unwrapHandle(e) {
|
|
1052
|
-
return
|
|
1264
|
+
return T(this.context, e, this._symbolHandle);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
class Ne extends Fe {
|
|
1268
|
+
constructor(t, r) {
|
|
1269
|
+
super(t, r);
|
|
1270
|
+
l(this, "asyncContext");
|
|
1271
|
+
this.asyncContext = t;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Evaluate JS code asynchronously in the VM and get the result on the host
|
|
1275
|
+
* side. Like `evalCode`, it converts and re-throws errors thrown during
|
|
1276
|
+
* evaluation. Use this when the code awaits host-provided promises.
|
|
1277
|
+
*/
|
|
1278
|
+
evalCodeAsync(t, r) {
|
|
1279
|
+
return F(this, null, function* () {
|
|
1280
|
+
const s = yield this.asyncContext.evalCodeAsync(t, r);
|
|
1281
|
+
return this._unwrapResultAndUnmarshal(s);
|
|
1282
|
+
});
|
|
1053
1283
|
}
|
|
1054
1284
|
}
|
|
1055
1285
|
export {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1286
|
+
Fe as Arena,
|
|
1287
|
+
Ne as AsyncArena,
|
|
1288
|
+
A as VMMap,
|
|
1289
|
+
m as call,
|
|
1290
|
+
Ie as complexity,
|
|
1291
|
+
te as consumeAll,
|
|
1292
|
+
q as defaultRegisteredObjects,
|
|
1293
|
+
ce as isES2015Class,
|
|
1294
|
+
x as isHandleObject,
|
|
1295
|
+
P as isObject,
|
|
1296
|
+
ee as json,
|
|
1297
|
+
D as marshal,
|
|
1298
|
+
He as unmarshal,
|
|
1299
|
+
I as walkObject
|
|
1069
1300
|
};
|