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.
@@ -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 l = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
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 = (a) => {
14
+ var i = (u) => {
15
15
  try {
16
- f(t.next(a));
17
- } catch (u) {
18
- s(u);
16
+ f(t.next(u));
17
+ } catch (a) {
18
+ s(a);
19
19
  }
20
- }, o = (a) => {
20
+ }, o = (u) => {
21
21
  try {
22
- f(t.throw(a));
23
- } catch (u) {
24
- s(u);
22
+ f(t.throw(u));
23
+ } catch (a) {
24
+ s(a);
25
25
  }
26
- }, f = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(i, o);
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
- 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());
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
- l(this, "newFunction", (e, t) => {
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 T(n, e) {
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 = T(n, n.evalCode(e)), r = (i, ...o) => T(n, n.callFunction(t, i != null ? i : n.undefined, ...o)), s = () => t.dispose();
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 H = /* @__PURE__ */ new WeakMap();
135
+ const T = /* @__PURE__ */ new WeakMap();
136
136
  function Y(n) {
137
- H.has(n) || H.set(n, /* @__PURE__ */ new Map());
137
+ T.has(n) || T.set(n, /* @__PURE__ */ new Map());
138
138
  }
139
139
  function Z(n) {
140
- const e = H.get(n);
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
- H.delete(n);
144
+ T.delete(n);
145
145
  }
146
146
  }
147
147
  function m(n, e, t, ...r) {
148
- const s = H.get(n);
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 = T(n, n.evalCode(e)), s.set(e, i)), T(n, n.callFunction(i, t != null ? t : n.undefined, ...r));
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 R(n, e) {
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 = (a, u) => {
279
- const p = r(a), y = typeof u.value == "undefined" ? void 0 : r(u.value), h = typeof u.get == "undefined" ? void 0 : r(u.get), c = typeof u.set == "undefined" ? void 0 : r(u.set);
280
- y && o.push(y), h && o.push(h), c && o.push(c), n.newObject().consume((d) => {
281
- Object.entries(u).forEach(([_, v]) => {
282
- const b = _ === "value" ? y : _ === "get" ? h : _ === "set" ? c : v ? n.true : n.false;
283
- b && n.setProp(d, _, b);
284
- }), n.setProp(i, p, d);
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 a = Object.getOwnPropertyDescriptors(e);
289
- Object.entries(a).forEach(([u, p]) => f(u, p)), Object.getOwnPropertySymbols(a).forEach((u) => f(u, a[u])), m(n, "Object.defineProperties", void 0, t, i).dispose();
290
- for (const u of o) s(u);
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 u;
296
+ }, f = (u) => u) {
297
+ var d;
298
298
  if (typeof e != "function") return;
299
- const f = n.newFunction(e.name, function(...p) {
300
- const y = r(this), h = p.map((c) => r(c));
301
- if (ce(e) && S(y)) {
302
- const c = new e(...h);
303
- return Object.entries(c).forEach(([d, _]) => {
304
- const v = t(_);
305
- n.setProp(this, d, v), o(v);
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 t(i ? i(e, y, h) : e.apply(y, h));
308
+ return f(
309
+ t(
310
+ i ? i(e, h, c) : e.apply(h, c)
311
+ )
312
+ );
309
313
  }).consume(
310
- (p) => (
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
- p
325
+ y
322
326
  )
323
327
  )
324
- ), a = (u = s(e, f)) != null ? u : f;
325
- return D(n, e, f, t, o), a;
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()"), a = (i = r(e, f)) != null ? i : f;
341
- for (const [u, p] of e) {
342
- const y = t(u), h = t(p);
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 a;
349
+ return u;
346
350
  }
347
351
  if (e instanceof Set) {
348
- const f = m(n, "() => new Set()"), a = (o = r(e, f)) != null ? o : f;
349
- for (const u of e) {
350
- const p = t(u);
351
- m(n, "(s, v) => s.add(v)", void 0, f, p).dispose(), s(p);
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 a;
357
+ return u;
354
358
  }
355
359
  }
356
360
  function me(n, e, t, r, s = () => {
357
361
  }) {
358
- var u;
362
+ var a;
359
363
  if (typeof e != "object" || e === null) return;
360
- const i = Array.isArray(e) ? n.newArray() : n.newObject(), o = (u = r(e, i)) != null ? u : i, f = Object.getPrototypeOf(e), a = f && f !== Object.prototype && f !== Array.prototype ? t(f) : void 0;
361
- return a && (m(n, "Object.setPrototypeOf", void 0, o, a).dispose(), s(a)), D(n, e, i, t, s), o;
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, d, _, v, b, j;
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 a = (w, k) => o(w, k, f);
411
+ const u = (w, k) => o(w, k, f);
408
412
  if (f === "json")
409
- return ye(t, n, a);
410
- const u = (w) => U(w, e), p = e.disposeTransient;
411
- return (j = (b = (v = (_ = (d = ie(t, n, a, [...fe, ...(c = e.custom) != null ? c : []])) != null ? d : ve(t, n, u, a)) != null ? _ : le(t, n, u, r, a, e.preApply, p)) != null ? v : he(t, n, u, a, p)) != null ? b : me(t, n, u, a, p)) != null ? j : t.undefined;
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((a, [u, p]) => {
465
- const y = n.getProp(i, u), h = n.typeof(y);
466
- if (h === "undefined") return a;
467
- if (!p && h === "boolean")
468
- return a[u] = n.dump(n.getProp(i, u)), a;
469
- const [c, d] = r(y);
470
- return d && y.dispose(), a[u] = c, a;
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(...a) {
493
- return R(
494
- [t(this), ...a.map((u) => t(u))],
495
- (u, ...p) => {
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 [d] = r(
498
- m(n, "(Cls, ...args) => new Cls(...args)", u, e, ...p)
510
+ const [l] = r(
511
+ m(n, "(Cls, ...args) => new Cls(...args)", a, e, ...d)
499
512
  );
500
- return Object.defineProperties(this, Object.getOwnPropertyDescriptors(d)), this;
513
+ return Object.defineProperties(this, Object.getOwnPropertyDescriptors(l)), this;
501
514
  }
502
- const y = T(n, n.callFunction(e, u, ...p)), [h, c] = r(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), (a) => n.dump(a)), i = !s && g(m(n, "a => a instanceof Set", void 0, e), (a) => n.dump(a));
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 a of f) {
526
- const u = n.unwrapResult(a);
538
+ for (const u of f) {
539
+ const a = n.unwrapResult(u);
527
540
  if (s) {
528
- const p = n.getProp(u, 0), y = n.getProp(u, 1), [h, c] = t(p), [d, _] = t(y);
529
- c && p.dispose(), _ && y.dispose(), o.set(h, d), u.dispose();
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 [p, y] = t(u);
532
- y && u.dispose(), o.add(p);
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 Te(n, e, t, r) {
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), (a) => n.dump(a)) ? [] : {}, i = (f = r(s, e)) != null ? f : s, o = g(
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
- (a) => {
554
- if (n.typeof(a) === "undefined") return;
555
- const [u] = t(a);
556
- return u;
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 He(n, e) {
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 Re(n, e, t, r) {
566
- var u;
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, a] = t(s.reject);
569
- return m(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, f), o && i.dispose(), a && f.dispose(), (u = r(s.promise, e)) != null ? u : s.promise;
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 p, y, h;
592
+ var d, y, h;
580
593
  const { ctx: t, marshal: r, find: s, pre: i } = e;
581
594
  {
582
- const [c, d] = He(t, n);
583
- if (d) return [c, !1];
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, ...(p = e.custom) != null ? p : []]);
608
+ const f = be(t, n, i, [...Pe, ...(d = e.custom) != null ? d : []]);
596
609
  if (f) return [f, !0];
597
- const a = ke(t, n, o, i);
598
- return a ? [a, !0] : [(h = (y = Re(t, n, r, i)) != null ? y : Se(t, n, r, o, i)) != null ? h : Te(t, n, o, i), !1];
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
- l(this, "ctx");
603
- l(this, "_keyToId", /* @__PURE__ */ new Map());
604
- l(this, "_key2ToId", /* @__PURE__ */ new Map());
605
- l(this, "_idToHandle", /* @__PURE__ */ new Map());
606
- l(this, "_idToHandle2", /* @__PURE__ */ new Map());
607
- l(this, "_idToKey", /* @__PURE__ */ new Map());
608
- l(this, "_idToKey2", /* @__PURE__ */ new Map());
609
- l(this, "_disposables", /* @__PURE__ */ new Set());
610
- l(this, "_mapGet");
611
- l(this, "_mapSet");
612
- l(this, "_mapDelete");
613
- l(this, "_mapClear");
614
- l(this, "_nextId", Number.MIN_SAFE_INTEGER);
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((a) => {
652
- this._call(this._mapSet, void 0, t, a, s != null ? s : this.ctx.undefined);
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 a;
686
- const r = (a = this._keyToId.get(e)) != null ? a : this._key2ToId.get(e);
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((u) => !!(u != null && u.alive))
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 T(
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 a = new Proxy(e, {
749
- get(u, p) {
750
- return p === t ? u : Reflect.get(u, p);
761
+ const u = new Proxy(e, {
762
+ get(a, d) {
763
+ return d === t ? a : Reflect.get(a, d);
751
764
  },
752
- set(u, p, y, h) {
765
+ set(a, d, y, h) {
753
766
  var _;
754
- const c = P(y, t), d = (_ = i == null ? void 0 : i(h)) != null ? _ : "host";
755
- return d !== "vm" && !Reflect.set(u, p, c) || d === "host" || !n.alive || R(
756
- [s(h), s(p), s(c)],
757
- (v, b, j) => {
758
- const [w, k] = E(n, v, r);
759
- k ? w.consume((O) => n.setProp(O, b, j)) : n.setProp(w, b, j);
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(u, p) {
776
+ deleteProperty(a, d) {
764
777
  var h;
765
- const y = (h = i == null ? void 0 : i(a)) != null ? h : "host";
766
- return R([s(a), s(p)], (c, d) => {
767
- const [_, v] = E(n, c, r);
768
- if (y === "vm" || Reflect.deleteProperty(u, p)) {
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
- v ? _.consume((b) => m(n, "(a, b) => delete a[b]", void 0, b, d)) : m(n, "(a, b) => delete a[b]", void 0, _, d);
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(u, p, y) {
776
- var d;
777
- const h = (d = i == null ? void 0 : i(a)) != null ? d : "host", c = F({}, y);
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(u, p, c) ? !1 : (h === "host" || !n.alive || R(
779
- [s(a), s(p), s(c)],
780
- (_, v, b) => {
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
- v,
787
- b
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 a;
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 a = (c) => {
802
- const d = i == null ? void 0 : i(s(c));
803
- return typeof d == "string" ? n.newString(d) : n.undefined;
804
- }, u = (c, d, _) => {
805
- const v = s(c);
806
- if (!v) return;
807
- const b = s(d);
808
- if (b === "__proto__") return;
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(v, t)[b] = j;
811
- }, p = (c, d) => {
823
+ P(b, t)[v] = j;
824
+ }, d = (c, l) => {
812
825
  const _ = s(c);
813
826
  if (!_) return;
814
- const v = s(d);
815
- Reflect.deleteProperty(P(_, t), v);
816
- }, y = (c, d, _) => {
817
- const v = s(c);
818
- if (!v) return;
819
- const b = s(d);
820
- if (b === "__proto__") return;
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(v, t), b, j);
823
- }, h = n.newFunction("proxyFuncs", (c, ...d) => {
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 a(d[0]);
839
+ return u(l[0]);
827
840
  case 2:
828
- return u(d[0], d[1], d[2]);
841
+ return a(l[0], l[1], l[2]);
829
842
  case 3:
830
- return p(d[0], d[1]);
843
+ return d(l[0], l[1]);
831
844
  case 4:
832
- return y(d[0], d[1], d[2]);
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
- l(this, "context");
912
- l(this, "_map");
913
- l(this, "_registeredMap");
914
- l(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
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
- l(this, "_transientHandles", /* @__PURE__ */ new Set());
923
- l(this, "_sync", /* @__PURE__ */ new Set());
924
- l(this, "_temporalSync", /* @__PURE__ */ new Set());
925
- l(this, "_symbol", /* @__PURE__ */ Symbol());
926
- l(this, "_symbolHandle");
927
- l(this, "_options");
928
- l(this, "_isMarshalable", (e) => {
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
- l(this, "_marshalByReference", (e) => {
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
- l(this, "_registerHostRef", (e, t) => {
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
- l(this, "_marshalFind", (e) => {
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
- l(this, "_marshalPre", (e, t, r) => {
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
- l(this, "_registerTransient", (e) => {
969
+ p(this, "_registerTransient", (e) => {
957
970
  this._transientHandles.add(e);
958
971
  });
959
- l(this, "_disposeTransient", (e) => {
972
+ p(this, "_disposeTransient", (e) => {
960
973
  this._transientHandles.delete(e) && e.alive && e.dispose();
961
974
  });
962
- l(this, "_marshalPreApply", (e, t, r) => {
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
- l(this, "_marshal", (e) => {
972
- var o, f, a, u;
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 = (u = (a = this._options) == null ? void 0 : a.syncEnabled) != null ? u : !0;
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
- l(this, "_preUnmarshal", (e, t) => {
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
- l(this, "_unmarshalFind", (e) => {
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
- l(this, "_unmarshal", (e) => {
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
- l(this, "_syncMode", (e) => {
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
- l(this, "_unwrapIfNotSynced", (e) => {
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 a = this._unwrap(e), [u, p] = this._unwrapHandle(t);
1263
- if (r.set(i, o, a, u))
1264
- s && this._sync.add(a);
1265
- else throw p && u.dispose(), new Error("already registered");
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
- l(this, "asyncContext");
1322
+ p(this, "asyncContext");
1305
1323
  this.asyncContext = t;
1306
1324
  }
1307
1325
  /**