quickjs-emscripten-sync 1.9.1 → 1.11.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.
@@ -1,115 +1,33 @@
1
- var z = Object.defineProperty;
1
+ var Q = Object.defineProperty, X = Object.defineProperties;
2
+ var Y = Object.getOwnPropertyDescriptors;
2
3
  var B = Object.getOwnPropertySymbols;
3
- var $ = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
4
- var M = (n, e, t) => e in n ? z(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, F = (n, e) => {
4
+ var Z = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
5
+ var M = (n, e, t) => e in n ? Q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, I = (n, e) => {
5
6
  for (var t in e || (e = {}))
6
- $.call(e, t) && M(n, t, e[t]);
7
+ Z.call(e, t) && M(n, t, e[t]);
7
8
  if (B)
8
9
  for (var t of B(e))
9
- L.call(e, t) && M(n, t, e[t]);
10
+ x.call(e, t) && M(n, t, e[t]);
10
11
  return n;
11
- };
12
- var l = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
13
- var A = (n, e, t) => new Promise((r, s) => {
14
- var i = (a) => {
12
+ }, N = (n, e) => X(n, Y(e));
13
+ var d = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
14
+ var F = (n, e, t) => new Promise((r, s) => {
15
+ var i = (u) => {
15
16
  try {
16
- f(t.next(a));
17
- } catch (u) {
18
- s(u);
17
+ a(t.next(u));
18
+ } catch (f) {
19
+ s(f);
19
20
  }
20
- }, o = (a) => {
21
+ }, o = (u) => {
21
22
  try {
22
- f(t.throw(a));
23
- } catch (u) {
24
- s(u);
23
+ a(t.throw(u));
24
+ } catch (f) {
25
+ s(f);
25
26
  }
26
- }, f = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(i, o);
27
- f((t = t.apply(n, e)).next());
27
+ }, a = (u) => u.done ? r(u.value) : Promise.resolve(u.value).then(i, o);
28
+ a((t = t.apply(n, e)).next());
28
29
  });
29
- const K = (n) => {
30
- const e = new q(n);
31
- return new Proxy(n, {
32
- get(t, r, s) {
33
- return r in e ? e[r] : Reflect.get(t, r, s);
34
- }
35
- });
36
- };
37
- class q {
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());
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) => {
46
- this.fnCounter++;
47
- const r = this.fnCounter;
48
- return this.fnMap.set(r, t), this.context.unwrapResult(
49
- this.context.callFunction(
50
- this.fnGenerator,
51
- this.context.undefined,
52
- this.context.newString(e),
53
- this.context.newNumber(t.length),
54
- this.context.newNumber(r),
55
- this.fn
56
- )
57
- );
58
- });
59
- this.context = e;
60
- const t = this.fnMap;
61
- this.fn = this.context.newFunction("", function(r, ...s) {
62
- const i = e.getNumber(r), o = t.get(i);
63
- if (!o) throw new Error("function is not registered");
64
- return o.call(this, ...s);
65
- }), this.fnGenerator = e.unwrapResult(
66
- e.evalCode(`((name, length, id, f) => {
67
- const fn = function(...args) {
68
- return f.call(this, id, ...args);
69
- };
70
- fn.name = name;
71
- fn.length = length;
72
- return fn;
73
- })`)
74
- );
75
- }
76
- disposeEx() {
77
- this.fnGenerator.dispose(), this.fn.dispose();
78
- }
79
- }
80
- const Q = [
81
- // basic objects
82
- [Symbol, "Symbol"],
83
- [Symbol.prototype, "Symbol.prototype"],
84
- [Object, "Object"],
85
- [Object.prototype, "Object.prototype"],
86
- [Function, "Function"],
87
- [Function.prototype, "Function.prototype"],
88
- [Boolean, "Boolean"],
89
- [Boolean.prototype, "Boolean.prototype"],
90
- [Array, "Array"],
91
- [Array.prototype, "Array.prototype"],
92
- // [BigInt, "BigInt"],
93
- // [BigInt.prototype, "BigInt.prototype"],
94
- // errors
95
- [Error, "Error"],
96
- [Error.prototype, "Error.prototype"],
97
- [EvalError, "EvalError"],
98
- [EvalError.prototype, "EvalError.prototype"],
99
- [RangeError, "RangeError"],
100
- [RangeError.prototype, "RangeError.prototype"],
101
- [ReferenceError, "ReferenceError"],
102
- [ReferenceError.prototype, "ReferenceError.prototype"],
103
- [SyntaxError, "SyntaxError"],
104
- [SyntaxError.prototype, "SyntaxError.prototype"],
105
- [TypeError, "TypeError"],
106
- [TypeError.prototype, "TypeError.prototype"],
107
- [URIError, "URIError"],
108
- [URIError.prototype, "URIError.prototype"],
109
- // built-in symbols
110
- ...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
111
- ];
112
- function T(n, e) {
30
+ function R(n, e) {
113
31
  if ("error" in e && e.error) {
114
32
  const { error: t } = e;
115
33
  let r;
@@ -126,28 +44,28 @@ function T(n, e) {
126
44
  }
127
45
  return e.value;
128
46
  }
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();
47
+ function ee(n, e) {
48
+ 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
49
  return r.dispose = s, r[Symbol.dispose] = s, Object.defineProperty(r, "alive", {
132
50
  get: () => t.alive
133
51
  }), r;
134
52
  }
135
- const H = /* @__PURE__ */ new WeakMap();
136
- function Y(n) {
137
- H.has(n) || H.set(n, /* @__PURE__ */ new Map());
53
+ const E = /* @__PURE__ */ new WeakMap();
54
+ function te(n) {
55
+ E.has(n) || E.set(n, /* @__PURE__ */ new Map());
138
56
  }
139
- function Z(n) {
140
- const e = H.get(n);
57
+ function ne(n) {
58
+ const e = E.get(n);
141
59
  if (e) {
142
60
  for (const t of e.values())
143
61
  t.alive && t.dispose();
144
- H.delete(n);
62
+ E.delete(n);
145
63
  }
146
64
  }
147
- function m(n, e, t, ...r) {
148
- const s = H.get(n);
65
+ function b(n, e, t, ...r) {
66
+ const s = E.get(n);
149
67
  if (!s) {
150
- const o = X(n, e);
68
+ const o = ee(n, e);
151
69
  try {
152
70
  return o(t, ...r);
153
71
  } finally {
@@ -155,27 +73,27 @@ function m(n, e, t, ...r) {
155
73
  }
156
74
  }
157
75
  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));
76
+ 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
77
  }
160
- function x(n, e, t) {
161
- return n.dump(m(n, "(a, b) => a instanceof b", void 0, e, t));
78
+ function re(n, e, t) {
79
+ return n.dump(b(n, "(a, b) => a instanceof b", void 0, e, t));
162
80
  }
163
- function ee(n, e) {
81
+ function U(n, e) {
164
82
  const t = n.typeof(e);
165
83
  return t === "function" || t === "object" && !n.sameValue(e, n.null);
166
84
  }
167
- function te(n, e) {
85
+ function se(n, e) {
168
86
  const t = JSON.stringify(e);
169
- return t ? n.newString(t).consume((r) => m(n, "JSON.parse", void 0, r)) : n.undefined;
87
+ return t ? n.newString(t).consume((r) => b(n, "JSON.parse", void 0, r)) : n.undefined;
170
88
  }
171
- function g(n, e) {
89
+ function j(n, e) {
172
90
  try {
173
91
  return e(n);
174
92
  } finally {
175
93
  n.alive && n.dispose();
176
94
  }
177
95
  }
178
- function ne(n, e) {
96
+ function V(n, e) {
179
97
  try {
180
98
  return e(n);
181
99
  } finally {
@@ -183,14 +101,14 @@ function ne(n, e) {
183
101
  t.alive && t.dispose();
184
102
  }
185
103
  }
186
- function re([n, e], t) {
104
+ function ie([n, e], t) {
187
105
  try {
188
106
  return t(n);
189
107
  } finally {
190
108
  e && n.dispose();
191
109
  }
192
110
  }
193
- function R(n, e) {
111
+ function O(n, e) {
194
112
  try {
195
113
  return e(...n.map((t) => t[0]));
196
114
  } finally {
@@ -198,51 +116,145 @@ function R(n, e) {
198
116
  r && t.dispose();
199
117
  }
200
118
  }
201
- function se(n) {
119
+ function oe(n) {
202
120
  return "handle" in n;
203
121
  }
204
122
  function C(n) {
205
- return se(n) ? n.handle : n;
123
+ return oe(n) ? n.handle : n;
206
124
  }
207
- function ie(n, e, t, r) {
208
- var i;
125
+ const ae = (n) => {
126
+ const e = new ue(n);
127
+ return new Proxy(n, {
128
+ get(t, r, s) {
129
+ return r in e ? e[r] : Reflect.get(t, r, s);
130
+ }
131
+ });
132
+ };
133
+ class ue {
134
+ constructor(e) {
135
+ d(this, "context");
136
+ d(this, "fn");
137
+ d(this, "fnGenerator");
138
+ d(this, "fnCounter", Number.MIN_SAFE_INTEGER);
139
+ d(this, "fnMap", /* @__PURE__ */ new Map());
140
+ /** Similar to the original newFunction, but no matter how many new functions are generated, newFunction is called only once. */
141
+ d(this, "newFunction", (e, t) => {
142
+ this.fnCounter++;
143
+ const r = this.fnCounter;
144
+ return this.fnMap.set(r, t), V(
145
+ [
146
+ this.context.newString(e),
147
+ this.context.newNumber(t.length),
148
+ this.context.newNumber(r)
149
+ ],
150
+ ([s, i, o]) => this.context.unwrapResult(
151
+ this.context.callFunction(
152
+ this.fnGenerator,
153
+ this.context.undefined,
154
+ s,
155
+ i,
156
+ o,
157
+ this.fn
158
+ )
159
+ )
160
+ );
161
+ });
162
+ this.context = e;
163
+ const t = this.fnMap;
164
+ this.fn = this.context.newFunction("", function(r, ...s) {
165
+ const i = e.getNumber(r), o = t.get(i);
166
+ if (!o) throw new Error("function is not registered");
167
+ return o.call(this, ...s);
168
+ }), this.fnGenerator = e.unwrapResult(
169
+ e.evalCode(`((name, length, id, f) => {
170
+ const fn = function(...args) {
171
+ return f.call(this, id, ...args);
172
+ };
173
+ fn.name = name;
174
+ fn.length = length;
175
+ return fn;
176
+ })`)
177
+ );
178
+ }
179
+ disposeEx() {
180
+ this.fnGenerator.dispose(), this.fn.dispose();
181
+ }
182
+ }
183
+ const fe = [
184
+ // basic objects
185
+ [Symbol, "Symbol"],
186
+ [Symbol.prototype, "Symbol.prototype"],
187
+ [Object, "Object"],
188
+ [Object.prototype, "Object.prototype"],
189
+ [Function, "Function"],
190
+ [Function.prototype, "Function.prototype"],
191
+ [Boolean, "Boolean"],
192
+ [Boolean.prototype, "Boolean.prototype"],
193
+ [Array, "Array"],
194
+ [Array.prototype, "Array.prototype"],
195
+ // [BigInt, "BigInt"],
196
+ // [BigInt.prototype, "BigInt.prototype"],
197
+ // errors
198
+ [Error, "Error"],
199
+ [Error.prototype, "Error.prototype"],
200
+ [EvalError, "EvalError"],
201
+ [EvalError.prototype, "EvalError.prototype"],
202
+ [RangeError, "RangeError"],
203
+ [RangeError.prototype, "RangeError.prototype"],
204
+ [ReferenceError, "ReferenceError"],
205
+ [ReferenceError.prototype, "ReferenceError.prototype"],
206
+ [SyntaxError, "SyntaxError"],
207
+ [SyntaxError.prototype, "SyntaxError.prototype"],
208
+ [TypeError, "TypeError"],
209
+ [TypeError.prototype, "TypeError.prototype"],
210
+ [URIError, "URIError"],
211
+ [URIError.prototype, "URIError.prototype"],
212
+ // built-in symbols
213
+ ...Object.getOwnPropertyNames(Symbol).filter((n) => typeof Symbol[n] == "symbol").map((n) => [Symbol[n], `Symbol.${n}`])
214
+ ];
215
+ function le(n, e, t, r) {
216
+ var o;
209
217
  let s;
210
- for (const o of r)
211
- if (s = o(e, n), s) break;
212
- return s ? (i = t(e, s)) != null ? i : s : void 0;
218
+ for (const a of r)
219
+ if (s = a(e, n), s) break;
220
+ if (!s) return;
221
+ let i = !0;
222
+ try {
223
+ const a = (o = t(e, s)) != null ? o : s;
224
+ return i = !1, a;
225
+ } finally {
226
+ i && s.alive && s.dispose();
227
+ }
213
228
  }
214
- function oe(n, e) {
215
- return typeof n != "symbol" ? void 0 : m(
216
- e,
217
- "d => Symbol(d)",
218
- void 0,
219
- n.description ? e.newString(n.description) : e.undefined
220
- );
229
+ function ce(n, e) {
230
+ if (typeof n == "symbol")
231
+ return n.description ? j(e.newString(n.description), (t) => b(e, "d => Symbol(d)", void 0, t)) : b(e, "d => Symbol(d)", void 0, e.undefined);
221
232
  }
222
- function ue(n, e) {
223
- return n instanceof Date ? m(e, "d => new Date(d)", void 0, e.newNumber(n.getTime())) : void 0;
233
+ function pe(n, e) {
234
+ if (n instanceof Date)
235
+ return j(e.newNumber(n.getTime()), (t) => b(e, "d => new Date(d)", void 0, t));
224
236
  }
225
- function ae(n, e) {
237
+ function de(n, e) {
226
238
  if (n instanceof ArrayBuffer)
227
239
  return e.newArrayBuffer(n.slice(0));
228
240
  if (ArrayBuffer.isView(n)) {
229
241
  const t = new Uint8Array(n.buffer, n.byteOffset, n.byteLength).slice();
230
- return ne(
242
+ return V(
231
243
  [e.newArrayBuffer(t.buffer), e.newString(n.constructor.name)],
232
- ([r, s]) => m(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
244
+ ([r, s]) => b(e, "(buf, name) => new globalThis[name](buf)", void 0, r, s)
233
245
  );
234
246
  }
235
247
  }
236
- const fe = [oe, ue, ae];
237
- function ce(n) {
248
+ const ye = [ce, pe, de];
249
+ function he(n) {
238
250
  return typeof n == "function" && /^class\s/.test(Function.prototype.toString.call(n));
239
251
  }
240
- function S(n) {
252
+ function P(n) {
241
253
  return typeof n == "function" || typeof n == "object" && n !== null;
242
254
  }
243
- function N(n, e) {
255
+ function G(n, e) {
244
256
  const t = /* @__PURE__ */ new Set(), r = (s) => {
245
- if (!(!S(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
257
+ if (!(!P(s) || t.has(s) || (e == null ? void 0 : e(s, t)) === !1)) {
246
258
  if (t.add(s), Array.isArray(s)) {
247
259
  for (const i of s)
248
260
  r(i);
@@ -258,10 +270,10 @@ function N(n, e) {
258
270
  };
259
271
  return r(n), t;
260
272
  }
261
- function Ie(n, e) {
262
- return N(n, e ? (t, r) => r.size < e : void 0).size;
273
+ function Ge(n, e) {
274
+ return G(n, e ? (t, r) => r.size < e : void 0).size;
263
275
  }
264
- function pe() {
276
+ function me() {
265
277
  let n = () => {
266
278
  }, e = () => {
267
279
  };
@@ -273,94 +285,148 @@ function pe() {
273
285
  reject: e
274
286
  };
275
287
  }
276
- function D(n, e, t, r, s = () => {
288
+ function J(n, e, t, r, s = () => {
277
289
  }) {
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);
290
+ let i;
291
+ const o = [], a = Object.getPrototypeOf(e), u = a === Object.prototype || a === Array.prototype, f = (l, c) => {
292
+ if (u && typeof l == "string" && l !== "__proto__" && c.writable === !0 && c.enumerable === !0 && c.configurable === !0 && c.get === void 0 && c.set === void 0) {
293
+ const _ = r(l), w = r(c.value);
294
+ n.setProp(t, _, w), s(w);
295
+ return;
296
+ }
297
+ const m = r(l), p = typeof c.value == "undefined" ? void 0 : r(c.value), y = typeof c.get == "undefined" ? void 0 : r(c.get), h = typeof c.set == "undefined" ? void 0 : r(c.set);
298
+ p && o.push(p), y && o.push(y), h && o.push(h);
299
+ const g = i != null ? i : i = n.newObject();
300
+ j(n.newObject(), (_) => {
301
+ Object.entries(c).forEach(([w, v]) => {
302
+ const H = w === "value" ? p : w === "get" ? y : w === "set" ? h : v ? n.true : n.false;
303
+ H && n.setProp(_, w, H);
304
+ }), n.setProp(g, m, _);
285
305
  });
286
306
  };
287
307
  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);
308
+ const l = Object.getOwnPropertyDescriptors(e);
309
+ if (Object.entries(l).forEach(([c, m]) => f(c, m)), Object.getOwnPropertySymbols(l).forEach((c) => f(c, l[c])), i) {
310
+ b(n, "Object.defineProperties", void 0, t, i).dispose();
311
+ for (const c of o) s(c);
312
+ }
291
313
  } finally {
292
- i.dispose();
314
+ i == null || i.dispose();
293
315
  }
294
316
  }
295
- function le(n, e, t, r, s, i, o = () => {
296
- }) {
297
- var u;
317
+ function _e(n, e, t, r, s, i, o = () => {
318
+ }, a = (l) => l, u = (l) => l, f) {
319
+ var g;
298
320
  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);
321
+ const l = u(e), c = he(l), p = !!f && f(l) && "newAsyncifiedFunction" in n ? (
322
+ // Asyncify: the VM stack is suspended until the host promise settles, so
323
+ // the guest receives the resolved value synchronously. Async functions
324
+ // can never be class constructors, so the class-constructor path is
325
+ // skipped here.
326
+ n.newAsyncifiedFunction(e.name, function(..._) {
327
+ return F(this, null, function* () {
328
+ const w = n.sameValue(this, n.global) ? void 0 : r(this), v = _.map((k) => r(k)), H = yield i ? i(e, w, v) : e.apply(w, v);
329
+ return a(t(H));
330
+ });
331
+ })
332
+ ) : n.newFunction(e.name, function(..._) {
333
+ const w = n.sameValue(this, n.global) ? void 0 : r(this), v = _.map((H) => r(H));
334
+ if (c && P(w)) {
335
+ const H = new e(...v);
336
+ return Object.entries(H).forEach(([k, q]) => {
337
+ const A = t(q);
338
+ n.setProp(this, k, A), o(A);
306
339
  }), this;
307
340
  }
308
- return t(i ? i(e, y, h) : e.apply(y, h));
309
- }).consume(
310
- (p) => (
311
- // fucntions created by vm.newFunction are not callable as a class constrcutor
312
- m(
341
+ return a(
342
+ t(
343
+ i ? i(e, w, v) : e.apply(w, v)
344
+ )
345
+ );
346
+ }), y = j(
347
+ p,
348
+ (_) => (
349
+ // functions created by vm.newFunction are not callable as a class constructor
350
+ b(
313
351
  n,
314
352
  `Cls => {
315
- const fn = function(...args) { return Cls.apply(this, args); };
316
- fn.name = Cls.name;
317
- fn.length = Cls.length;
318
- return fn;
319
- }`,
353
+ const fn = function(...args) { return Cls.apply(this, args); };
354
+ fn.name = Cls.name;
355
+ fn.length = Cls.length;
356
+ return fn;
357
+ }`,
320
358
  void 0,
321
- p
359
+ _
322
360
  )
323
361
  )
324
- ), a = (u = s(e, f)) != null ? u : f;
325
- return D(n, e, f, t, o), a;
362
+ );
363
+ let h = !0;
364
+ try {
365
+ const _ = (g = s(e, y)) != null ? g : y;
366
+ return h = !1, J(n, e, y, t, o), _;
367
+ } finally {
368
+ h && y.alive && y.dispose();
369
+ }
326
370
  }
327
- function de(n, e, t) {
371
+ function ve(n, e, t) {
328
372
  if (!(typeof e != "object" && typeof e != "function") && e !== null)
329
373
  return t(e, n.newHostRef(e).handle);
330
374
  }
331
- function ye(n, e, t) {
375
+ function be(n, e, t) {
332
376
  var i;
333
- const r = te(n, e);
377
+ const r = se(n, e);
334
378
  return (i = t(e, r)) != null ? i : r;
335
379
  }
336
- function he(n, e, t, r, s = () => {
380
+ function we(n, e, t, r, s = () => {
337
381
  }) {
338
382
  var i, o;
339
383
  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);
343
- m(n, "(m, k, v) => m.set(k, v)", void 0, f, y, h).dispose(), s(y), s(h);
384
+ const a = b(n, "() => new Map()");
385
+ let u = !0;
386
+ try {
387
+ const f = (i = r(e, a)) != null ? i : a;
388
+ u = !1;
389
+ for (const [l, c] of e) {
390
+ const m = t(l), p = t(c);
391
+ b(n, "(m, k, v) => m.set(k, v)", void 0, a, m, p).dispose(), s(m), s(p);
392
+ }
393
+ return f;
394
+ } finally {
395
+ u && a.alive && a.dispose();
344
396
  }
345
- return a;
346
397
  }
347
398
  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);
399
+ const a = b(n, "() => new Set()");
400
+ let u = !0;
401
+ try {
402
+ const f = (o = r(e, a)) != null ? o : a;
403
+ u = !1;
404
+ for (const l of e) {
405
+ const c = t(l);
406
+ b(n, "(s, v) => s.add(v)", void 0, a, c).dispose(), s(c);
407
+ }
408
+ return f;
409
+ } finally {
410
+ u && a.alive && a.dispose();
352
411
  }
353
- return a;
354
412
  }
355
413
  }
356
- function me(n, e, t, r, s = () => {
414
+ function ge(n, e, t, r, s = () => {
357
415
  }) {
358
- var u;
416
+ var a;
359
417
  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;
418
+ const i = Array.isArray(e) ? n.newArray() : n.newObject();
419
+ let o = !0;
420
+ try {
421
+ const u = (a = r(e, i)) != null ? a : i;
422
+ o = !1;
423
+ const f = Object.getPrototypeOf(e), l = f && f !== Object.prototype && f !== Array.prototype ? t(f) : void 0;
424
+ return l && (b(n, "Object.setPrototypeOf", void 0, u, l).dispose(), s(l)), J(n, e, i, t, s), u;
425
+ } finally {
426
+ o && i.alive && i.dispose();
427
+ }
362
428
  }
363
- function _e(n, e) {
429
+ function je(n, e) {
364
430
  switch (typeof e) {
365
431
  case "undefined":
366
432
  return n.undefined;
@@ -376,69 +442,87 @@ function _e(n, e) {
376
442
  return e === null ? n.null : void 0;
377
443
  }
378
444
  }
379
- function ve(n, e, t, r) {
380
- var i;
445
+ function He(n, e, t, r) {
446
+ var o;
381
447
  if (!(e instanceof Promise)) return;
382
448
  const s = n.newPromise();
383
- return e.then(
384
- (o) => s.resolve(t(o)),
385
- (o) => s.reject(t(o))
386
- ), (i = r(e, s)) != null ? i : s.handle;
449
+ let i = !0;
450
+ try {
451
+ e.then(
452
+ (u) => s.resolve(t(u)),
453
+ (u) => s.reject(t(u))
454
+ );
455
+ const a = (o = r(e, s)) != null ? o : s.handle;
456
+ return i = !1, a;
457
+ } finally {
458
+ i && s.alive && s.dispose();
459
+ }
387
460
  }
388
- function U(n, e) {
389
- var y, h, c, d, _, v, b, j;
461
+ function W(n, e) {
462
+ var c, m, p, y, h, g, _, w;
390
463
  const { ctx: t, unmarshal: r, isMarshalable: s, find: i, pre: o } = e;
391
464
  {
392
- const w = _e(t, n);
393
- if (w)
394
- return typeof n == "bigint" && ((y = e.registerTransient) == null || y.call(e, w)), w;
465
+ const v = je(t, n);
466
+ if (v)
467
+ return typeof n == "bigint" && ((c = e.registerTransient) == null || c.call(e, v)), v;
395
468
  }
396
469
  {
397
- const w = i(n);
398
- if (w) return w;
470
+ const v = i(n);
471
+ if (v) return v;
399
472
  }
400
- if ((h = e.marshalByReference) != null && h.call(e, n) && e.registerHostRef) {
401
- const w = de(t, n, e.registerHostRef);
402
- if (w) return w;
473
+ if ((m = e.marshalByReference) != null && m.call(e, n) && e.registerHostRef) {
474
+ const v = ve(t, n, e.registerHostRef);
475
+ if (v) return v;
403
476
  }
404
- const f = s == null ? void 0 : s(n);
405
- if (f === !1)
477
+ const a = s == null ? void 0 : s(n);
478
+ if (a === !1)
406
479
  return t.undefined;
407
- const a = (w, k) => o(w, k, f);
408
- 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;
480
+ const u = (v, H) => o(v, H, a);
481
+ if (a === "json")
482
+ return be(t, n, u);
483
+ const f = (v) => W(v, e), l = e.disposeTransient;
484
+ return (w = (_ = (g = (h = (y = le(t, n, u, [...ye, ...(p = e.custom) != null ? p : []])) != null ? y : He(t, n, f, u)) != null ? h : _e(
485
+ t,
486
+ n,
487
+ f,
488
+ r,
489
+ u,
490
+ e.preApply,
491
+ l,
492
+ e.prepareReturn,
493
+ e.unwrap,
494
+ e.asyncify
495
+ )) != null ? g : we(t, n, f, u, l)) != null ? _ : ge(t, n, f, u, l)) != null ? w : t.undefined;
412
496
  }
413
- function be(n, e, t, r) {
497
+ function Se(n, e, t, r) {
414
498
  var i;
415
499
  let s;
416
500
  for (const o of r)
417
501
  if (s = o(e, n), s) break;
418
502
  return s ? (i = t(s, e)) != null ? i : s : void 0;
419
503
  }
420
- function we(n, e) {
504
+ function Pe(n, e) {
421
505
  if (e.typeof(n) !== "symbol") return;
422
506
  const t = e.getString(e.getProp(n, "description"));
423
507
  return Symbol(t);
424
508
  }
425
- function ge(n, e) {
426
- if (!g(m(e, "a => a instanceof Date", void 0, n), (r) => e.dump(r))) return;
427
- const t = g(m(e, "a => a.getTime()", void 0, n), (r) => e.getNumber(r));
509
+ function ke(n, e) {
510
+ if (!j(b(e, "a => a instanceof Date", void 0, n), (r) => e.dump(r))) return;
511
+ const t = j(b(e, "a => a.getTime()", void 0, n), (r) => e.getNumber(r));
428
512
  return new Date(t);
429
513
  }
430
- function je(n, e) {
431
- if (g(m(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
514
+ function Re(n, e) {
515
+ if (j(b(e, "a => a instanceof ArrayBuffer", void 0, n), (t) => e.dump(t))) {
432
516
  const t = e.getArrayBuffer(n), r = t.value.slice();
433
517
  return t.dispose(), r.buffer;
434
518
  }
435
- if (g(m(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
436
- const t = g(
437
- m(e, "a => a.constructor.name", void 0, n),
438
- (f) => e.getString(f)
519
+ if (j(b(e, "a => ArrayBuffer.isView(a)", void 0, n), (t) => e.dump(t))) {
520
+ const t = j(
521
+ b(e, "a => a.constructor.name", void 0, n),
522
+ (a) => e.getString(a)
439
523
  ), r = globalThis[t];
440
524
  if (typeof r != "function") return;
441
- const s = m(
525
+ const s = b(
442
526
  e,
443
527
  "a => a.buffer.slice(a.byteOffset, a.byteOffset + a.byteLength)",
444
528
  void 0,
@@ -447,66 +531,65 @@ function je(n, e) {
447
531
  return i.dispose(), s.dispose(), new r(o.buffer);
448
532
  }
449
533
  }
450
- const Pe = [we, ge, je];
451
- function V(n, e, t, r) {
452
- g(
453
- n.newFunction("", (s, i) => {
454
- const [o] = r(s);
455
- if (typeof o != "string" && typeof o != "number" && typeof o != "symbol")
534
+ const Ee = [Pe, ke, Re], Oe = `(o, fn) => {
535
+ const descs = Object.getOwnPropertyDescriptors(o);
536
+ const emit = (k, d) => {
537
+ let f = 0;
538
+ if (typeof d.value !== "undefined") f |= 1;
539
+ if (typeof d.get !== "undefined") f |= 2;
540
+ if (typeof d.set !== "undefined") f |= 4;
541
+ if (typeof d.configurable === "boolean") { f |= 8; if (d.configurable) f |= 16; }
542
+ if (typeof d.enumerable === "boolean") { f |= 32; if (d.enumerable) f |= 64; }
543
+ if (typeof d.writable === "boolean") { f |= 128; if (d.writable) f |= 256; }
544
+ fn(k, d, f);
545
+ };
546
+ Object.entries(descs).forEach(([k, v]) => emit(k, v));
547
+ Object.getOwnPropertySymbols(descs).forEach(k => emit(k, descs[k]));
548
+ }`;
549
+ function z(n, e, t, r) {
550
+ j(
551
+ n.newFunction("", (s, i, o) => {
552
+ const [a] = r(s);
553
+ if (typeof a != "string" && typeof a != "number" && typeof a != "symbol")
456
554
  return;
457
- const f = [
458
- ["value", !0],
459
- ["get", !0],
460
- ["set", !0],
461
- ["configurable", !1],
462
- ["enumerable", !1],
463
- ["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;
471
- }, {});
472
- Object.defineProperty(t, o, f);
555
+ const u = n.getNumber(o), f = {}, l = (c) => {
556
+ const m = n.getProp(i, c);
557
+ let p = !1;
558
+ try {
559
+ const [y, h] = r(m);
560
+ return p = !h, y;
561
+ } finally {
562
+ !p && m.alive && m.dispose();
563
+ }
564
+ };
565
+ u & 1 && (f.value = l("value")), u & 2 && (f.get = l("get")), u & 4 && (f.set = l("set")), u & 8 && (f.configurable = !!(u & 16)), u & 32 && (f.enumerable = !!(u & 64)), u & 128 && (f.writable = !!(u & 256)), Object.defineProperty(t, a, f);
473
566
  }),
474
567
  (s) => {
475
- m(
476
- n,
477
- `(o, fn) => {
478
- const descs = Object.getOwnPropertyDescriptors(o);
479
- Object.entries(descs).forEach(([k, v]) => fn(k, v));
480
- Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));
481
- }`,
482
- void 0,
483
- e,
484
- s
485
- ).dispose();
568
+ b(n, Oe, void 0, e, s).dispose();
486
569
  }
487
570
  );
488
571
  }
489
- function Se(n, e, t, r, s) {
490
- var f;
572
+ function Te(n, e, t, r, s) {
573
+ var a;
491
574
  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) => {
575
+ const i = function(...u) {
576
+ return O(
577
+ [t(this), ...u.map((f) => t(f))],
578
+ (f, ...l) => {
496
579
  if (new.target) {
497
- const [d] = r(
498
- m(n, "(Cls, ...args) => new Cls(...args)", u, e, ...p)
580
+ const [y] = r(
581
+ b(n, "(Cls, ...args) => new Cls(...args)", f, e, ...l)
499
582
  );
500
- return Object.defineProperties(this, Object.getOwnPropertyDescriptors(d)), this;
583
+ return Object.defineProperties(this, Object.getOwnPropertyDescriptors(y)), this;
501
584
  }
502
- const y = T(n, n.callFunction(e, u, ...p)), [h, c] = r(y);
503
- return c && y.dispose(), h;
585
+ const c = R(n, n.callFunction(e, f, ...l)), [m, p] = r(c);
586
+ return p && c.dispose(), m;
504
587
  }
505
588
  );
506
- }, o = (f = s(i, e)) != null ? f : i;
507
- return V(n, e, i, r), o;
589
+ }, o = (a = s(i, e)) != null ? a : i;
590
+ return z(n, e, i, r), o;
508
591
  }
509
- function G(n, e) {
592
+ function $(n, e) {
510
593
  const t = n.toHostRef(e);
511
594
  if (t)
512
595
  try {
@@ -515,33 +598,46 @@ function G(n, e) {
515
598
  t.dispose();
516
599
  }
517
600
  }
518
- 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));
601
+ function Me(n, e, t, r) {
602
+ const s = j(b(n, "a => a instanceof Map", void 0, e), (u) => n.dump(u)), i = !s && j(b(n, "a => a instanceof Set", void 0, e), (u) => n.dump(u));
520
603
  if (!s && !i) return;
521
604
  const o = s ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
522
605
  r(o, e);
523
- const f = n.unwrapResult(n.getIterator(e));
606
+ const a = n.unwrapResult(n.getIterator(e));
524
607
  try {
525
- for (const a of f) {
526
- const u = n.unwrapResult(a);
608
+ for (const u of a) {
609
+ const f = n.unwrapResult(u);
527
610
  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();
611
+ const l = n.getProp(f, 0), c = n.getProp(f, 1);
612
+ let m = !0, p = !0;
613
+ try {
614
+ const [y, h] = t(l);
615
+ m = h;
616
+ const [g, _] = t(c);
617
+ p = _, o.set(y, g);
618
+ } finally {
619
+ m && l.alive && l.dispose(), p && c.alive && c.dispose(), f.alive && f.dispose();
620
+ }
530
621
  } else {
531
- const [p, y] = t(u);
532
- y && u.dispose(), o.add(p);
622
+ let l = !0;
623
+ try {
624
+ const [c, m] = t(f);
625
+ l = m, o.add(c);
626
+ } finally {
627
+ l && f.alive && f.dispose();
628
+ }
533
629
  }
534
630
  }
535
631
  } finally {
536
- f.alive && f.dispose();
632
+ a.alive && a.dispose();
537
633
  }
538
634
  return o;
539
635
  }
540
- function Te(n, e, t, r) {
541
- var f;
636
+ function Ie(n, e, t, r) {
637
+ var a;
542
638
  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(
544
- m(
639
+ const s = j(b(n, "Array.isArray", void 0, e), (u) => n.dump(u)) ? [] : {}, i = (a = r(s, e)) != null ? a : s, o = j(
640
+ b(
545
641
  n,
546
642
  `o => {
547
643
  const p = Object.getPrototypeOf(o);
@@ -550,68 +646,68 @@ function Te(n, e, t, r) {
550
646
  void 0,
551
647
  e
552
648
  ),
553
- (a) => {
554
- if (n.typeof(a) === "undefined") return;
555
- const [u] = t(a);
556
- return u;
649
+ (u) => {
650
+ if (n.typeof(u) === "undefined") return;
651
+ const [f] = t(u);
652
+ return f;
557
653
  }
558
654
  );
559
- return typeof o == "object" && Object.setPrototypeOf(i, o), V(n, e, s, t), i;
655
+ return typeof o == "object" && Object.setPrototypeOf(i, o), z(n, e, s, t), i;
560
656
  }
561
- function He(n, e) {
657
+ function K(n, e) {
562
658
  const t = n.typeof(e);
563
659
  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
660
  }
565
- function Re(n, e, t, r) {
566
- var u;
567
- 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;
661
+ function Fe(n, e, t, r) {
662
+ var f;
663
+ if (!Ce(n, e)) return;
664
+ const s = me(), [i, o] = t(s.resolve), [a, u] = t(s.reject);
665
+ return b(n, "(p, res, rej) => { p.then(res, rej); }", void 0, e, i, a), o && i.dispose(), u && a.dispose(), (f = r(s.promise, e)) != null ? f : s.promise;
570
666
  }
571
- function Ee(n, e) {
572
- return e.owner ? n.unwrapResult(n.evalCode("Promise")).consume((t) => e.owner ? x(n, e, t) : !1) : !1;
667
+ function Ce(n, e) {
668
+ return e.owner ? j(n.unwrapResult(n.evalCode("Promise")), (t) => e.owner ? re(n, e, t) : !1) : !1;
573
669
  }
574
- function Oe(n, e) {
575
- const [t] = J(n, e);
670
+ function Ae(n, e) {
671
+ const [t] = L(n, e);
576
672
  return t;
577
673
  }
578
- function J(n, e) {
579
- var p, y, h;
674
+ function L(n, e) {
675
+ var l, c, m;
580
676
  const { ctx: t, marshal: r, find: s, pre: i } = e;
581
677
  {
582
- const [c, d] = He(t, n);
583
- if (d) return [c, !1];
678
+ const [p, y] = K(t, n);
679
+ if (y) return [p, !1];
584
680
  }
585
681
  {
586
- const c = s(n);
587
- if (c)
588
- return [c, !0];
682
+ const p = s(n);
683
+ if (p)
684
+ return [p, !0];
589
685
  }
590
- const o = (c) => J(c, e);
686
+ const o = (p) => L(p, e);
591
687
  if (e.hostRef) {
592
- const c = G(t, n);
593
- if (c) return [c.value, !0];
688
+ const p = $(t, n);
689
+ if (p) return [p.value, !0];
594
690
  }
595
- const f = be(t, n, i, [...Pe, ...(p = e.custom) != null ? p : []]);
596
- 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];
691
+ const a = Se(t, n, i, [...Ee, ...(l = e.custom) != null ? l : []]);
692
+ if (a) return [a, !0];
693
+ const u = Me(t, n, o, i);
694
+ return u ? [u, !0] : [(m = (c = Fe(t, n, r, i)) != null ? c : Te(t, n, r, o, i)) != null ? m : Ie(t, n, o, i), !1];
599
695
  }
600
- class I {
696
+ class D {
601
697
  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);
698
+ d(this, "ctx");
699
+ d(this, "_keyToId", /* @__PURE__ */ new Map());
700
+ d(this, "_key2ToId", /* @__PURE__ */ new Map());
701
+ d(this, "_idToHandle", /* @__PURE__ */ new Map());
702
+ d(this, "_idToHandle2", /* @__PURE__ */ new Map());
703
+ d(this, "_idToKey", /* @__PURE__ */ new Map());
704
+ d(this, "_idToKey2", /* @__PURE__ */ new Map());
705
+ d(this, "_disposables", /* @__PURE__ */ new Set());
706
+ d(this, "_mapGet");
707
+ d(this, "_mapSet");
708
+ d(this, "_mapDelete");
709
+ d(this, "_mapClear");
710
+ d(this, "_nextId", Number.MIN_SAFE_INTEGER);
615
711
  this.ctx = e;
616
712
  const t = e.unwrapResult(
617
713
  e.evalCode(`() => {
@@ -642,15 +738,15 @@ class I {
642
738
  this._mapGet = e.getProp(t, "get"), this._mapSet = e.getProp(t, "set"), this._mapDelete = e.getProp(t, "delete"), this._mapClear = e.getProp(t, "clear"), t.dispose(), this._disposables.add(this._mapGet), this._disposables.add(this._mapSet), this._disposables.add(this._mapDelete), this._disposables.add(this._mapClear);
643
739
  }
644
740
  set(e, t, r, s) {
645
- var f;
741
+ var a;
646
742
  if (!t.alive || s && !s.alive) return !1;
647
- const i = (f = this.get(e)) != null ? f : this.get(r);
743
+ const i = (a = this.get(e)) != null ? a : this.get(r);
648
744
  if (i)
649
745
  return i === t || i === s;
650
- 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);
653
- }), !0;
746
+ const o = this._nextId;
747
+ return j(this.ctx.newNumber(o), (u) => {
748
+ this._call(this._mapSet, void 0, t, u, s != null ? s : this.ctx.undefined);
749
+ }), this._nextId++, 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)), !0;
654
750
  }
655
751
  merge(e) {
656
752
  if (e)
@@ -662,7 +758,7 @@ class I {
662
758
  const t = (s = this._keyToId.get(e)) != null ? s : this._key2ToId.get(e), r = typeof t == "number" ? this._idToHandle.get(t) : void 0;
663
759
  if (r) {
664
760
  if (!r.alive) {
665
- this.delete(e);
761
+ this.delete(e, !0);
666
762
  return;
667
763
  }
668
764
  return r;
@@ -682,17 +778,17 @@ class I {
682
778
  return this._keyToId.keys();
683
779
  }
684
780
  delete(e, t) {
685
- var a;
686
- const r = (a = this._keyToId.get(e)) != null ? a : this._key2ToId.get(e);
781
+ var u;
782
+ const r = (u = this._keyToId.get(e)) != null ? u : this._key2ToId.get(e);
687
783
  if (typeof r == "undefined") return;
688
784
  const s = this._idToHandle.get(r), i = this._idToHandle2.get(r);
689
785
  this._call(
690
786
  this._mapDelete,
691
787
  void 0,
692
- ...[s, i].filter((u) => !!(u != null && u.alive))
788
+ ...[s, i].filter((f) => !!(f != null && f.alive))
693
789
  );
694
- const o = this._idToKey.get(r), f = this._idToKey2.get(r);
695
- 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());
790
+ const o = this._idToKey.get(r), a = this._idToKey2.get(r);
791
+ typeof o != "undefined" && this._keyToId.delete(o), 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(), i != null && i.alive && i.dispose());
696
792
  }
697
793
  deleteByHandle(e, t) {
698
794
  const r = this.getByHandle(e);
@@ -731,7 +827,7 @@ class I {
731
827
  };
732
828
  }
733
829
  _call(e, t, ...r) {
734
- return T(
830
+ return R(
735
831
  this.ctx,
736
832
  this.ctx.callFunction(
737
833
  e,
@@ -741,102 +837,112 @@ class I {
741
837
  );
742
838
  }
743
839
  }
744
- function Me(n, e, t, r, s, i, o, f = !0) {
745
- if (!S(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || o && !o(e))
840
+ function Be(n, e, t, r, s, i, o, a = !0) {
841
+ if (!P(e) || e instanceof Promise || e instanceof Date || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || e instanceof Map || e instanceof Set || o && !o(e))
746
842
  return;
747
- 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);
843
+ if (De(e, t) || !a) return e;
844
+ const u = new Proxy(e, {
845
+ get(f, l) {
846
+ return l === t ? f : Reflect.get(f, l);
751
847
  },
752
- set(u, p, y, h) {
753
- 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);
848
+ set(f, l, c, m) {
849
+ var h;
850
+ const p = S(c, t), y = (h = i == null ? void 0 : i(m)) != null ? h : "host";
851
+ return y !== "vm" && !Reflect.set(f, l, p) || y === "host" || !n.alive || O(
852
+ [s(m), s(l), s(p)],
853
+ (g, _, w) => {
854
+ const [v, H] = T(n, g, r);
855
+ H ? j(v, (k) => n.setProp(k, _, w)) : n.setProp(v, _, w);
760
856
  }
761
857
  ), !0;
762
858
  },
763
- deleteProperty(u, p) {
764
- 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)) {
769
- 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);
859
+ deleteProperty(f, l) {
860
+ var m;
861
+ const c = (m = i == null ? void 0 : i(u)) != null ? m : "host";
862
+ return O([s(u), s(l)], (p, y) => {
863
+ const [h, g] = T(n, p, r);
864
+ if (c === "vm" || Reflect.deleteProperty(f, l)) {
865
+ if (c === "host" || !n.alive) return !0;
866
+ g ? j(h, (_) => b(n, "(a, b) => delete a[b]", void 0, _, y)) : b(n, "(a, b) => delete a[b]", void 0, h, y);
771
867
  }
772
868
  return !0;
773
869
  });
774
870
  },
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) => {
781
- const [j, w] = E(n, _, r), k = (O) => m(
871
+ defineProperty(f, l, c) {
872
+ var y;
873
+ const m = (y = i == null ? void 0 : i(u)) != null ? y : "host", p = I({}, c);
874
+ return "value" in p && (p.value = S(p.value, t)), typeof p.get == "function" && (p.get = S(p.get, t)), typeof p.set == "function" && (p.set = S(p.set, t)), m !== "vm" && !Reflect.defineProperty(f, l, p) ? !1 : (m === "host" || !n.alive || O(
875
+ [s(u), s(l), s(p)],
876
+ (h, g, _) => {
877
+ const [w, v] = T(n, h, r), H = (k) => b(
782
878
  n,
783
879
  "(o, k, d) => { Object.defineProperty(o, k, d); }",
784
880
  void 0,
785
- O,
786
- v,
787
- b
881
+ k,
882
+ g,
883
+ _
788
884
  ).dispose();
789
- w ? j.consume(k) : k(j);
885
+ v ? j(w, H) : H(w);
790
886
  }
791
887
  ), !0);
792
888
  }
793
889
  });
794
- return a;
890
+ return u;
795
891
  }
796
- function Ce(n, e, t, r, s, i, o, f = !0) {
797
- if (!ee(n, e) || o && !o(e, n))
798
- return [void 0, !1];
799
- if (W(n, e, r)) return [e, !1];
800
- 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;
809
- const j = s(_);
810
- P(v, t)[b] = j;
811
- }, p = (c, d) => {
812
- const _ = s(c);
892
+ function Ne(n, e, t, r, s, i, o = !0) {
893
+ let a;
894
+ const u = (y) => {
895
+ const h = s == null ? void 0 : s(r(y));
896
+ return typeof h == "string" ? n.newString(h) : n.undefined;
897
+ }, f = (y, h, g) => {
898
+ const _ = r(y);
899
+ if (!_) return;
900
+ const w = r(h);
901
+ if (w === "__proto__") return;
902
+ const v = r(g);
903
+ S(_, e)[w] = v;
904
+ }, l = (y, h) => {
905
+ const g = r(y);
906
+ if (!g) return;
907
+ const _ = r(h);
908
+ Reflect.deleteProperty(S(g, e), _);
909
+ }, c = (y, h, g) => {
910
+ const _ = r(y);
813
911
  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;
821
- const j = s(_);
822
- Object.defineProperty(P(v, t), b, j);
823
- }, h = n.newFunction("proxyFuncs", (c, ...d) => {
824
- switch (n.getNumber(c)) {
912
+ const w = r(h);
913
+ if (w === "__proto__") return;
914
+ const v = r(g);
915
+ Object.defineProperty(S(_, e), w, v);
916
+ }, m = () => (a && a.alive || (a = n.newFunction("proxyFuncs", (y, ...h) => {
917
+ switch (n.getNumber(y)) {
825
918
  case 1:
826
- return a(d[0]);
919
+ return u(h[0]);
827
920
  case 2:
828
- return u(d[0], d[1], d[2]);
921
+ return f(h[0], h[1], h[2]);
829
922
  case 3:
830
- return p(d[0], d[1]);
923
+ return l(h[0], h[1]);
831
924
  case 4:
832
- return y(d[0], d[1], d[2]);
925
+ return c(h[0], h[1], h[2]);
833
926
  }
834
927
  return n.undefined;
835
- });
836
- return g(h, (c) => [
837
- m(
838
- n,
839
- `(target, sym, proxyFuncs) => {
928
+ })), a);
929
+ return {
930
+ wrapHandle: (y) => {
931
+ if (!U(n, y) || i && !i(y, n))
932
+ return [void 0, !1];
933
+ if (!o) return [y, !1];
934
+ const h = b(
935
+ n,
936
+ `(target, sym, proxyFuncs) => {
937
+ if (
938
+ (target instanceof Promise) ||
939
+ (target instanceof Date) ||
940
+ (target instanceof ArrayBuffer) ||
941
+ (ArrayBuffer.isView(target)) ||
942
+ (target instanceof Map) ||
943
+ (target instanceof Set) ||
944
+ target[sym]
945
+ ) return null;
840
946
  const rec = new Proxy(target, {
841
947
  get(obj, key, receiver) {
842
948
  return key === sym ? obj : Reflect.get(obj, key, receiver)
@@ -874,44 +980,42 @@ function Ce(n, e, t, r, s, i, o, f = !0) {
874
980
  });
875
981
  return rec;
876
982
  }`,
877
- void 0,
878
- e,
879
- r,
880
- c
881
- ),
882
- !0
883
- ]);
983
+ void 0,
984
+ y,
985
+ t,
986
+ m()
987
+ );
988
+ return n.sameValue(h, n.null) ? (h.dispose(), [y, !1]) : [h, !0];
989
+ },
990
+ dispose: () => {
991
+ a && a.alive && a.dispose(), a = void 0;
992
+ }
993
+ };
884
994
  }
885
- function P(n, e) {
995
+ function S(n, e) {
886
996
  var t;
887
- return S(n) && (t = n[e]) != null ? t : n;
888
- }
889
- function E(n, e, t) {
890
- return W(n, e, t) ? [n.getProp(e, t), !0] : [e, !1];
997
+ return P(n) && (t = n[e]) != null ? t : n;
891
998
  }
892
- function Be(n, e) {
893
- return S(n) && !!n[e];
894
- }
895
- function W(n, e, t) {
896
- return !!n.dump(
897
- m(
898
- n,
899
- // Built-ins that must not be wrapped (internal slots / non-property access)
900
- // report as "wrapped" so wrapHandle leaves them alone.
901
- '(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]',
902
- void 0,
903
- e,
904
- t
905
- )
999
+ function T(n, e, t) {
1000
+ const r = b(
1001
+ n,
1002
+ '(a, s) => (typeof a === "object" && a !== null || typeof a === "function") && a[s] || null',
1003
+ void 0,
1004
+ e,
1005
+ t
906
1006
  );
1007
+ return n.sameValue(r, n.null) ? (r.dispose(), [e, !1]) : [r, !0];
1008
+ }
1009
+ function De(n, e) {
1010
+ return P(n) && !!n[e];
907
1011
  }
908
- class Fe {
1012
+ class Ue {
909
1013
  /** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
910
1014
  constructor(e, t) {
911
- l(this, "context");
912
- l(this, "_map");
913
- l(this, "_registeredMap");
914
- l(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
1015
+ d(this, "context");
1016
+ d(this, "_map");
1017
+ d(this, "_registeredMap");
1018
+ d(this, "_registeredMapDispose", /* @__PURE__ */ new Set());
915
1019
  // Handles with no owner: "json" copies and BigInt values. Unlike
916
1020
  // proxy-marshalled objects they are not identity-tracked in `_map`. A nested
917
1021
  // one is disposed by its parent consumer via `_disposeTransient` as soon as
@@ -919,32 +1023,40 @@ class Fe {
919
1023
  // were never nested (e.g. a top-level value before its caller consumes it) on
920
1024
  // dispose. Top-level handles are removed in `_marshal` since their caller
921
1025
  // 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) => {
1026
+ d(this, "_transientHandles", /* @__PURE__ */ new Set());
1027
+ d(this, "_sync", /* @__PURE__ */ new Set());
1028
+ d(this, "_temporalSync", /* @__PURE__ */ new Set());
1029
+ d(this, "_symbol", /* @__PURE__ */ Symbol());
1030
+ d(this, "_symbolHandle");
1031
+ d(this, "_wrapHandleImpl");
1032
+ d(this, "_options");
1033
+ d(this, "_isMarshalable", (e) => {
929
1034
  var r, s;
930
1035
  const t = (r = this._options) == null ? void 0 : r.isMarshalable;
931
1036
  return (s = typeof t == "function" ? t(this._unwrap(e)) : t) != null ? s : "json";
932
1037
  });
933
- l(this, "_marshalByReference", (e) => {
1038
+ d(this, "_marshalByReference", (e) => {
934
1039
  var t, r;
935
1040
  return !!((r = (t = this._options) == null ? void 0 : t.marshalByReference) != null && r.call(t, this._unwrap(e)));
936
1041
  });
1042
+ d(this, "_asyncify", (e) => {
1043
+ var s;
1044
+ const t = (s = this._options) == null ? void 0 : s.asyncify;
1045
+ if (!t) return !1;
1046
+ const r = this._unwrap(e);
1047
+ return typeof t == "function" ? typeof r == "function" && t(r) : Object.prototype.toString.call(r) === "[object AsyncFunction]";
1048
+ });
937
1049
  // Register an opaque HostRef handle by its host value without wrapping it.
938
- l(this, "_registerHostRef", (e, t) => {
1050
+ d(this, "_registerHostRef", (e, t) => {
939
1051
  const r = this._unwrap(e), s = this._map.get(r);
940
1052
  return s || (this._map.set(r, t), t);
941
1053
  });
942
- l(this, "_marshalFind", (e) => {
1054
+ d(this, "_marshalFind", (e) => {
943
1055
  var s, i, o;
944
1056
  const t = this._unwrap(e);
945
1057
  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
1058
  });
947
- l(this, "_marshalPre", (e, t, r) => {
1059
+ d(this, "_marshalPre", (e, t, r) => {
948
1060
  if (r === "json") {
949
1061
  this._registerTransient(C(t));
950
1062
  return;
@@ -953,14 +1065,14 @@ class Fe {
953
1065
  if (s) return s[1];
954
1066
  this._registeredMap.has(e) || this._registerTransient(C(t));
955
1067
  });
956
- l(this, "_registerTransient", (e) => {
1068
+ d(this, "_registerTransient", (e) => {
957
1069
  this._transientHandles.add(e);
958
1070
  });
959
- l(this, "_disposeTransient", (e) => {
1071
+ d(this, "_disposeTransient", (e) => {
960
1072
  this._transientHandles.delete(e) && e.alive && e.dispose();
961
1073
  });
962
- l(this, "_marshalPreApply", (e, t, r) => {
963
- const s = S(t) ? this._unwrap(t) : void 0;
1074
+ d(this, "_marshalPreApply", (e, t, r) => {
1075
+ const s = P(t) ? this._unwrap(t) : void 0;
964
1076
  s && this._temporalSync.add(s);
965
1077
  try {
966
1078
  return e.apply(t, r);
@@ -968,12 +1080,12 @@ class Fe {
968
1080
  s && this._temporalSync.delete(s);
969
1081
  }
970
1082
  });
971
- l(this, "_marshal", (e) => {
972
- var o, f, a, u;
1083
+ d(this, "_marshal", (e) => {
1084
+ var o, a, u, f, l;
973
1085
  const t = this._registeredMap.get(e);
974
1086
  if (t)
975
1087
  return [t, !1];
976
- const r = this._marshalByReference(e) ? this._unwrap(e) : (o = this._wrap(e)) != null ? o : e, s = U(r, {
1088
+ const r = this._marshalByReference(e) ? this._unwrap(e) : (o = this._wrap(e)) != null ? o : e, s = W(r, {
977
1089
  ctx: this.context,
978
1090
  unmarshal: this._unmarshal,
979
1091
  isMarshalable: this._isMarshalable,
@@ -984,52 +1096,73 @@ class Fe {
984
1096
  registerTransient: this._registerTransient,
985
1097
  disposeTransient: this._disposeTransient,
986
1098
  preApply: this._marshalPreApply,
987
- custom: (f = this._options) == null ? void 0 : f.customMarshaller
1099
+ prepareReturn: this._prepareMarshalReturn,
1100
+ unwrap: (c) => this._unwrap(c),
1101
+ asyncify: (a = this._options) != null && a.asyncify ? this._asyncify : void 0,
1102
+ custom: (u = this._options) == null ? void 0 : u.customMarshaller
988
1103
  });
989
- this._transientHandles.delete(s);
990
- const i = (u = (a = this._options) == null ? void 0 : a.syncEnabled) != null ? u : !0;
991
- return [s, !i || !this._map.hasHandle(s)];
1104
+ return this._transientHandles.delete(s), !((l = (f = this._options) == null ? void 0 : f.syncEnabled) != null ? l : !0) || !P(e) ? [s, !0] : [s, !this._map.hasHandle(s)];
1105
+ });
1106
+ d(this, "_prepareMarshalReturn", (e) => {
1107
+ var r, s;
1108
+ return ((s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0) && e.alive && U(this.context, e) && this._map.hasHandle(e) ? e.dup() : e;
992
1109
  });
993
- l(this, "_preUnmarshal", (e, t) => {
1110
+ d(this, "_preUnmarshal", (e, t) => {
994
1111
  var r, s, i;
995
1112
  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
1113
  });
997
- l(this, "_unmarshalFind", (e) => {
1114
+ d(this, "_unmarshalFind", (e) => {
998
1115
  var t;
999
1116
  return (t = this._registeredMap.getByHandle(e)) != null ? t : this._map.getByHandle(e);
1000
1117
  });
1001
- l(this, "_unmarshal", (e) => {
1002
- var s, i, o;
1003
- const t = this._registeredMap.getByHandle(e);
1004
- if (typeof t != "undefined")
1005
- return t;
1006
- if ((s = this._options) != null && s.marshalByReference) {
1007
- const f = G(this.context, e);
1008
- if (f) return f.value;
1118
+ d(this, "_unmarshal", (e) => {
1119
+ var u, f, l;
1120
+ const [t, r] = K(this.context, e);
1121
+ if (r) return t;
1122
+ const s = this._registeredMap.getByHandle(e);
1123
+ if (typeof s != "undefined")
1124
+ return s;
1125
+ if ((u = this._options) != null && u.marshalByReference) {
1126
+ const c = $(this.context, e);
1127
+ if (c) return c.value;
1128
+ }
1129
+ const [i, o] = this._wrapHandle(e);
1130
+ let a = !1;
1131
+ try {
1132
+ const c = Ae(i != null ? i : e, {
1133
+ ctx: this.context,
1134
+ marshal: this._marshal,
1135
+ find: this._unmarshalFind,
1136
+ pre: this._preUnmarshal,
1137
+ custom: (f = this._options) == null ? void 0 : f.customUnmarshaller,
1138
+ hostRef: !!((l = this._options) != null && l.marshalByReference)
1139
+ });
1140
+ return a = !0, c;
1141
+ } finally {
1142
+ !a && o && (i != null && i.alive) && i !== e && i.dispose();
1009
1143
  }
1010
- const [r] = this._wrapHandle(e);
1011
- return Oe(r != null ? r : e, {
1012
- ctx: this.context,
1013
- marshal: this._marshal,
1014
- find: this._unmarshalFind,
1015
- pre: this._preUnmarshal,
1016
- custom: (i = this._options) == null ? void 0 : i.customUnmarshaller,
1017
- hostRef: !!((o = this._options) != null && o.marshalByReference)
1018
- });
1019
1144
  });
1020
- l(this, "_syncMode", (e) => {
1145
+ d(this, "_syncMode", (e) => {
1021
1146
  const t = this._unwrap(e);
1022
1147
  return this._sync.has(t) || this._temporalSync.has(t) ? "both" : void 0;
1023
1148
  });
1024
- l(this, "_unwrapIfNotSynced", (e) => {
1149
+ d(this, "_unwrapIfNotSynced", (e) => {
1025
1150
  const t = this._unwrap(e);
1026
1151
  return t instanceof Promise || !this._sync.has(t) ? t : e;
1027
1152
  });
1028
- var r;
1153
+ var r, s, i, o;
1029
1154
  t != null && t.compat && !("runtime" in e) && (e.runtime = {
1030
1155
  hasPendingJob: () => e.hasPendingJob(),
1031
- executePendingJobs: (s) => e.executePendingJobs(s)
1032
- }), this.context = t != null && t.experimentalContextEx ? K(e) : e, Y(this.context), this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._map = new I(e), this._registeredMap = new I(e), this.registerAll((r = t == null ? void 0 : t.registeredObjects) != null ? r : Q);
1156
+ executePendingJobs: (a) => e.executePendingJobs(a)
1157
+ }), this.context = t != null && t.experimentalContextEx ? ae(e) : e, te(this.context), this._options = t, this._symbolHandle = e.unwrapResult(e.evalCode("Symbol()")), this._wrapHandleImpl = Ne(
1158
+ this.context,
1159
+ this._symbol,
1160
+ this._symbolHandle,
1161
+ this._unmarshal,
1162
+ this._syncMode,
1163
+ (r = this._options) == null ? void 0 : r.isHandleWrappable,
1164
+ (i = (s = this._options) == null ? void 0 : s.syncEnabled) != null ? i : !0
1165
+ ), this._map = new D(e), this._registeredMap = new D(e), this.registerAll((o = t == null ? void 0 : t.registeredObjects) != null ? o : fe);
1033
1166
  }
1034
1167
  /**
1035
1168
  * Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
@@ -1038,7 +1171,7 @@ class Fe {
1038
1171
  var e, t;
1039
1172
  for (const r of this._transientHandles)
1040
1173
  r.alive && r.dispose();
1041
- this._transientHandles.clear(), this._map.dispose(), this._registeredMap.dispose(), this._symbolHandle.dispose(), Z(this.context), (t = (e = this.context).disposeEx) == null || t.call(e);
1174
+ this._transientHandles.clear(), this._map.dispose(), this._registeredMap.dispose(), this._wrapHandleImpl.dispose(), this._symbolHandle.dispose(), ne(this.context), (t = (e = this.context).disposeEx) == null || t.call(e);
1042
1175
  }
1043
1176
  /** Allows `using arena = new Arena(...)` to dispose the arena automatically. */
1044
1177
  [Symbol.dispose]() {
@@ -1046,10 +1179,16 @@ class Fe {
1046
1179
  }
1047
1180
  /**
1048
1181
  * 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.
1182
+ *
1183
+ * @param code - The JS code to evaluate
1184
+ * @param filename - Optional filename used in error stacks and for debugging
1185
+ * @param options - Optional eval options forwarded to quickjs-emscripten's
1186
+ * `evalCode`, either an `EvalFlags` bitmask (`number`) or a
1187
+ * {@link ContextEvalOptions} object (e.g. `{ strict: true }`)
1049
1188
  */
1050
- evalCode(e) {
1051
- const t = this.context.evalCode(e);
1052
- return this._unwrapResultAndUnmarshal(t);
1189
+ evalCode(e, t, r) {
1190
+ const s = this.context.evalCode(e, t, r);
1191
+ return this._unwrapResultAndUnmarshal(s);
1053
1192
  }
1054
1193
  /**
1055
1194
  * Evaluate ES module code in the VM and get the module's exports.
@@ -1058,6 +1197,10 @@ class Fe {
1058
1197
  *
1059
1198
  * @param code - The ES module code to evaluate
1060
1199
  * @param filename - Optional filename for debugging purposes (default: "module.js")
1200
+ * @param options - Optional {@link ContextEvalOptions}. `type` is always forced
1201
+ * to `"module"`, so any `type` in `options` is overridden. A numeric
1202
+ * `EvalFlags` bitmask cannot be merged with the forced module type and is
1203
+ * therefore not supported here; if a number is passed it is ignored.
1061
1204
  * @returns The module's exports object, or a Promise resolving to exports if using top-level await
1062
1205
  *
1063
1206
  * @example
@@ -1083,9 +1226,11 @@ class Fe {
1083
1226
  * console.log(exports.data); // 123
1084
1227
  * ```
1085
1228
  */
1086
- evalModule(e, t = "module.js") {
1087
- const r = this.context.evalCode(e, t, { type: "module" });
1088
- return this._unwrapResultAndUnmarshal(r);
1229
+ evalModule(e, t = "module.js", r) {
1230
+ const s = this.context.evalCode(e, t, N(I({}, typeof r == "number" ? {} : r), {
1231
+ type: "module"
1232
+ }));
1233
+ return this._unwrapResultAndUnmarshal(s);
1089
1234
  }
1090
1235
  /**
1091
1236
  * Almost same as `vm.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.
@@ -1094,7 +1239,7 @@ class Fe {
1094
1239
  const t = this.context.runtime.executePendingJobs(e);
1095
1240
  if ("value" in t)
1096
1241
  return t.value;
1097
- throw this._unwrapIfNotSynced(g(t.error, this._unmarshal));
1242
+ throw this._unwrapIfNotSynced(j(t.error, this._unmarshal));
1098
1243
  }
1099
1244
  /**
1100
1245
  * Set the max memory this runtime can allocate.
@@ -1142,6 +1287,43 @@ class Fe {
1142
1287
  setMaxStackSize(e) {
1143
1288
  this.context.runtime.setMaxStackSize(e);
1144
1289
  }
1290
+ /**
1291
+ * Set a callback which is regularly called by the QuickJS engine when it is
1292
+ * executing code. This callback can be used to implement an execution
1293
+ * timeout: return `true` from the handler to interrupt the running code.
1294
+ *
1295
+ * This is useful for preventing runaway CPU usage (e.g. infinite loops) in
1296
+ * untrusted code.
1297
+ *
1298
+ * @param cb - The interrupt handler. Return `true` to interrupt execution.
1299
+ *
1300
+ * @example
1301
+ * ```js
1302
+ * // Interrupt evaluation after 1 second
1303
+ * const deadline = Date.now() + 1000;
1304
+ * arena.setInterruptHandler(() => Date.now() > deadline);
1305
+ *
1306
+ * try {
1307
+ * arena.evalCode(`while (true) {}`);
1308
+ * } catch (e) {
1309
+ * console.log("Execution interrupted");
1310
+ * }
1311
+ * ```
1312
+ */
1313
+ setInterruptHandler(e) {
1314
+ this.context.runtime.setInterruptHandler(e);
1315
+ }
1316
+ /**
1317
+ * Remove the interrupt handler previously set with `setInterruptHandler`.
1318
+ *
1319
+ * @example
1320
+ * ```js
1321
+ * arena.removeInterruptHandler();
1322
+ * ```
1323
+ */
1324
+ removeInterruptHandler() {
1325
+ this.context.runtime.removeInterruptHandler();
1326
+ }
1145
1327
  /**
1146
1328
  * Get detailed memory usage statistics for this runtime.
1147
1329
  *
@@ -1189,7 +1371,7 @@ class Fe {
1189
1371
  */
1190
1372
  expose(e) {
1191
1373
  for (const [t, r] of Object.entries(e))
1192
- re(this._marshal(r), (s) => {
1374
+ ie(this._marshal(r), (s) => {
1193
1375
  this.context.setProp(this.context.global, t, s);
1194
1376
  });
1195
1377
  }
@@ -1200,7 +1382,7 @@ class Fe {
1200
1382
  */
1201
1383
  sync(e) {
1202
1384
  const t = this._wrap(e);
1203
- return typeof t == "undefined" ? e : (N(t, (r) => {
1385
+ return typeof t == "undefined" ? e : (G(t, (r) => {
1204
1386
  const s = this._unwrap(r);
1205
1387
  this._sync.add(s);
1206
1388
  }), t);
@@ -1236,7 +1418,7 @@ class Fe {
1236
1418
  this.unregister(r, t);
1237
1419
  }
1238
1420
  startSync(e) {
1239
- if (!S(e)) return;
1421
+ if (!P(e)) return;
1240
1422
  const t = this._unwrap(e);
1241
1423
  this._sync.add(t);
1242
1424
  }
@@ -1246,28 +1428,33 @@ class Fe {
1246
1428
  _unwrapResult(e) {
1247
1429
  if ("value" in e)
1248
1430
  return e.value;
1249
- throw this._unwrapIfNotSynced(g(e.error, this._unmarshal));
1431
+ throw this._unwrapIfNotSynced(j(e.error, this._unmarshal));
1250
1432
  }
1251
1433
  _unwrapResultAndUnmarshal(e) {
1252
1434
  if (e)
1253
- return this._unwrapIfNotSynced(g(this._unwrapResult(e), this._unmarshal));
1435
+ return this._unwrapIfNotSynced(j(this._unwrapResult(e), this._unmarshal));
1254
1436
  }
1255
1437
  _register(e, t, r = this._map, s) {
1256
1438
  if (this._registeredMap.has(e) || this._registeredMap.hasHandle(t))
1257
1439
  return;
1258
1440
  let i = this._wrap(e);
1259
- const [o] = this._wrapHandle(t), f = e instanceof Promise;
1260
- if (!o || !i && !f) return;
1261
- 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");
1266
- return [i, o];
1441
+ const [o, a] = this._wrapHandle(t), u = e instanceof Promise;
1442
+ if (!o || !i && !u) return;
1443
+ u && (i = e);
1444
+ const f = this._unwrap(e);
1445
+ let l, c = !1, m = !1;
1446
+ try {
1447
+ if ([l, c] = this._unwrapHandle(t), r.set(i, o, f, l))
1448
+ s && this._sync.add(f);
1449
+ else throw new Error("already registered");
1450
+ return m = !0, [i, o];
1451
+ } finally {
1452
+ m || (a && o.alive && o.dispose(), c && (l != null && l.alive) && l.dispose());
1453
+ }
1267
1454
  }
1268
1455
  _wrap(e) {
1269
1456
  var t, r, s;
1270
- return Me(
1457
+ return Be(
1271
1458
  this.context,
1272
1459
  e,
1273
1460
  this._symbol,
@@ -1279,56 +1466,52 @@ class Fe {
1279
1466
  );
1280
1467
  }
1281
1468
  _unwrap(e) {
1282
- return P(e, this._symbol);
1469
+ return S(e, this._symbol);
1283
1470
  }
1284
1471
  _wrapHandle(e) {
1285
- var t, r, s;
1286
- return Ce(
1287
- this.context,
1288
- e,
1289
- this._symbol,
1290
- this._symbolHandle,
1291
- this._unmarshal,
1292
- this._syncMode,
1293
- (t = this._options) == null ? void 0 : t.isHandleWrappable,
1294
- (s = (r = this._options) == null ? void 0 : r.syncEnabled) != null ? s : !0
1295
- );
1472
+ return this._wrapHandleImpl.wrapHandle(e);
1296
1473
  }
1297
1474
  _unwrapHandle(e) {
1298
- return E(this.context, e, this._symbolHandle);
1475
+ return T(this.context, e, this._symbolHandle);
1299
1476
  }
1300
1477
  }
1301
- class Ne extends Fe {
1478
+ class Je extends Ue {
1302
1479
  constructor(t, r) {
1303
1480
  super(t, r);
1304
- l(this, "asyncContext");
1481
+ d(this, "asyncContext");
1305
1482
  this.asyncContext = t;
1306
1483
  }
1307
1484
  /**
1308
1485
  * Evaluate JS code asynchronously in the VM and get the result on the host
1309
1486
  * side. Like `evalCode`, it converts and re-throws errors thrown during
1310
1487
  * evaluation. Use this when the code awaits host-provided promises.
1488
+ *
1489
+ * @param code - The JS code to evaluate
1490
+ * @param filename - Optional filename used in error stacks and for debugging
1491
+ * @param options - Optional eval options forwarded to quickjs-emscripten's
1492
+ * `evalCodeAsync`, either an `EvalFlags` bitmask (`number`) or a
1493
+ * {@link ContextEvalOptions} object (e.g. `{ strict: true }`)
1311
1494
  */
1312
- evalCodeAsync(t, r) {
1313
- return A(this, null, function* () {
1314
- const s = yield this.asyncContext.evalCodeAsync(t, r);
1315
- return this._unwrapResultAndUnmarshal(s);
1495
+ evalCodeAsync(t, r, s) {
1496
+ return F(this, null, function* () {
1497
+ const i = yield this.asyncContext.evalCodeAsync(t, r, s);
1498
+ return this._unwrapResultAndUnmarshal(i);
1316
1499
  });
1317
1500
  }
1318
1501
  }
1319
1502
  export {
1320
- Fe as Arena,
1321
- Ne as AsyncArena,
1322
- I as VMMap,
1323
- m as call,
1324
- Ie as complexity,
1325
- ne as consumeAll,
1326
- Q as defaultRegisteredObjects,
1327
- ce as isES2015Class,
1328
- ee as isHandleObject,
1329
- S as isObject,
1330
- te as json,
1331
- U as marshal,
1332
- Oe as unmarshal,
1333
- N as walkObject
1503
+ Ue as Arena,
1504
+ Je as AsyncArena,
1505
+ D as VMMap,
1506
+ b as call,
1507
+ Ge as complexity,
1508
+ V as consumeAll,
1509
+ fe as defaultRegisteredObjects,
1510
+ he as isES2015Class,
1511
+ U as isHandleObject,
1512
+ P as isObject,
1513
+ se as json,
1514
+ W as marshal,
1515
+ Ae as unmarshal,
1516
+ G as walkObject
1334
1517
  };