quickjs-emscripten-sync 1.9.1 → 1.10.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 +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/quickjs-emscripten-sync.js +222 -204
- package/dist/quickjs-emscripten-sync.umd.cjs +7 -7
- package/package.json +1 -1
- package/src/edge.test.ts +44 -2
- package/src/identity.test.ts +57 -0
- package/src/index.test.ts +20 -0
- package/src/index.ts +12 -0
- package/src/marshal/function.test.ts +6 -4
- package/src/marshal/function.ts +19 -2
- package/src/marshal/index.ts +15 -1
- package/src/remarshalleak.test.ts +50 -0
- package/src/vmmap.ts +5 -1
|
@@ -9,21 +9,21 @@ var M = (n, e, t) => e in n ? z(n, e, { enumerable: !0, configurable: !0, writab
|
|
|
9
9
|
L.call(e, t) && M(n, t, e[t]);
|
|
10
10
|
return n;
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var p = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
|
|
13
13
|
var A = (n, e, t) => new Promise((r, s) => {
|
|
14
|
-
var i = (
|
|
14
|
+
var i = (u) => {
|
|
15
15
|
try {
|
|
16
|
-
f(t.next(
|
|
17
|
-
} catch (
|
|
18
|
-
s(
|
|
16
|
+
f(t.next(u));
|
|
17
|
+
} catch (a) {
|
|
18
|
+
s(a);
|
|
19
19
|
}
|
|
20
|
-
}, o = (
|
|
20
|
+
}, o = (u) => {
|
|
21
21
|
try {
|
|
22
|
-
f(t.throw(
|
|
23
|
-
} catch (
|
|
24
|
-
s(
|
|
22
|
+
f(t.throw(u));
|
|
23
|
+
} catch (a) {
|
|
24
|
+
s(a);
|
|
25
25
|
}
|
|
26
|
-
}, f = (
|
|
26
|
+
}, f = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(i, o);
|
|
27
27
|
f((t = t.apply(n, e)).next());
|
|
28
28
|
});
|
|
29
29
|
const K = (n) => {
|
|
@@ -36,13 +36,13 @@ const K = (n) => {
|
|
|
36
36
|
};
|
|
37
37
|
class q {
|
|
38
38
|
constructor(e) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
p(this, "context");
|
|
40
|
+
p(this, "fn");
|
|
41
|
+
p(this, "fnGenerator");
|
|
42
|
+
p(this, "fnCounter", Number.MIN_SAFE_INTEGER);
|
|
43
|
+
p(this, "fnMap", /* @__PURE__ */ new Map());
|
|
44
44
|
/** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
|
|
45
|
-
|
|
45
|
+
p(this, "newFunction", (e, t) => {
|
|
46
46
|
this.fnCounter++;
|
|
47
47
|
const r = this.fnCounter;
|
|
48
48
|
return this.fnMap.set(r, t), this.context.unwrapResult(
|
|
@@ -109,7 +109,7 @@ const Q = [
|
|
|
109
109
|
// built-in symbols
|
|
110
110
|
...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
|
|
111
111
|
];
|
|
112
|
-
function
|
|
112
|
+
function R(n, e) {
|
|
113
113
|
if ("error" in e && e.error) {
|
|
114
114
|
const { error: t } = e;
|
|
115
115
|
let r;
|
|
@@ -127,25 +127,25 @@ function T(n, e) {
|
|
|
127
127
|
return e.value;
|
|
128
128
|
}
|
|
129
129
|
function X(n, e) {
|
|
130
|
-
const t =
|
|
130
|
+
const t = R(n, n.evalCode(e)), r = (i, ...o) => R(n, n.callFunction(t, i != null ? i : n.undefined, ...o)), s = () => t.dispose();
|
|
131
131
|
return r.dispose = s, r[Symbol.dispose] = s, Object.defineProperty(r, "alive", {
|
|
132
132
|
get: () => t.alive
|
|
133
133
|
}), r;
|
|
134
134
|
}
|
|
135
|
-
const
|
|
135
|
+
const T = /* @__PURE__ */ new WeakMap();
|
|
136
136
|
function Y(n) {
|
|
137
|
-
|
|
137
|
+
T.has(n) || T.set(n, /* @__PURE__ */ new Map());
|
|
138
138
|
}
|
|
139
139
|
function Z(n) {
|
|
140
|
-
const e =
|
|
140
|
+
const e = T.get(n);
|
|
141
141
|
if (e) {
|
|
142
142
|
for (const t of e.values())
|
|
143
143
|
t.alive && t.dispose();
|
|
144
|
-
|
|
144
|
+
T.delete(n);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
function m(n, e, t, ...r) {
|
|
148
|
-
const s =
|
|
148
|
+
const s = T.get(n);
|
|
149
149
|
if (!s) {
|
|
150
150
|
const o = X(n, e);
|
|
151
151
|
try {
|
|
@@ -155,7 +155,7 @@ function m(n, e, t, ...r) {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
let i = s.get(e);
|
|
158
|
-
return (!i || !i.alive) && (i =
|
|
158
|
+
return (!i || !i.alive) && (i = R(n, n.evalCode(e)), s.set(e, i)), R(n, n.callFunction(i, t != null ? t : n.undefined, ...r));
|
|
159
159
|
}
|
|
160
160
|
function x(n, e, t) {
|
|
161
161
|
return n.dump(m(n, "(a, b) => a instanceof b", void 0, e, t));
|
|
@@ -190,7 +190,7 @@ function re([n, e], t) {
|
|
|
190
190
|
e && n.dispose();
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function H(n, e) {
|
|
194
194
|
try {
|
|
195
195
|
return e(...n.map((t) => t[0]));
|
|
196
196
|
} finally {
|
|
@@ -275,39 +275,43 @@ function pe() {
|
|
|
275
275
|
}
|
|
276
276
|
function D(n, e, t, r, s = () => {
|
|
277
277
|
}) {
|
|
278
|
-
const i = n.newObject(), o = [], f = (
|
|
279
|
-
const
|
|
280
|
-
y && o.push(y), h && o.push(h), c && o.push(c), n.newObject().consume((
|
|
281
|
-
Object.entries(
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
}), n.setProp(i,
|
|
278
|
+
const i = n.newObject(), o = [], f = (u, a) => {
|
|
279
|
+
const d = r(u), y = typeof a.value == "undefined" ? void 0 : r(a.value), h = typeof a.get == "undefined" ? void 0 : r(a.get), c = typeof a.set == "undefined" ? void 0 : r(a.set);
|
|
280
|
+
y && o.push(y), h && o.push(h), c && o.push(c), n.newObject().consume((l) => {
|
|
281
|
+
Object.entries(a).forEach(([_, b]) => {
|
|
282
|
+
const v = _ === "value" ? y : _ === "get" ? h : _ === "set" ? c : b ? n.true : n.false;
|
|
283
|
+
v && n.setProp(l, _, v);
|
|
284
|
+
}), n.setProp(i, d, l);
|
|
285
285
|
});
|
|
286
286
|
};
|
|
287
287
|
try {
|
|
288
|
-
const
|
|
289
|
-
Object.entries(
|
|
290
|
-
for (const
|
|
288
|
+
const u = Object.getOwnPropertyDescriptors(e);
|
|
289
|
+
Object.entries(u).forEach(([a, d]) => f(a, d)), Object.getOwnPropertySymbols(u).forEach((a) => f(a, u[a])), m(n, "Object.defineProperties", void 0, t, i).dispose();
|
|
290
|
+
for (const a of o) s(a);
|
|
291
291
|
} finally {
|
|
292
292
|
i.dispose();
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
function le(n, e, t, r, s, i, o = () => {
|
|
296
|
-
}) {
|
|
297
|
-
var
|
|
296
|
+
}, f = (u) => u) {
|
|
297
|
+
var d;
|
|
298
298
|
if (typeof e != "function") return;
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
if (ce(e) && S(
|
|
302
|
-
const
|
|
303
|
-
return Object.entries(
|
|
304
|
-
const v = t(
|
|
305
|
-
n.setProp(this,
|
|
299
|
+
const u = n.newFunction(e.name, function(...y) {
|
|
300
|
+
const h = n.sameValue(this, n.global) ? void 0 : r(this), c = y.map((l) => r(l));
|
|
301
|
+
if (ce(e) && S(h)) {
|
|
302
|
+
const l = new e(...c);
|
|
303
|
+
return Object.entries(l).forEach(([_, b]) => {
|
|
304
|
+
const v = t(b);
|
|
305
|
+
n.setProp(this, _, v), o(v);
|
|
306
306
|
}), this;
|
|
307
307
|
}
|
|
308
|
-
return
|
|
308
|
+
return f(
|
|
309
|
+
t(
|
|
310
|
+
i ? i(e, h, c) : e.apply(h, c)
|
|
311
|
+
)
|
|
312
|
+
);
|
|
309
313
|
}).consume(
|
|
310
|
-
(
|
|
314
|
+
(y) => (
|
|
311
315
|
// fucntions created by vm.newFunction are not callable as a class constrcutor
|
|
312
316
|
m(
|
|
313
317
|
n,
|
|
@@ -318,11 +322,11 @@ function le(n, e, t, r, s, i, o = () => {
|
|
|
318
322
|
return fn;
|
|
319
323
|
}`,
|
|
320
324
|
void 0,
|
|
321
|
-
|
|
325
|
+
y
|
|
322
326
|
)
|
|
323
327
|
)
|
|
324
|
-
), a = (
|
|
325
|
-
return D(n, e,
|
|
328
|
+
), a = (d = s(e, u)) != null ? d : u;
|
|
329
|
+
return D(n, e, u, t, o), a;
|
|
326
330
|
}
|
|
327
331
|
function de(n, e, t) {
|
|
328
332
|
if (!(typeof e != "object" && typeof e != "function") && e !== null)
|
|
@@ -337,28 +341,28 @@ function he(n, e, t, r, s = () => {
|
|
|
337
341
|
}) {
|
|
338
342
|
var i, o;
|
|
339
343
|
if (e instanceof Map) {
|
|
340
|
-
const f = m(n, "() => new Map()"),
|
|
341
|
-
for (const [
|
|
342
|
-
const y = t(
|
|
344
|
+
const f = m(n, "() => new Map()"), u = (i = r(e, f)) != null ? i : f;
|
|
345
|
+
for (const [a, d] of e) {
|
|
346
|
+
const y = t(a), h = t(d);
|
|
343
347
|
m(n, "(m, k, v) => m.set(k, v)", void 0, f, y, h).dispose(), s(y), s(h);
|
|
344
348
|
}
|
|
345
|
-
return
|
|
349
|
+
return u;
|
|
346
350
|
}
|
|
347
351
|
if (e instanceof Set) {
|
|
348
|
-
const f = m(n, "() => new Set()"),
|
|
349
|
-
for (const
|
|
350
|
-
const
|
|
351
|
-
m(n, "(s, v) => s.add(v)", void 0, f,
|
|
352
|
+
const f = m(n, "() => new Set()"), u = (o = r(e, f)) != null ? o : f;
|
|
353
|
+
for (const a of e) {
|
|
354
|
+
const d = t(a);
|
|
355
|
+
m(n, "(s, v) => s.add(v)", void 0, f, d).dispose(), s(d);
|
|
352
356
|
}
|
|
353
|
-
return
|
|
357
|
+
return u;
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
function me(n, e, t, r, s = () => {
|
|
357
361
|
}) {
|
|
358
|
-
var
|
|
362
|
+
var a;
|
|
359
363
|
if (typeof e != "object" || e === null) return;
|
|
360
|
-
const i = Array.isArray(e) ? n.newArray() : n.newObject(), o = (
|
|
361
|
-
return
|
|
364
|
+
const i = Array.isArray(e) ? n.newArray() : n.newObject(), o = (a = r(e, i)) != null ? a : i, f = Object.getPrototypeOf(e), u = f && f !== Object.prototype && f !== Array.prototype ? t(f) : void 0;
|
|
365
|
+
return u && (m(n, "Object.setPrototypeOf", void 0, o, u).dispose(), s(u)), D(n, e, i, t, s), o;
|
|
362
366
|
}
|
|
363
367
|
function _e(n, e) {
|
|
364
368
|
switch (typeof e) {
|
|
@@ -386,7 +390,7 @@ function ve(n, e, t, r) {
|
|
|
386
390
|
), (i = r(e, s)) != null ? i : s.handle;
|
|
387
391
|
}
|
|
388
392
|
function U(n, e) {
|
|
389
|
-
var y, h, c,
|
|
393
|
+
var y, h, c, l, _, b, v, j;
|
|
390
394
|
const { ctx: t, unmarshal: r, isMarshalable: s, find: i, pre: o } = e;
|
|
391
395
|
{
|
|
392
396
|
const w = _e(t, n);
|
|
@@ -404,11 +408,20 @@ function U(n, e) {
|
|
|
404
408
|
const f = s == null ? void 0 : s(n);
|
|
405
409
|
if (f === !1)
|
|
406
410
|
return t.undefined;
|
|
407
|
-
const
|
|
411
|
+
const u = (w, k) => o(w, k, f);
|
|
408
412
|
if (f === "json")
|
|
409
|
-
return ye(t, n,
|
|
410
|
-
const
|
|
411
|
-
return (j = (
|
|
413
|
+
return ye(t, n, u);
|
|
414
|
+
const a = (w) => U(w, e), d = e.disposeTransient;
|
|
415
|
+
return (j = (v = (b = (_ = (l = ie(t, n, u, [...fe, ...(c = e.custom) != null ? c : []])) != null ? l : ve(t, n, a, u)) != null ? _ : le(
|
|
416
|
+
t,
|
|
417
|
+
n,
|
|
418
|
+
a,
|
|
419
|
+
r,
|
|
420
|
+
u,
|
|
421
|
+
e.preApply,
|
|
422
|
+
d,
|
|
423
|
+
e.prepareReturn
|
|
424
|
+
)) != null ? b : he(t, n, a, u, d)) != null ? v : me(t, n, a, u, d)) != null ? j : t.undefined;
|
|
412
425
|
}
|
|
413
426
|
function be(n, e, t, r) {
|
|
414
427
|
var i;
|
|
@@ -461,13 +474,13 @@ function V(n, e, t, r) {
|
|
|
461
474
|
["configurable", !1],
|
|
462
475
|
["enumerable", !1],
|
|
463
476
|
["writable", !1]
|
|
464
|
-
].reduce((
|
|
465
|
-
const y = n.getProp(i,
|
|
466
|
-
if (h === "undefined") return
|
|
467
|
-
if (!
|
|
468
|
-
return a
|
|
469
|
-
const [c,
|
|
470
|
-
return
|
|
477
|
+
].reduce((u, [a, d]) => {
|
|
478
|
+
const y = n.getProp(i, a), h = n.typeof(y);
|
|
479
|
+
if (h === "undefined") return u;
|
|
480
|
+
if (!d && h === "boolean")
|
|
481
|
+
return u[a] = n.dump(n.getProp(i, a)), u;
|
|
482
|
+
const [c, l] = r(y);
|
|
483
|
+
return l && y.dispose(), u[a] = c, u;
|
|
471
484
|
}, {});
|
|
472
485
|
Object.defineProperty(t, o, f);
|
|
473
486
|
}),
|
|
@@ -489,17 +502,17 @@ function V(n, e, t, r) {
|
|
|
489
502
|
function Se(n, e, t, r, s) {
|
|
490
503
|
var f;
|
|
491
504
|
if (n.typeof(e) !== "function") return;
|
|
492
|
-
const i = function(...
|
|
493
|
-
return
|
|
494
|
-
[t(this), ...
|
|
495
|
-
(
|
|
505
|
+
const i = function(...u) {
|
|
506
|
+
return H(
|
|
507
|
+
[t(this), ...u.map((a) => t(a))],
|
|
508
|
+
(a, ...d) => {
|
|
496
509
|
if (new.target) {
|
|
497
|
-
const [
|
|
498
|
-
m(n, "(Cls, ...args) => new Cls(...args)",
|
|
510
|
+
const [l] = r(
|
|
511
|
+
m(n, "(Cls, ...args) => new Cls(...args)", a, e, ...d)
|
|
499
512
|
);
|
|
500
|
-
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(
|
|
513
|
+
return Object.defineProperties(this, Object.getOwnPropertyDescriptors(l)), this;
|
|
501
514
|
}
|
|
502
|
-
const y =
|
|
515
|
+
const y = R(n, n.callFunction(e, a, ...d)), [h, c] = r(y);
|
|
503
516
|
return c && y.dispose(), h;
|
|
504
517
|
}
|
|
505
518
|
);
|
|
@@ -516,20 +529,20 @@ function G(n, e) {
|
|
|
516
529
|
}
|
|
517
530
|
}
|
|
518
531
|
function ke(n, e, t, r) {
|
|
519
|
-
const s = g(m(n, "a => a instanceof Map", void 0, e), (
|
|
532
|
+
const s = g(m(n, "a => a instanceof Map", void 0, e), (u) => n.dump(u)), i = !s && g(m(n, "a => a instanceof Set", void 0, e), (u) => n.dump(u));
|
|
520
533
|
if (!s && !i) return;
|
|
521
534
|
const o = s ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
522
535
|
r(o, e);
|
|
523
536
|
const f = n.unwrapResult(n.getIterator(e));
|
|
524
537
|
try {
|
|
525
|
-
for (const
|
|
526
|
-
const
|
|
538
|
+
for (const u of f) {
|
|
539
|
+
const a = n.unwrapResult(u);
|
|
527
540
|
if (s) {
|
|
528
|
-
const
|
|
529
|
-
c &&
|
|
541
|
+
const d = n.getProp(a, 0), y = n.getProp(a, 1), [h, c] = t(d), [l, _] = t(y);
|
|
542
|
+
c && d.dispose(), _ && y.dispose(), o.set(h, l), a.dispose();
|
|
530
543
|
} else {
|
|
531
|
-
const [
|
|
532
|
-
y &&
|
|
544
|
+
const [d, y] = t(a);
|
|
545
|
+
y && a.dispose(), o.add(d);
|
|
533
546
|
}
|
|
534
547
|
}
|
|
535
548
|
} finally {
|
|
@@ -537,10 +550,10 @@ function ke(n, e, t, r) {
|
|
|
537
550
|
}
|
|
538
551
|
return o;
|
|
539
552
|
}
|
|
540
|
-
function
|
|
553
|
+
function Re(n, e, t, r) {
|
|
541
554
|
var f;
|
|
542
555
|
if (n.typeof(e) !== "object" || n.sameValue(e, n.null)) return;
|
|
543
|
-
const s = g(m(n, "Array.isArray", void 0, e), (
|
|
556
|
+
const s = g(m(n, "Array.isArray", void 0, e), (u) => n.dump(u)) ? [] : {}, i = (f = r(s, e)) != null ? f : s, o = g(
|
|
544
557
|
m(
|
|
545
558
|
n,
|
|
546
559
|
`o => {
|
|
@@ -550,23 +563,23 @@ function Te(n, e, t, r) {
|
|
|
550
563
|
void 0,
|
|
551
564
|
e
|
|
552
565
|
),
|
|
553
|
-
(
|
|
554
|
-
if (n.typeof(
|
|
555
|
-
const [
|
|
556
|
-
return
|
|
566
|
+
(u) => {
|
|
567
|
+
if (n.typeof(u) === "undefined") return;
|
|
568
|
+
const [a] = t(u);
|
|
569
|
+
return a;
|
|
557
570
|
}
|
|
558
571
|
);
|
|
559
572
|
return typeof o == "object" && Object.setPrototypeOf(i, o), V(n, e, s, t), i;
|
|
560
573
|
}
|
|
561
|
-
function
|
|
574
|
+
function Te(n, e) {
|
|
562
575
|
const t = n.typeof(e);
|
|
563
576
|
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];
|
|
564
577
|
}
|
|
565
|
-
function
|
|
566
|
-
var
|
|
578
|
+
function He(n, e, t, r) {
|
|
579
|
+
var a;
|
|
567
580
|
if (!Ee(n, e)) return;
|
|
568
|
-
const s = pe(), [i, o] = t(s.resolve), [f,
|
|
569
|
-
return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, f), o && i.dispose(),
|
|
581
|
+
const s = pe(), [i, o] = t(s.resolve), [f, u] = t(s.reject);
|
|
582
|
+
return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, f), o && i.dispose(), u && f.dispose(), (a = r(s.promise, e)) != null ? a : s.promise;
|
|
570
583
|
}
|
|
571
584
|
function Ee(n, e) {
|
|
572
585
|
return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? x(n, e, t) : !1) : !1;
|
|
@@ -576,11 +589,11 @@ function Oe(n, e) {
|
|
|
576
589
|
return t;
|
|
577
590
|
}
|
|
578
591
|
function J(n, e) {
|
|
579
|
-
var
|
|
592
|
+
var d, y, h;
|
|
580
593
|
const { ctx: t, marshal: r, find: s, pre: i } = e;
|
|
581
594
|
{
|
|
582
|
-
const [c,
|
|
583
|
-
if (
|
|
595
|
+
const [c, l] = Te(t, n);
|
|
596
|
+
if (l) return [c, !1];
|
|
584
597
|
}
|
|
585
598
|
{
|
|
586
599
|
const c = s(n);
|
|
@@ -592,26 +605,26 @@ function J(n, e) {
|
|
|
592
605
|
const c = G(t, n);
|
|
593
606
|
if (c) return [c.value, !0];
|
|
594
607
|
}
|
|
595
|
-
const f = be(t, n, i, [...Pe, ...(
|
|
608
|
+
const f = be(t, n, i, [...Pe, ...(d = e.custom) != null ? d : []]);
|
|
596
609
|
if (f) return [f, !0];
|
|
597
|
-
const
|
|
598
|
-
return
|
|
610
|
+
const u = ke(t, n, o, i);
|
|
611
|
+
return u ? [u, !0] : [(h = (y = He(t, n, r, i)) != null ? y : Se(t, n, r, o, i)) != null ? h : Re(t, n, o, i), !1];
|
|
599
612
|
}
|
|
600
613
|
class I {
|
|
601
614
|
constructor(e) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
+
p(this, "ctx");
|
|
616
|
+
p(this, "_keyToId", /* @__PURE__ */ new Map());
|
|
617
|
+
p(this, "_key2ToId", /* @__PURE__ */ new Map());
|
|
618
|
+
p(this, "_idToHandle", /* @__PURE__ */ new Map());
|
|
619
|
+
p(this, "_idToHandle2", /* @__PURE__ */ new Map());
|
|
620
|
+
p(this, "_idToKey", /* @__PURE__ */ new Map());
|
|
621
|
+
p(this, "_idToKey2", /* @__PURE__ */ new Map());
|
|
622
|
+
p(this, "_disposables", /* @__PURE__ */ new Set());
|
|
623
|
+
p(this, "_mapGet");
|
|
624
|
+
p(this, "_mapSet");
|
|
625
|
+
p(this, "_mapDelete");
|
|
626
|
+
p(this, "_mapClear");
|
|
627
|
+
p(this, "_nextId", Number.MIN_SAFE_INTEGER);
|
|
615
628
|
this.ctx = e;
|
|
616
629
|
const t = e.unwrapResult(
|
|
617
630
|
e.evalCode(`() => {
|
|
@@ -648,8 +661,8 @@ class I {
|
|
|
648
661
|
if (i)
|
|
649
662
|
return i === t || i === s;
|
|
650
663
|
const o = this._nextId++;
|
|
651
|
-
return this._keyToId.set(e, o), this._idToHandle.set(o, t), this._idToKey.set(o, e), r && (this._key2ToId.set(r, o), this._idToKey2.set(o, r), s && this._idToHandle2.set(o, s)), this.ctx.newNumber(o).consume((
|
|
652
|
-
this._call(this._mapSet, void 0, t,
|
|
664
|
+
return this._keyToId.set(e, o), this._idToHandle.set(o, t), this._idToKey.set(o, e), r && (this._key2ToId.set(r, o), this._idToKey2.set(o, r), s && this._idToHandle2.set(o, s)), this.ctx.newNumber(o).consume((u) => {
|
|
665
|
+
this._call(this._mapSet, void 0, t, u, s != null ? s : this.ctx.undefined);
|
|
653
666
|
}), !0;
|
|
654
667
|
}
|
|
655
668
|
merge(e) {
|
|
@@ -662,7 +675,7 @@ class I {
|
|
|
662
675
|
const t = (s = this._keyToId.get(e)) != null ? s : this._key2ToId.get(e), r = typeof t == "number" ? this._idToHandle.get(t) : void 0;
|
|
663
676
|
if (r) {
|
|
664
677
|
if (!r.alive) {
|
|
665
|
-
this.delete(e);
|
|
678
|
+
this.delete(e, !0);
|
|
666
679
|
return;
|
|
667
680
|
}
|
|
668
681
|
return r;
|
|
@@ -682,14 +695,14 @@ class I {
|
|
|
682
695
|
return this._keyToId.keys();
|
|
683
696
|
}
|
|
684
697
|
delete(e, t) {
|
|
685
|
-
var
|
|
686
|
-
const r = (
|
|
698
|
+
var u;
|
|
699
|
+
const r = (u = this._keyToId.get(e)) != null ? u : this._key2ToId.get(e);
|
|
687
700
|
if (typeof r == "undefined") return;
|
|
688
701
|
const s = this._idToHandle.get(r), i = this._idToHandle2.get(r);
|
|
689
702
|
this._call(
|
|
690
703
|
this._mapDelete,
|
|
691
704
|
void 0,
|
|
692
|
-
...[s, i].filter((
|
|
705
|
+
...[s, i].filter((a) => !!(a != null && a.alive))
|
|
693
706
|
);
|
|
694
707
|
const o = this._idToKey.get(r), f = this._idToKey2.get(r);
|
|
695
708
|
typeof o != "undefined" && this._keyToId.delete(o), typeof f != "undefined" && this._key2ToId.delete(f), this._idToHandle.delete(r), this._idToHandle2.delete(r), this._idToKey.delete(r), this._idToKey2.delete(r), t && (s != null && s.alive && s.dispose(), i != null && i.alive && i.dispose());
|
|
@@ -731,7 +744,7 @@ class I {
|
|
|
731
744
|
};
|
|
732
745
|
}
|
|
733
746
|
_call(e, t, ...r) {
|
|
734
|
-
return
|
|
747
|
+
return R(
|
|
735
748
|
this.ctx,
|
|
736
749
|
this.ctx.callFunction(
|
|
737
750
|
e,
|
|
@@ -745,91 +758,91 @@ function Me(n, e, t, r, s, i, o, f = !0) {
|
|
|
745
758
|
if (!S(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || o && !o(e))
|
|
746
759
|
return;
|
|
747
760
|
if (Be(e, t) || !f) return e;
|
|
748
|
-
const
|
|
749
|
-
get(
|
|
750
|
-
return
|
|
761
|
+
const u = new Proxy(e, {
|
|
762
|
+
get(a, d) {
|
|
763
|
+
return d === t ? a : Reflect.get(a, d);
|
|
751
764
|
},
|
|
752
|
-
set(
|
|
765
|
+
set(a, d, y, h) {
|
|
753
766
|
var _;
|
|
754
|
-
const c = P(y, t),
|
|
755
|
-
return
|
|
756
|
-
[s(h), s(
|
|
757
|
-
(
|
|
758
|
-
const [w, k] = E(n,
|
|
759
|
-
k ? w.consume((O) => n.setProp(O,
|
|
767
|
+
const c = P(y, t), l = (_ = i == null ? void 0 : i(h)) != null ? _ : "host";
|
|
768
|
+
return l !== "vm" && !Reflect.set(a, d, c) || l === "host" || !n.alive || H(
|
|
769
|
+
[s(h), s(d), s(c)],
|
|
770
|
+
(b, v, j) => {
|
|
771
|
+
const [w, k] = E(n, b, r);
|
|
772
|
+
k ? w.consume((O) => n.setProp(O, v, j)) : n.setProp(w, v, j);
|
|
760
773
|
}
|
|
761
774
|
), !0;
|
|
762
775
|
},
|
|
763
|
-
deleteProperty(
|
|
776
|
+
deleteProperty(a, d) {
|
|
764
777
|
var h;
|
|
765
|
-
const y = (h = i == null ? void 0 : i(
|
|
766
|
-
return
|
|
767
|
-
const [_,
|
|
768
|
-
if (y === "vm" || Reflect.deleteProperty(
|
|
778
|
+
const y = (h = i == null ? void 0 : i(u)) != null ? h : "host";
|
|
779
|
+
return H([s(u), s(d)], (c, l) => {
|
|
780
|
+
const [_, b] = E(n, c, r);
|
|
781
|
+
if (y === "vm" || Reflect.deleteProperty(a, d)) {
|
|
769
782
|
if (y === "host" || !n.alive) return !0;
|
|
770
|
-
|
|
783
|
+
b ? _.consume((v) => m(n, "(a, b) => delete a[b]", void 0, v, l)) : m(n, "(a, b) => delete a[b]", void 0, _, l);
|
|
771
784
|
}
|
|
772
785
|
return !0;
|
|
773
786
|
});
|
|
774
787
|
},
|
|
775
|
-
defineProperty(
|
|
776
|
-
var
|
|
777
|
-
const h = (
|
|
778
|
-
return "value" in c && (c.value = P(c.value, t)), typeof c.get == "function" && (c.get = P(c.get, t)), typeof c.set == "function" && (c.set = P(c.set, t)), h !== "vm" && !Reflect.defineProperty(
|
|
779
|
-
[s(
|
|
780
|
-
(_,
|
|
788
|
+
defineProperty(a, d, y) {
|
|
789
|
+
var l;
|
|
790
|
+
const h = (l = i == null ? void 0 : i(u)) != null ? l : "host", c = F({}, y);
|
|
791
|
+
return "value" in c && (c.value = P(c.value, t)), typeof c.get == "function" && (c.get = P(c.get, t)), typeof c.set == "function" && (c.set = P(c.set, t)), h !== "vm" && !Reflect.defineProperty(a, d, c) ? !1 : (h === "host" || !n.alive || H(
|
|
792
|
+
[s(u), s(d), s(c)],
|
|
793
|
+
(_, b, v) => {
|
|
781
794
|
const [j, w] = E(n, _, r), k = (O) => m(
|
|
782
795
|
n,
|
|
783
796
|
"(o, k, d) => { Object.defineProperty(o, k, d); }",
|
|
784
797
|
void 0,
|
|
785
798
|
O,
|
|
786
|
-
|
|
787
|
-
|
|
799
|
+
b,
|
|
800
|
+
v
|
|
788
801
|
).dispose();
|
|
789
802
|
w ? j.consume(k) : k(j);
|
|
790
803
|
}
|
|
791
804
|
), !0);
|
|
792
805
|
}
|
|
793
806
|
});
|
|
794
|
-
return
|
|
807
|
+
return u;
|
|
795
808
|
}
|
|
796
809
|
function Ce(n, e, t, r, s, i, o, f = !0) {
|
|
797
810
|
if (!ee(n, e) || o && !o(e, n))
|
|
798
811
|
return [void 0, !1];
|
|
799
812
|
if (W(n, e, r)) return [e, !1];
|
|
800
813
|
if (!f) return [e, !1];
|
|
801
|
-
const
|
|
802
|
-
const
|
|
803
|
-
return typeof
|
|
804
|
-
},
|
|
805
|
-
const
|
|
806
|
-
if (!
|
|
807
|
-
const
|
|
808
|
-
if (
|
|
814
|
+
const u = (c) => {
|
|
815
|
+
const l = i == null ? void 0 : i(s(c));
|
|
816
|
+
return typeof l == "string" ? n.newString(l) : n.undefined;
|
|
817
|
+
}, a = (c, l, _) => {
|
|
818
|
+
const b = s(c);
|
|
819
|
+
if (!b) return;
|
|
820
|
+
const v = s(l);
|
|
821
|
+
if (v === "__proto__") return;
|
|
809
822
|
const j = s(_);
|
|
810
|
-
P(
|
|
811
|
-
},
|
|
823
|
+
P(b, t)[v] = j;
|
|
824
|
+
}, d = (c, l) => {
|
|
812
825
|
const _ = s(c);
|
|
813
826
|
if (!_) return;
|
|
814
|
-
const
|
|
815
|
-
Reflect.deleteProperty(P(_, t),
|
|
816
|
-
}, y = (c,
|
|
817
|
-
const
|
|
818
|
-
if (!
|
|
819
|
-
const
|
|
820
|
-
if (
|
|
827
|
+
const b = s(l);
|
|
828
|
+
Reflect.deleteProperty(P(_, t), b);
|
|
829
|
+
}, y = (c, l, _) => {
|
|
830
|
+
const b = s(c);
|
|
831
|
+
if (!b) return;
|
|
832
|
+
const v = s(l);
|
|
833
|
+
if (v === "__proto__") return;
|
|
821
834
|
const j = s(_);
|
|
822
|
-
Object.defineProperty(P(
|
|
823
|
-
}, h = n.newFunction("proxyFuncs", (c, ...
|
|
835
|
+
Object.defineProperty(P(b, t), v, j);
|
|
836
|
+
}, h = n.newFunction("proxyFuncs", (c, ...l) => {
|
|
824
837
|
switch (n.getNumber(c)) {
|
|
825
838
|
case 1:
|
|
826
|
-
return
|
|
839
|
+
return u(l[0]);
|
|
827
840
|
case 2:
|
|
828
|
-
return
|
|
841
|
+
return a(l[0], l[1], l[2]);
|
|
829
842
|
case 3:
|
|
830
|
-
return
|
|
843
|
+
return d(l[0], l[1]);
|
|
831
844
|
case 4:
|
|
832
|
-
return y(
|
|
845
|
+
return y(l[0], l[1], l[2]);
|
|
833
846
|
}
|
|
834
847
|
return n.undefined;
|
|
835
848
|
});
|
|
@@ -908,10 +921,10 @@ function W(n, e, t) {
|
|
|
908
921
|
class Fe {
|
|
909
922
|
/** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
|
|
910
923
|
constructor(e, t) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
924
|
+
p(this, "context");
|
|
925
|
+
p(this, "_map");
|
|
926
|
+
p(this, "_registeredMap");
|
|
927
|
+
p(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
|
|
915
928
|
// Handles with no owner: "json" copies and BigInt values. Unlike
|
|
916
929
|
// proxy-marshalled objects they are not identity-tracked in `_map`. A nested
|
|
917
930
|
// one is disposed by its parent consumer via `_disposeTransient` as soon as
|
|
@@ -919,32 +932,32 @@ class Fe {
|
|
|
919
932
|
// were never nested (e.g. a top-level value before its caller consumes it) on
|
|
920
933
|
// dispose. Top-level handles are removed in `_marshal` since their caller
|
|
921
934
|
// disposes them via `mayConsume`.
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
935
|
+
p(this, "_transientHandles", /* @__PURE__ */ new Set());
|
|
936
|
+
p(this, "_sync", /* @__PURE__ */ new Set());
|
|
937
|
+
p(this, "_temporalSync", /* @__PURE__ */ new Set());
|
|
938
|
+
p(this, "_symbol", /* @__PURE__ */ Symbol());
|
|
939
|
+
p(this, "_symbolHandle");
|
|
940
|
+
p(this, "_options");
|
|
941
|
+
p(this, "_isMarshalable", (e) => {
|
|
929
942
|
var r, s;
|
|
930
943
|
const t = (r = this._options) == null ? void 0 : r.isMarshalable;
|
|
931
944
|
return (s = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? s : "json";
|
|
932
945
|
});
|
|
933
|
-
|
|
946
|
+
p(this, "_marshalByReference", (e) => {
|
|
934
947
|
var t, r;
|
|
935
948
|
return !!((r = (t = this._options) == null ? void 0 : t.marshalByReference) != null && r.call(t, this._unwrap(e)));
|
|
936
949
|
});
|
|
937
950
|
// Register an opaque HostRef handle by its host value without wrapping it.
|
|
938
|
-
|
|
951
|
+
p(this, "_registerHostRef", (e, t) => {
|
|
939
952
|
const r = this._unwrap(e), s = this._map.get(r);
|
|
940
953
|
return s || (this._map.set(r, t), t);
|
|
941
954
|
});
|
|
942
|
-
|
|
955
|
+
p(this, "_marshalFind", (e) => {
|
|
943
956
|
var s, i, o;
|
|
944
957
|
const t = this._unwrap(e);
|
|
945
958
|
return (o = (i = (s = this._registeredMap.get(e)) != null ? s : t !== e ? this._registeredMap.get(t) : void 0) != null ? i : this._map.get(e)) != null ? o : t !== e ? this._map.get(t) : void 0;
|
|
946
959
|
});
|
|
947
|
-
|
|
960
|
+
p(this, "_marshalPre", (e, t, r) => {
|
|
948
961
|
if (r === "json") {
|
|
949
962
|
this._registerTransient(C(t));
|
|
950
963
|
return;
|
|
@@ -953,13 +966,13 @@ class Fe {
|
|
|
953
966
|
if (s) return s[1];
|
|
954
967
|
this._registeredMap.has(e) || this._registerTransient(C(t));
|
|
955
968
|
});
|
|
956
|
-
|
|
969
|
+
p(this, "_registerTransient", (e) => {
|
|
957
970
|
this._transientHandles.add(e);
|
|
958
971
|
});
|
|
959
|
-
|
|
972
|
+
p(this, "_disposeTransient", (e) => {
|
|
960
973
|
this._transientHandles.delete(e) && e.alive && e.dispose();
|
|
961
974
|
});
|
|
962
|
-
|
|
975
|
+
p(this, "_marshalPreApply", (e, t, r) => {
|
|
963
976
|
const s = S(t) ? this._unwrap(t) : void 0;
|
|
964
977
|
s && this._temporalSync.add(s);
|
|
965
978
|
try {
|
|
@@ -968,8 +981,8 @@ class Fe {
|
|
|
968
981
|
s && this._temporalSync.delete(s);
|
|
969
982
|
}
|
|
970
983
|
});
|
|
971
|
-
|
|
972
|
-
var o, f,
|
|
984
|
+
p(this, "_marshal", (e) => {
|
|
985
|
+
var o, f, u, a;
|
|
973
986
|
const t = this._registeredMap.get(e);
|
|
974
987
|
if (t)
|
|
975
988
|
return [t, !1];
|
|
@@ -984,21 +997,26 @@ class Fe {
|
|
|
984
997
|
registerTransient: this._registerTransient,
|
|
985
998
|
disposeTransient: this._disposeTransient,
|
|
986
999
|
preApply: this._marshalPreApply,
|
|
1000
|
+
prepareReturn: this._prepareMarshalReturn,
|
|
987
1001
|
custom: (f = this._options) == null ? void 0 : f.customMarshaller
|
|
988
1002
|
});
|
|
989
1003
|
this._transientHandles.delete(s);
|
|
990
|
-
const i = (
|
|
1004
|
+
const i = (a = (u = this._options) == null ? void 0 : u.syncEnabled) != null ? a : !0;
|
|
991
1005
|
return [s, !i || !this._map.hasHandle(s)];
|
|
992
1006
|
});
|
|
993
|
-
|
|
1007
|
+
p(this, "_prepareMarshalReturn", (e) => {
|
|
1008
|
+
var r, s;
|
|
1009
|
+
return ((s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0) && e.alive && this._map.hasHandle(e) ? e.dup() : e;
|
|
1010
|
+
});
|
|
1011
|
+
p(this, "_preUnmarshal", (e, t) => {
|
|
994
1012
|
var r, s, i;
|
|
995
1013
|
return (i = this._register(e, t, void 0, (s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0)) == null ? void 0 : i[0];
|
|
996
1014
|
});
|
|
997
|
-
|
|
1015
|
+
p(this, "_unmarshalFind", (e) => {
|
|
998
1016
|
var t;
|
|
999
1017
|
return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
|
|
1000
1018
|
});
|
|
1001
|
-
|
|
1019
|
+
p(this, "_unmarshal", (e) => {
|
|
1002
1020
|
var s, i, o;
|
|
1003
1021
|
const t = this._registeredMap.getByHandle(e);
|
|
1004
1022
|
if (typeof t != "undefined")
|
|
@@ -1017,11 +1035,11 @@ class Fe {
|
|
|
1017
1035
|
hostRef: !!((o = this._options) != null && o.marshalByReference)
|
|
1018
1036
|
});
|
|
1019
1037
|
});
|
|
1020
|
-
|
|
1038
|
+
p(this, "_syncMode", (e) => {
|
|
1021
1039
|
const t = this._unwrap(e);
|
|
1022
1040
|
return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
|
|
1023
1041
|
});
|
|
1024
|
-
|
|
1042
|
+
p(this, "_unwrapIfNotSynced", (e) => {
|
|
1025
1043
|
const t = this._unwrap(e);
|
|
1026
1044
|
return t instanceof Promise || !this._sync.has(t) ? t : e;
|
|
1027
1045
|
});
|
|
@@ -1259,10 +1277,10 @@ class Fe {
|
|
|
1259
1277
|
const [o] = this._wrapHandle(t), f = e instanceof Promise;
|
|
1260
1278
|
if (!o || !i && !f) return;
|
|
1261
1279
|
f && (i = e);
|
|
1262
|
-
const
|
|
1263
|
-
if (r.set(i, o,
|
|
1264
|
-
s && this._sync.add(
|
|
1265
|
-
else throw
|
|
1280
|
+
const u = this._unwrap(e), [a, d] = this._unwrapHandle(t);
|
|
1281
|
+
if (r.set(i, o, u, a))
|
|
1282
|
+
s && this._sync.add(u);
|
|
1283
|
+
else throw d && a.dispose(), new Error("already registered");
|
|
1266
1284
|
return [i, o];
|
|
1267
1285
|
}
|
|
1268
1286
|
_wrap(e) {
|
|
@@ -1301,7 +1319,7 @@ class Fe {
|
|
|
1301
1319
|
class Ne extends Fe {
|
|
1302
1320
|
constructor(t, r) {
|
|
1303
1321
|
super(t, r);
|
|
1304
|
-
|
|
1322
|
+
p(this, "asyncContext");
|
|
1305
1323
|
this.asyncContext = t;
|
|
1306
1324
|
}
|
|
1307
1325
|
/**
|